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