SCROLL TO THE BOTTOM TO SEE THE FIGURE

> # Koch Snowflake
# from Greg Fee
# Simon Fraser University, Dec98
Koch := proc(n)
local e,x,y,d,ox,oy,i,j,L,cp;
e := 4;
x := hfarray(1..e); y := hfarray(1..e);
x[1]:=-1; x[2]:=.5; x[3]:=x[2]; x[4]:=x[1];
y[1]:=0; y[2]:=evalhf(sqrt(.75)); y[3]:=-y[2];y[4]:=0;
for i from 2 to n do
d := e;
ox := hfarray(1..d); oy := hfarray(1..d);
for j to d do ox[j] := x[j]; oy[j] := y[j]; od;
e := 4*d-3; x := hfarray(1..e);
y := hfarray(1..e);
evalhf(next_Koch(d,ox,oy,e,x,y));
od;
L := [seq([x[i],y[i]],i=1..e)];
cp :=[0,0,0]: # for varied colour;
cp[1 + (n mod 3)]:=1;
SCALING(CONSTRAINED),AXESSTYLE(NONE);
PLOT(CURVES(L,COLOUR(RGB,op(cp))),%);
end;

Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...
Koch := proc (n) local e, x, y, d, ox, oy, i, j, L,...

>

next_Koch := proc(d,ox,oy,e,x,y)
local j,tr,ux,uy,i,px,py,qx,qy,dx,dy;
j := 0; tr := evalhf(1/3);
ux := .5; uy := evalhf(sqrt(.75));
qx := ox[1]; qy := oy[1];
for i from 2 to d do
px := qx; qx := ox[i]; py := qy; qy := oy[i];
j := j+1; x[j] := px; y[j] := py; j := j+1;
dx := qx-px; dy := qy-py; dx := tr*dx; dy := tr*dy;
x[j] := px+dx; y[j] := py+dy;
x[j+1] := x[j]+ux*dx-uy*dy; y[j+1] := y[j]+ux*dy+uy*dx;
x[j+2] := x[j]+dx; y[j+2] := y[j]+dy; j := j+2;
od;
j := j+1; x[j] := qx; y[j] := qy;
end;

next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...
next_Koch := proc (d, ox, oy, e, x, y) local j, tr,...

Using Options/Plot Display/Window brings the figure up in a separate window.

> with(plots): display(seq(Koch(l),l=1..7),
title=`Koch Snowflake`,titlefont=[TIMES,BOLD,30]);
# Plots the closed fractals over each other

[Maple Plot]

>