ArrayList cuts ; Cut currentCut = null; color flameColor; boolean toReset = false; void keyPressed(){ if(key == ' '){ toReset = true; } } void reset(){ cuts = new ArrayList(); currentCut = null; stem1 = random(-15,15); stem2 = random(-15,15); stem3 = random(-15,15); stem4 = random(-15,15); } void makeFlameColor(){ float r = random(.3,.5); flameColor = color(255*r,100*r,33*r); } float stem1,stem2,stem3,stem4; void setup() { size(500,500); frameRate(20); reset(); } void draw(){ background(60); makeFlameColor(); strokeWeight(3); stroke(0); fill(100,120,0); beginShape(); vertex(230+stem1,20+stem2); vertex(270+stem3,20+stem4); vertex(270,80); vertex(230,80); endShape(CLOSE); //rect(180,20,40,100); fill(255,153,51); ellipse(250,250,400,400); noFill(); stroke(128,75,25); ellipse(250,250,300,400); ellipse(250,250,200,400); ellipse(250,250,80,400); stroke(0); ellipse(250,250,400,400); //I put this in the main loop rather than //the event handler 'cause I'm worried about //the iterator... if(handleCut){ if(currentCut == null){ currentCut = new Cut(); } if(currentCut.newPoint(mouseX,mouseY)){ cuts.add(currentCut); currentCut = null; } handleCut = false; } if(toReset){ reset(); toReset = false; } for(Cut c : cuts){ c.draw(); } if(currentCut != null){ currentCut.draw(); } } boolean handleCut = false; void mousePressed(){ handleCut = true; } class Cut{ ArrayList points = new ArrayList(); boolean isDone = false; boolean isNear(Point p,float x, float y){ return dist(p.x,p.y,x,y) < 10; } //return true if this closes the thing boolean newPoint(float x, float y){ if(points.size() > 0){ Point p = (Point)points.get(0); if(isNear(p,x,y)){ isDone = true; return true; } } points.add(new Point(x,y)); return false; } void drawAsShape(){ beginShape(); for(Point p : points){ vertex(p.x,p.y); } endShape(CLOSE); } void draw(){ stroke(0); if(isDone){ noStroke(); fill(128,77,26) ; } else { noFill(); } if(isDone){ fill(128,77,26) ; pushMatrix(); for(int i = 1; i < 8; i++){ translate(1,1); drawAsShape(); } popMatrix(); fill(flameColor) ; drawAsShape(); } else { if(points.size()< 1){ return; } Point lastPoint = points.get(0);; for(int i = 0; i < points.size() - 1; i++){ Point p1 = points.get(i); Point p2 = points.get(i+1); line(p1.x,p1.y,p2.x,p2.y); lastPoint = p2; } stroke(128); fill(128); line(lastPoint.x,lastPoint.y, mouseX,mouseY); if(points.size() > 0){ Point p = (Point)points.get(0); if(isNear(p,mouseX,mouseY)){ ellipse(p.x,p.y,20,20); } } } } } class Point { float x,y; Point(float x, float y){ this.x = x; this.y = y; } }