SET WINDOW 0,1,0,1
CALL Koch(0,0,1,0)
END
EXTERNAL SUB Koch(x0,y0,x4,y4)
IF SQR((x4-x0)^2+(y4-y0)^2)<0.001 THEN   ! Moderate 0.001 acording to the screen resolution.
   PLOT LINES:x0,y0; x4,y4
ELSE
   LET x1=(2*x0+x4)/3
   LET y1=(2*y0+y4)/3
   LET x3=(x0+2*x4)/3
   LET y3=(y0+2*y4)/3
   LET x2=x1+COS(PI/3)*(x3-x1)-SIN(PI/3)*(y3-y1)
   LET y2=y1+SIN(PI/3)*(x3-x1)+COS(PI/3)*(y3-y1)
   CALL Koch(x0,y0,x1,y1)
   CALL Koch(x1,y1,x2,y2)
   CALL Koch(x2,y2,x3,y3)
   CALL Koch(x3,y3,x4,y4)
END IF
END SUB
