Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

How to Generate the Sierpinski Triangle [2/10]

2. The Three Inscribed Triangles

The next step of generating the Sierpinski triangle is to draw three inscribed smaller triangles. Each of the three inscribed triangles can use the same color as the vertice it is touching.
[Run the program by clicking the 'Run' button]

For drawing the three smaller triangles, the mid-points of each side of the big triangle need to be computed. In the source code, the mid-points are named mid12 , mid13 , mid23 . Each of the three mid-points is later visualized in a different color (purple, azure and olive).
[Run the program]

The three inscribed triangles are visualized in colors red, orange, and cyan. Those colors match the color of the vertice that each of the inscribed triangles is touching.

Since ZedLX doesn't have a built-in function for calculating mid-points, a user-defined function MidPoint is provided at the end of the source code. There are many possible implementations of this function. The source code provides three implementations, where only the last one is actually used in this program.

Loading...