Learn creative coding writing simple programs

140. Recursive graphics

Using recursion in computer programs allows us to generate beautiful and complex images with simple programs. Recursion is simply achieved by writing a function that calls itself one or more times.

To avoid giving a headache to our computer, it's important to set a limit in how many times the function can call itself. Otherwise it will attempt to call itself infinite times, and the computer will stop liking you. There are different ways to set a limit. You can use a variable to count the recursion depth, and stop when the depth is enough for you. You could also set a limit by drawing shapes that get smaller and smaller, and then stop when they are small enough.

In this episode, instead of coming up with random colors for the program, I use a color picker called Gcolor2 to grab colors from a photo. In Windows you can use picpick.org, and in Mac "DigitalColor Meter", already installed by default.

Check episodes 67 and 68 if the sin() / cos() part is confusing.

Tags: recursion, recursive, lerpColor

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