Spaces:
Runtime error
Runtime error
Create app_enhanced.py
Browse files- app_enhanced.py +44 -0
app_enhanced.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Add these features to the main class:
|
| 2 |
+
|
| 3 |
+
def setup_enhanced_features(self):
|
| 4 |
+
"""Enhanced features for the drawing app"""
|
| 5 |
+
if 'drawing_history' not in st.session_state:
|
| 6 |
+
st.session_state.drawing_history = []
|
| 7 |
+
if 'current_tool' not in st.session_state:
|
| 8 |
+
st.session_state.current_tool = "brush"
|
| 9 |
+
if 'shapes' not in st.session_state:
|
| 10 |
+
st.session_state.shapes = []
|
| 11 |
+
|
| 12 |
+
def add_enhanced_controls(self):
|
| 13 |
+
"""Add enhanced drawing controls"""
|
| 14 |
+
st.sidebar.subheader("🛠️ Advanced Tools")
|
| 15 |
+
|
| 16 |
+
# Tool selection
|
| 17 |
+
tool = st.sidebar.radio(
|
| 18 |
+
"Select Tool:",
|
| 19 |
+
["Brush 🖌️", "Eraser 🧽", "Line 📏", "Circle ⭕", "Rectangle ▢"]
|
| 20 |
+
)
|
| 21 |
+
st.session_state.current_tool = tool
|
| 22 |
+
|
| 23 |
+
# Special effects
|
| 24 |
+
if st.sidebar.button("🌈 Rainbow Mode"):
|
| 25 |
+
self.activate_rainbow_mode()
|
| 26 |
+
|
| 27 |
+
# Undo functionality
|
| 28 |
+
if st.sidebar.button("↩️ Undo Last Stroke"):
|
| 29 |
+
self.undo_last_stroke()
|
| 30 |
+
|
| 31 |
+
def activate_rainbow_mode(self):
|
| 32 |
+
"""Cycle through colors automatically"""
|
| 33 |
+
colors = [(255,0,0), (255,165,0), (255,255,0), (0,255,0),
|
| 34 |
+
(0,0,255), (75,0,130), (238,130,238)]
|
| 35 |
+
st.session_state.rainbow_mode = True
|
| 36 |
+
st.session_state.rainbow_colors = colors
|
| 37 |
+
st.session_state.color_index = 0
|
| 38 |
+
|
| 39 |
+
def undo_last_stroke(self):
|
| 40 |
+
"""Remove the last drawing stroke"""
|
| 41 |
+
if st.session_state.drawing_history:
|
| 42 |
+
st.session_state.canvas = st.session_state.drawing_history.pop()
|
| 43 |
+
st.session_state.draw = ImageDraw.Draw(st.session_state.canvas)
|
| 44 |
+
st.rerun()
|