Learn creative coding writing simple programs

72. Create visual rhythms using modulo

With the modulo function we can trigger events at regular intervals. If we have a variable "n" that increases each time draw() is called, we can write if(n % 11 == 0) { ... } to do something every 11th frame. The 0 value can be any value between 0 and 10. If you want to trigger just one event, that number is not important. But if you want to trigger two consecutive events, then you can for example use n % 11 == 4 for the first event, and n % 11 == 5 for the second event. For all the other values (0, 1, 2, 3, 6, 7, 8, 9, 10) nothing would happen. Don't worry if you don't understand how it works yet. Try watching the video and writing the example programs. We will keep working on it on coming episodes.

Tags: modulo, rhythm, animation, timing, events

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