Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

How to Generate the Sierpinski Triangle [9/10]

9. Depth of Recursion

We now present a quick image sequence of a Sierpinski triangle with increasing depth of recursion. The depth of recursion equals the level of detail.
[Run the program]

At any iteration of the main for loop, the level of detail is equal to the value of the loop's variable i. The level of detail starts from 0, ends at less than 9, and it is increased by one in each iteration of the loop. Each iteration lasts about one second, which is ensured by the call to the sleepMs function. This function produces a pause, where the argument is in milliseconds.

The end result is that a sequence of images is produced, showing the effect of increasing levels of detail of the Sierpinski triangle.

If you like this tutorial, you can use the gray sharing buttons to share it with your friends. The sharing buttons create a link to the current page. The buttons for Twitter, Facebook, Pinterest, Reddit and LinkedIn are provided.

Loading...