The trick
Join the midpoints of the sides and you get three triangles in the corners and a hole in the middle. Do the same with each one. The code is a function that calls itself three times until it reaches level 0, and paints there.
The Sierpinski triangle: a triangle that splits into three triangles, which split into three triangles, which split into three… Raise the level and watch it divide.
Join the midpoints of the sides and you get three triangles in the corners and a hole in the middle. Do the same with each one. The code is a function that calls itself three times until it reaches level 0, and paints there.
Each level triples the triangles (3n) and keeps 3/4 of the area. At level 8 there are already 6,561 triangles and 10% of the area is left: if you kept going forever, the area would be 0.
JavaScript with no libraries on a 2D <canvas>: recursion, midpoints and one
fill() per triangle with a random color from the palette.