Breathing exercise animation
I wanted to try and make a small app to help with breathing exercises. I haven't done anything with animation/ui yet, so I was wondering if anyone could help me with a starting point. I want the animation to do the following:
- Have a circle expand for x seconds
- Pauze for y seconds
- Have the circle contract in z seconds
- Pauze for a seconds
- Repeat for b minutes
Ultimately it would be nice to have all the settings and duration configurable in the ui, but changing the values directly in the script is no problem.
I thought the analog clock example would be a good starting point, but when I understood that one and tried to figure out how to use that approach for this use case, I got the feeling that the updating step would become more complex than necessary.
What would be a good starting point for this?
You can do that using the
scenemodule. Your circle could be either a
SpriteNode. Then, you would use an Action to animate, using
Action.scale_to(scale[, duration, timing_mode])
So you might have something like
# this will be all in setup # Could have different timing mode or durations... action_inhale=Action.scale_to(2.0, 5.0, scene.TIMING_EASE_IN_OUT) action_inhale=Action.scale_to(1.0, 5.0, scene.TIMING_EASE_IN_OUT) action_breath=Action.sequence(action_inhale, action_exhale) action_breathing=Action.repeat_forever(action_breath) # or, maybe repeat specific number of times circle=ShapeNode(ui.Path.oval(0,0,100,100), fill_color="orange") # ... Set position, add as child to scene, etc # ... circle.run_action(action_breathing) #alternatively, you could kick this off due to some action, menu, etc.
I didn't include the pauses, but those would just be Action.wait(duration) added to your sequence.
Thank you, that was exactly the starting point I needed! I managed to get it working, now I just need to position everything and make it look good.