// Dartmouth CS 2, Winter 2009, Chris Bailey-Kellogg // Notes 22 | Sketch 5 float[] x, y; // Coordinates of the points on the curve int depth; // How deeply we've recurse void setup() { size(400,400); background(255); initDragon(); drawCurve(x,y); } void draw() {} // Each time the mouse is pressed, recurse one more level void mousePressed() { background(255); depth++; if (depth==15) initDragon(); // wrap around else expandDragon(); println(depth); drawCurve(x,y); } // Set up the initial curve -- a horizontal line void initDragon() { depth = 0; x = new float[2]; y = new float[2]; x[0] = width/4; y[0] = height/2; x[1] = width*3/4; y[1] = height/2; } // Update the points by treating each segment as the hypotenuse // and replacing it with the other sides of a right triangle void expandDragon() { // new points int l2 = 1 + 2*(x.length-1); float[] x2 = new float[l2], y2 = new float[l2]; // index into new points int i2=0; // alternate left/right int dir=-1; for (int i=0; i