Learn creative coding writing simple programs

73. The circlebeats of a running circle

A music box can be similar to an expression that uses a modulo. Both can be used to trigger repetitive events, and both run in circles: the end connects with the beginning.
In todays episode we use the modulo to trigger a regular event. We draw a circle with a fixed size of 50 pixels, but when the event is triggered, the circle will quickly grow to 80 pixels, and then slowly shrink back to 50. The idea is to simulate a heartbeat animation, but using a circle.
With an if() statement we check if the circle has grown enough. When it has grown enough, we reverse the direction of the growth. We don't want it to grow all over the screen. Now that the circle is shrinking, we need another if() statement to make sure it does not become too small. We also need to stop the shrinking at some point.
So we could say the circle has three behaviours: waiting with a size of 50 pixels, growing to a size of 80, and shrinking back to 50. Repeat.

Tags: modulo, repeating, event

Code editor

You can make changes to the code below. Then
Below you can ask and answer questions related to this video. If your question is unrelated to the video, please post it at the Processing Forum as I'm unable to help with all of your programs and still have enough free time to eat and sleep :)
comments powered by Disqus