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

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
  Do `float` and `int` smell similar?
To highlight code blocks, use ```processing and ``` like this:
  void setup() {
    size(600, 600);