NavyDevilDoc commited on
Commit
fcc2f4f
路
verified 路
1 Parent(s): 58c406c

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +30 -14
src/streamlit_app.py CHANGED
@@ -339,7 +339,7 @@ def main():
339
 
340
  elif angle_input_method == "Auto Animation":
341
  speed = st.sidebar.slider("Animation Speed", 1, 10, 5, key="animation_speed_slider")
342
- angle_step = st.sidebar.slider("Angle Step", 5, 30, 15, key="animation_step_slider") # Smaller steps for smoother animation
343
 
344
  # Add animation controls
345
  col_anim1, col_anim2 = st.sidebar.columns(2)
@@ -348,32 +348,48 @@ def main():
348
  with col_anim2:
349
  stop_animation = st.sidebar.button("鈴癸笍 Stop", key="stop_anim_button")
350
 
351
- # Add session state for animation control
352
  if 'animation_running' not in st.session_state:
353
  st.session_state.animation_running = False
354
  if 'current_animation_angle' not in st.session_state:
355
  st.session_state.current_animation_angle = 0
 
 
356
 
357
  if start_animation:
358
  st.session_state.animation_running = True
 
359
  if stop_animation:
360
  st.session_state.animation_running = False
361
 
362
- # Optimized animation without sleep
363
  if st.session_state.animation_running:
364
- # Update angle
365
- st.session_state.current_animation_angle += angle_step
366
- if st.session_state.current_animation_angle >= 360:
367
- st.session_state.current_animation_angle = 0
368
- st.session_state.animation_running = False
369
- st.success("Animation complete!")
370
 
371
- angle = st.session_state.current_animation_angle
372
-
373
- # Use auto-refresh for animation
374
- st.rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
375
  else:
376
- angle = st.session_state.current_animation_angle
377
 
378
  else: # Common Angles
379
  common_angles = {
 
339
 
340
  elif angle_input_method == "Auto Animation":
341
  speed = st.sidebar.slider("Animation Speed", 1, 10, 5, key="animation_speed_slider")
342
+ angle_step = st.sidebar.slider("Angle Step", 5, 30, 15, key="animation_step_slider")
343
 
344
  # Add animation controls
345
  col_anim1, col_anim2 = st.sidebar.columns(2)
 
348
  with col_anim2:
349
  stop_animation = st.sidebar.button("鈴癸笍 Stop", key="stop_anim_button")
350
 
351
+ # Initialize session state for animation control
352
  if 'animation_running' not in st.session_state:
353
  st.session_state.animation_running = False
354
  if 'current_animation_angle' not in st.session_state:
355
  st.session_state.current_animation_angle = 0
356
+ if 'last_update_time' not in st.session_state:
357
+ st.session_state.last_update_time = time.time()
358
 
359
  if start_animation:
360
  st.session_state.animation_running = True
361
+ st.session_state.last_update_time = time.time()
362
  if stop_animation:
363
  st.session_state.animation_running = False
364
 
365
+ # Animation with timing control
366
  if st.session_state.animation_running:
367
+ current_time = time.time()
368
+ # Control animation speed (higher speed = faster updates)
369
+ time_threshold = 1.0 / speed # seconds between updates
 
 
 
370
 
371
+ if current_time - st.session_state.last_update_time >= time_threshold:
372
+ # Update angle
373
+ st.session_state.current_animation_angle += angle_step
374
+ if st.session_state.current_animation_angle >= 360:
375
+ st.session_state.current_animation_angle = 0
376
+ st.session_state.animation_running = False
377
+ st.success("Animation complete!")
378
+
379
+ st.session_state.last_update_time = current_time
380
+ st.rerun()
381
+ else:
382
+ # Keep checking for updates
383
+ time.sleep(0.1)
384
+ st.rerun()
385
+
386
+ angle = st.session_state.current_animation_angle
387
+
388
+ # Display current animation status
389
+ if st.session_state.animation_running:
390
+ st.sidebar.info(f"馃幀 Animating... Current angle: {angle}掳")
391
  else:
392
+ st.sidebar.info(f"鈴革笍 Animation stopped at: {angle}掳")
393
 
394
  else: # Common Angles
395
  common_angles = {