In this assignment, you can use the second Sierpinski gasket program as a template to draw the Koch snowflake. You can use

glBegin(GL_LINES);

glVertex2f(x1,y1);

glVertex2f(x2,y2);

//etc.

glEnd();

Also you can use the GL_LINE_STRIP with all point involved. That means you need to have all your points set to use this function.To draw lines (instead of the points drawn for the gasket). Note: Points 1 and 2 are connected, 3 and 4 are connected, etc. If you list 2N points, then N lines will be drawn.

The basic recursive step in drawing a Koch snowflake is to replace an
edge P_{1}P_{5} with the four edges P_{1}P_{2},
P_{2}P_{3}, P_{3}P_{4} and P_{4}P_{5}.
Here's the idea:

This

becomes

You can construct the second drawing by replacing the middle third of
the segment with the other two edges of an equilateral triangle for which
it is the base. Hence the distances P_{2}P_{4}, P_{2}P_{3},
and P_{3}P_{4} are identical.

You can determine the points P_{2}, P_{3}, and P_{4}
using a little vector arithmetic. If we rotate the vector connecting P_{2}
and P_{4} through 60 degrees, we get the vector from P_{2}
to P_{3}. We'll call the matrix which does this rotation *R*.
Then

If your matrix multiplication or vector addition is rusty, I'll go over this during class. You may also want to go over appendices C.1 and C.2 in our text.

For example, suppose that P_{1} = (50,100) and P_{5} =
(350,100). Then the vector P_{1}P_{5} is (350-50,100-100)
= (300,0). We have P_{2} = (50,100) + (1/3) (300,0) = (50,100) +
(100,0) = (150,100) and P_{4} = (50,100) + (2/3) (300,0) = (50,100)
+ (200,0) = (250,100).

The matrix product *R* (P_{2}P_{4}) is calculated
by first deriving P_{2}P_{4} = (100,0), then *R* (P_{2}P_{4})
=

This must be added to
, which results in a point with x coordinate 200 and y coordinate 100 +
50(3)^{1/2}.

Once you can replace an edge with four edges, you can do the same thing to each of the four edges. In pseudocode, you want to write a Flake function like this:

to Flake(n, P1, P5)

if n is 0, then simply connect P1 to P5

else Flake(n-1,P1,P2), Flake(n-1,P2,P3), Flake(n-1,P3,P4) and Flake(n-1,P4,P5)

where P2, P3 and P4 are determined as above.