float[] x, y; // Coordinates of the points on the curve int depth; // How deeply we've recurse void setup() { size(400,400); smooth(); background(255); initKoch(); drawCurve(x,y); } void draw() {} // Each time the mouse is pressed, recurse one more level void mousePressed() { background(255); depth++; if (depth==6) initKoch(); // wrap around else expandKoch(); println(depth); drawCurve(x,y); } // Set up the initial curve -- a horizontal line void initKoch() { depth = 0; x = new float[2]; y = new float[2]; x[0] = 0; y[0] = height/2; x[1] = width; y[1] = height/2; } // Update the points by putting a triangular part jutting out // between each pair of points in the current set void expandKoch() { // new points int l2 = 1 + 4*(x.length-1); float[] x2 = new float[l2], y2 = new float[l2]; // index into new points int i2=0; for (int i=0; i