//DONE //look at target //footprints //wallbounce ArrayList prints = new ArrayList(); void keyPressed(){ if(key == ' '){ reset(); } } void reset(){ prints.clear(); } void setup(){ frameRate(30); size(500,500); smooth(); } Snowman s = new Snowman(125,125); void draw(){ background(255); if(mousePressed){ s.compress(); } for(Footprint p : prints){ p.draw(); } s.move(); s.draw(); } void mouseMoved(){ // s.a = map(mouseX,0,250,-2*PI,2*PI); } void mouseReleased(){ s.release(); } class Snowman{ float x,y; float a = 0;// PI+ .01; float aNose,aEye1,aEye2; float sz = 30; float COMPRESSMAX = sz /4; float compression = 0; float yspeed, yoff; float aJump; Snowman(float px, float py){ x = px; y = py; } void compress(){ if(compression < COMPRESSMAX) compression += (compression + COMPRESSMAX) / 15; } void release(){ if(yoff <= 0){ prints.add(new Footprint(this)); } yspeed = compression*2/3; aJump = a + (PI/2); compression = 0; } float GRAV = .30; void move(){ a = atan2(mouseY - y, mouseX - x) - PI/2; yspeed -= GRAV; yoff += yspeed; if(yoff <= 0){ yoff = 0; yspeed = 0; } else{ x += 2*cos(aJump) ; y += 2*sin(aJump) ; if(x <= 0 || x >= 500 || y < 0 || y >= 500){ aJump += PI; } } } float fixAngle(float a){ while(a >= 2*PI) a-= 2 * PI; while(a < 0) a += 2 * PI; return a; } void draw(){ // a += .1; //print(a); a = fixAngle(a); aNose = fixAngle(a + PI/2); aEye1 = fixAngle(aNose+.3); aEye2 = fixAngle(aNose-.3); strokeWeight(3); //for the whole thig\ng pushMatrix(); translate(x,y); //shadow noStroke(); fill(180,128); ellipse(0,0+sz/4,sz,sz/2); translate(0,-yoff); if(!inFront(a)){ drawArm(a); } else { drawArm(a+PI); } fill(255); if(!inFront(aNose)) drawNose(aNose); if(!inFront(aEye1)) drawEye(aEye1); if(!inFront(aEye2)) drawEye(aEye2); stroke(0); ellipse(0,0,sz,sz); //head; pushMatrix(); translate(0,(-sz*.6) + compression); ellipse(0,0,sz*.75,sz*.75); fill(0); ellipse(0,-sz*.25,sz*.75,sz*.25); ellipse(0,-sz*.6,sz*.4,sz*.10); noStroke(); // fill(255,0,0,100); rect(-sz*.25,-sz*.6,sz*.5,sz*.3); popMatrix(); if(inFront(a)){ drawArm(a); } else { drawArm(a+PI); } if(inFront(aNose)) drawNose(aNose); if(inFront(aEye1)) drawEye(aEye1); if(inFront(aEye2)) drawEye(aEye2); popMatrix(); } boolean inFront(float a){ return (a >= 0 && a <= PI); } void drawArm(float a){ stroke(60,60,0); float a1sx = cos(a) * sz*.5; float a1sy = sin(a) * sz*.5 * .25; float a1ex = cos(a) * sz; float a1ey = sin(a) * sz * .25; line(a1sx,a1sy,a1ex,a1ey); } void drawNose(float a){ stroke(160,160,0); float INNER = .4; float OUTTER = .6; float a1sx = cos(a) * sz*INNER; float a1sy = sin(a) * sz*INNER * .25; float a1ex = cos(a) * sz*OUTTER; float a1ey = sin(a) * sz * OUTTER *.25; pushMatrix(); translate(0,compression -sz*.6); line(a1sx,a1sy,a1ex,a1ey); popMatrix(); } void drawEye(float a){ stroke(0); float a1sx = cos(a) * sz *.4; float a1sy = sin(a) * sz *.4 *.25; pushMatrix(); translate(0,compression - sz * .66); line(a1sx,a1sy,a1sx,a1sy); popMatrix(); } } class Footprint{ float x,y,sz; Footprint(Snowman s){ x = s.x; y = s.y; sz = s.sz; } void draw(){ noStroke(); fill(235); ellipse(x,y+sz/4,sz,sz/2); } }