PImage back, back2; PGraphics paint; ArrayList arms, trees; int authoring_state, paint_size, arm_type; PVector ptl, ptr, pbr, pbl; PictureSaver pic_saver; class CyclerArm extends Arm { /* Subclass of Arm that does "spirograph" style loops */ CyclerArm(int cx, int cy, float a1, float a2, int len, color colour, float da1, float da2) { super(cx,cy,a1,a2,len,colour); this.da1 = da1; this.da2 = da2; } void update() { a1 = a1 + da1; a2 = a2 - da2; timer_update(); } } class SpiralArm extends Arm { /* Subclass of Arm which draws Hundertwasserish square spirals */ PVector hare, bound1, bound2, velocity; int direction; int margin, speed; SpiralArm(int cx, int cy, int len, color colour) { super(cx, cy, 0, 0, len, colour); hare = new PVector(190,100); bound1 = new PVector(0,0); bound2 = new PVector(200,200); velocity = new PVector(0,1); direction = DOWN; margin = 10; speed = 9; } void update() { hare.add(velocity); switch (direction) { case DOWN : if (hare.y > bound2.y-margin) { velocity= new PVector(-1,0); direction = LEFT; bound2.y = bound2.y - speed; println(hare.x+","+hare.y+" bottom"+" "+bound1.x+","+bound1.y+"--"+bound2.x+","+bound2.y); } break; case LEFT : if (hare.x < bound1.x+margin) { velocity = new PVector(0,-1); direction = UP; bound1.x = bound1.x + speed; println(hare.x+","+hare.y+" left"+" "+bound1.x+","+bound1.y+"--"+bound2.x+","+bound2.y); } break; case RIGHT : if (hare.x > bound2.x-margin) { velocity = new PVector(0,1); direction = DOWN; bound2.x = bound2.x - speed; println(hare.x+","+hare.y+" right"+" "+bound1.x+","+bound1.y+"--"+bound2.x+","+bound2.y); } break; case UP : if (hare.y < bound1.y+margin) { velocity = new PVector(1,0); direction = RIGHT; bound1.y = bound1.y + speed; println(hare.x+","+hare.y+" top"+" "+bound1.x+","+bound1.y+"--"+bound2.x+","+bound2.y); } break; } if (draw_boundaries) { PVector th = trans(new PVector(hare.x,hare.y)); fill(50,50,255); ellipse(th.x,th.y,4,4); PVector p1, p2, p3, p4; p1 = trans(new PVector(bound1.x,bound1.y)); p2 = trans(new PVector(bound2.x,bound1.y)); p3 = trans(new PVector(bound2.x,bound2.y)); p4 = trans(new PVector(bound1.x,bound2.y)); strokeWeight(2); stroke(50,50,255); line(p1.x,p1.y,p2.x,p2.y); line(p2.x,p2.y,p3.x,p3.y); line(p3.x,p3.y,p4.x,p4.y); line(p4.x,p4.y,p1.x,p1.y); } move_towards(hare.x, hare.y); timer_update(); } void joggle() { super.joggle(); bound1 = new PVector(0,0); bound2 = new PVector(200,200); } } class PictureSaver { int pic_number; PictureSaver() { pic_number = 0; } void save_it() { save("window_right"+pic_number+".jpg"); pic_number=pic_number+1; } } void setup() { size(375,500); my_setup(""); init_paint(); authoring_state = 0; arm_type = 0; pic_saver = new PictureSaver(); } void my_setup(String pic) { if (pic != "") { back = loadImage(pic); back.loadPixels(); back2 = loadImage(pic); back2.loadPixels(); } else { back = null; } noStroke(); arms = new ArrayList(); trees = new ArrayList(); init_paint(); } void init_paint() { paint_size = 2; paint = createGraphics(375, 500, P2D); paint.smooth(); paint.strokeWeight(3); } void draw() { if (back == null) { background(200); } else { background(back); } pushMatrix(); for (int i=0;i 0) { a = (Arm)arms.get(arms.size()-1); } else { break; } a.joggle(); break; case ',' : if (arms.size() > 0) { a = (Arm)arms.get(arms.size()-1); } else { break; } a.da1 = a.da1 + 0.01; break; case '.' : if (arms.size() > 0) { a = (Arm)arms.get(arms.size()-1); } else { break; } a.da1 = a.da1 - 0.01; break; case 'l' : if (arms.size() > 0) { a = (Arm)arms.get(arms.size()-1); } else { break; } a.da2 = a.da2 + 0.01; break; case ';' : if (arms.size() > 0) { a = (Arm)arms.get(arms.size()-1); } else { break; } a.da2 = a.da2 - 0.01; break; case ' ' : // start an arm authoring_state = 0; break; case 't' : // do a tree authoring_state = 10; break; case 'p' : // save a screen-shot pic_saver.save_it(); break; case 'r' : // remove arm if (arms.size() > 0) { arms.remove(arms.size()-1); } break; case '1' : paint_size=1; break; case '2' : paint_size=2; break; case '3' : paint_size=3; break; case '4' : paint_size=4; break; case '5' : paint_size=5; break; case '6' : paint_size=6; break; case 'y' : arm_type = 0; break; case 'u' : arm_type = 1; break; case 'i' : arm_type = 2; break; case 'o' : arm_type = 3; break; case '=' : Arm b; for (int i=0;i