Sierpinski triangle is a fractal and attractive fixed set with the overall shape of an equilateral triangle. It subdivides recursively into smaller triangles.
- In the given segment of codes, a triangle is made and then draws out three other adjacent small triangles till the terminating condition which checks out whether the height of the triangle is less than 5 pixels returns true.
- We only need to verify whether a given triangle is smaller than 5 pixels since beyond that the triangles would start converging at fixed points.
- A counter colorVal is defined for in response to the aesthetic need of the triangle and in all, it cycles through all the available colours by iterating every triangle set.
- Using this methodology we can also further implement a fractal zoom and hypothetically provide an infinite zoom later.
Below is the implementation of the above approach:
- Sierpinski triangle
- bar() function in C graphics
- Mandlebrot Set in C/C++ Using Graphics
- Draw a line in C++ graphics
- Draw ellipse in C graphics
- Vector vs Raster Graphics
- Draw Rectangle in C graphics
- Computer Graphics | Antialiasing
- Applications of Computer Graphics
- How to include graphics.h in CodeBlocks?
- Segments in Computer Graphics
- Draw circle in C graphics
- bar3d() function in C graphics
- Computer Graphics | The RGB color model
- How to add "graphics.h" C/C++ library to gcc compiler in Linux
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.