Spaces:
Runtime error
Runtime error
File size: 2,053 Bytes
798c949 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import streamlit as st
import svgwrite
# Define the size of the cards
CARD_WIDTH = 75
CARD_HEIGHT = 100
# Define the size of the SVG canvas
CANVAS_WIDTH = CARD_WIDTH * 5
CANVAS_HEIGHT = CARD_HEIGHT
# Define the parts that can be added to the card
PARTS = {
"background": ["white", "black", "red", "blue", "green", "yellow"],
"suit": ["clubs", "diamonds", "hearts", "spades"],
"value": ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"],
}
# Function to draw the card
def draw_card(background_color, suit, value):
# Create a new SVG drawing
dwg = svgwrite.Drawing(size=(f"{CARD_WIDTH}px", f"{CARD_HEIGHT}px"))
# Draw the card border
dwg.add(dwg.rect((0, 0), (CARD_WIDTH, CARD_HEIGHT), rx=10, ry=10, fill=background_color, stroke="black", stroke_width=2))
# Draw the card suit symbol
suit = svgwrite.text.Text(suit.upper(), insert=(5, 15), fill="black", font_size="16px", font_weight="bold")
dwg.add(suit)
# Draw the card value
value = svgwrite.text.Text(value, insert=(5, CARD_HEIGHT - 10), fill="black", font_size="16px", font_weight="bold")
dwg.add(value)
# Convert the SVG drawing to a string
svg_string = dwg.tostring()
return svg_string
# Function to display the parts selection sidebar
def display_parts_selection():
selected_parts = {}
for part, options in PARTS.items():
selected_option = st.sidebar.selectbox(f"Select {part}", options)
selected_parts[part] = selected_option
return selected_parts
# Function to display the resulting card
def display_card(selected_parts):
card_svg = draw_card(selected_parts["background"], selected_parts["suit"], selected_parts["value"])
st.write(f'<svg viewBox="0 0 {CARD_WIDTH} {CARD_HEIGHT}">{card_svg}</svg>', unsafe_allow_html=True)
# Set the page title and icon
st.set_page_config(page_title="Card Crafting Game", page_icon=":spades:")
# Display the parts selection sidebar
selected_parts = display_parts_selection()
# Display the resulting card
display_card(selected_parts)
|