Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

How to Generate the Sierpinski Triangle [7/10]

7. Coloring the Sierpinski Triangle

The Sierpinski triangle is now displayed in completely different colors, compared to the image produced by the previous page.
[Run the program]

The clearScr function allows a default background color and a default drawing color to be provided. It enables both colors to be specified in the single line of the source code. In the source code, the single call to the function trianglep does not specify an explicit color anymore, which makes it use the default drawing color.

Compared to the previous page, the number of levels has been increased to 7. As the number of levels of the Sierpinski triangle is being increased, the triangle will actually become thinner and thinner. With a sufficiently high number of levels, the entire triangle would disappear, as the Sierpinski triangle has a total area of zero. At the same time, it has infinite sum of all edge lengths. It is an extraordinary shape, indeed.
[Run the program]

On the next page, RGB triplets are used for coloring the Sierpinski triangle.

Loading...