Forum Archive

Breathing exercise animation

Rosanne

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:

  1. Have a circle expand for x seconds
  2. Pauze for y seconds
  3. Have the circle contract in z seconds
  4. Pauze for a seconds
  5. 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?

JonB

You can do that using the scene module. Your circle could be either a ShapeNode or 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.

JonB

I didn't include the pauses, but those would just be Action.wait(duration) added to your sequence.

Rosanne

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.