The Sierpinski Triangle

The Sierpinski Triangle Fractal is one of the simpler fractals to understand and program. You begin by drawing a triangle (Figure 1). Then, connecting the midpoints of the triangle's sides, you construct three triangles (Figure 2). (The triangles are at the corners. The 'upside down' one in the middle is not a triangle, but is formed as a result of the other three. The process continues. In the next step, you connect the midpoints of the three smaller triangles to create three triangles in each one. (Figure 3). Continuing this process, the resulting fractal image looks like Figure 4.

Figure 1
Figure 2
Figure 3
Figure 4

Obviously, the only thing you need to get started drawing a Sierpinski Triangle is the coordinates of the three vertices of the first triangle. So, the signature for your recursive method might look like this:

public void drawSierpinski(int x1, int y1, int x2, int y2, int x3, int y3)

where (x1, y1) (x2, y2) and (x3, y3) are the coordinates of the initial triangle vertices. The vertices can be anywhere. That is, the triangle does not have to be equilateral or isosceles.