omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Breathing exercise animation

    Pythonista
    2
    4
    620
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Rosanne
      Rosanne last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        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 1 Reply Last reply Reply Quote 0
        • JonB
          JonB @JonB last edited by

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

          1 Reply Last reply Reply Quote 0
          • Rosanne
            Rosanne last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors