ArrayList angels = new ArrayList(); Kid k = new Kid(); PGraphics buf; //PGraphics bufmain = g; void setup(){ size(500,500); frameRate(30); buf = createGraphics(width,height,JAVA2D); resetSnow(); } void reset(){ resetSnow(); } void resetSnow(){ angels = new ArrayList(); } void keyPressed(){ if(key == ' '){ resetSnow(); } } void draw(){ background(255); //PImage img = buf.get(0,0,width,height); //image(img,0,0); udpateR(); drawAngels(); //k.rot += .1; k.draw(); if(currentAngel == null){ if(mousePressed){ ticksDown++; if(ticksDown == TICKSWAIT){ currentAngel = new Angel(k); } } } else { ticksDown = 0; } } Angel currentAngel = null; int ticksDown = 0; int TICKSWAIT = 15; void mousePressed(){ ticksDown = 0; } void mouseReleased(){ if(currentAngel == null) return; angels.add(currentAngel); currentAngel = null; } void drawAngels(){ for(Angel a : angels){ a.draw(); } if(currentAngel != null) currentAngel.draw(); } void mouseDragged(){ if(currentAngel != null) return; k.rot += (mouseX-pmouseX) / 80.0 + (mouseY-pmouseY) / 100.0; k.x=mouseX; k.y = mouseY; ticksDown = 0; } void udpateR(){ if(currentAngel != null){ if(rup){ r += .1; if(r > PI/4){ rup = false; r = PI/4; } } else { r -= .1; if(r < 0){ rup = true; r = 0; } } } if(currentAngel != null){ currentAngel.record(r); } } float r; boolean rup = true; class Angel extends Kid{ float min, max; boolean first = true; Angel(Kid k){ x = k.x; y = k.y; rot = k.rot; } void record(r){ if(first){ min = max = r; first = false; } if(r < min) min = r; if(r > max) max = r; } void draw(){ pushMatrix(); translate(x,y); rotate(rot); drawSuit(false,this); popMatrix(); } } class Kid{ float x =125; float y = 125; float rot; void draw(){ // r+=.1; pushMatrix(); translate(x,y); rotate(rot); drawSuit(true,null); //outline drawSuit(false,null); // // drawSuit(false,true); popMatrix(); } float TORSOWIDTH = 32; float TORSOHEIGHT = 48; float LEGWIDTH = 12; float LEGHEIGHT = 24; float LEGOUT = 8; float ARMWIDTH = 12; float ARMLENGTH = 40; float HEADWIDTH = 27; color blue = color(40,100,240); color red = color(240,100,40); color bootgrey = color(128); color skin = color(255,225,200); void drawSuit(boolean isBG,Angel angel){ blue = color(40,100,240); red = color(240,100,40); bootgrey = color(128); skin = color(255,225,200); drawingBG = isBG if(angel != null){ red = bootgrey = skin = blue = color(225); } setPens(blue,drawingBG); rect(-TORSOWIDTH/2,-TORSOHEIGHT/2,TORSOWIDTH,TORSOHEIGHT); if(angel == null) { //just do one drawLeftLeg(r); drawRightLeg(r); drawLeftArm(r); drawRightArm(r); } else { int sects = 4; float d = (angel.max - angel.min) / sects; for(int i = 0; i <= sects; i++){ float rox = angel.min + (d * i); drawLeftLeg(rox); drawRightLeg(rox); drawLeftArm(rox); drawRightArm(rox); } } //setPens(bootgrey,drawingBG); ellipse(0,-HEADWIDTH/2, HEADWIDTH*1.5,HEADWIDTH*1.5);//ruff setPens(skin,drawingBG); ellipse(0,-HEADWIDTH/2, HEADWIDTH,HEADWIDTH);//face } void drawLeftLeg(float r){ //left leg pushMatrix(); translate(-LEGOUT,TORSOHEIGHT/2); rotate(r/2); rect(-LEGWIDTH/2,0,LEGWIDTH,LEGHEIGHT); setPens(bootgrey,drawingBG); rect(-LEGWIDTH/2,LEGHEIGHT*2/3,LEGWIDTH,LEGHEIGHT/3); setPens(blue,drawingBG); popMatrix(); } void drawRightLeg(float r){ //right leg pushMatrix(); translate(LEGOUT,TORSOHEIGHT/2); rotate(-r/2); rect(-LEGWIDTH/2,0,LEGWIDTH,LEGHEIGHT); setPens(bootgrey,drawingBG); rect(-LEGWIDTH/2,LEGHEIGHT*2/3,LEGWIDTH,LEGHEIGHT/3); setPens(blue,drawingBG); popMatrix(); } void drawLeftArm(float r){ //left arm pushMatrix(); translate(-TORSOWIDTH/4,0); rotate(PI*3/8 + (r * 1.25)); rect(-ARMWIDTH/2,0,ARMWIDTH,ARMLENGTH); setPens(red,drawingBG); rect(-ARMWIDTH/2,ARMLENGTH*3/4,ARMWIDTH,ARMLENGTH/4); setPens(blue,drawingBG); popMatrix(); } void drawRightArm(float r){ //right arm pushMatrix(); translate(TORSOWIDTH/4,0); rotate(-PI*3/8 - (r * 1.25)); rect(-ARMWIDTH/2,0,ARMWIDTH,ARMLENGTH); setPens(red,drawingBG); rect(-ARMWIDTH/2,ARMLENGTH*3/4,ARMWIDTH,ARMLENGTH/4); setPens(blue,drawingBG); popMatrix(); } void setPens(color c, boolean drawingBG){ if(drawingBG){ strokeWeight(5); fill(0); stroke(0); } else { noStroke(); fill(c); } } }