Fractal built from a substitution system.
The Koch curve is the pattern obtained by taking a single line, dividing it in three equal parts, and drawing an equilateral triangle in the middle section—therefore obtaining four child lines—as shown in the following picture:
This operation is repeated infinitely for each of the child lines thus obtained, giving a fractal that was built from a substitution system (each line is substituted for four other lines).
The Macromedia Flash animation shown here takes four such lines placed one after the other and applies the substitution rules five times, therefore giving something that looks like an island. Different results are obtained depending on the way the points are placed, and in which order they are placed; for example if two of the points are superposed and the others arranged in an equilateral triangle, we obtain what is known as the Koch snowflake (if the points are placed clockwise), or the Koch anti-snowflake (if the points are placed counter-clockwise).
In the program, a stack is used to keep a list of lines to drawn at each depth of the substitution system. When a line is substituted, the equilateral triangle gets placed on the left side of the vector (from point
1 to point
2 of the line) by using a rotation matrix.
Plaintext source of this program, released under the GPL.