ArrayList tails = new ArrayList(); ArrayList mane = new ArrayList(); void setup(){ frameRate(30); smooth(); size(500,500); for(int i = 1; i < 3;i++){ tails.add(new TailAngle(i*.01,true)); } for(int i = 0; i < 4;i++){ mane.add(new TailAngle(random(0.01,.05),false)); } // frameRate(3); } color BROWN = color(128,64,0); color DARKBROWN = color(64,32,0); color SKYBLUE = color(128,128,255); color RED = color(220,0,0); color YELLOW = color(200,200,0); float MID = 250; float a = 0; float as; float wa; //wanted angle void draw(){ background(color(120,255,120)); pushMatrix(); translate(-20+MID+sin(a)*40,30+MID-abs(sin(a)*40)); rotate(a); fill(BROWN); strokeWeight(2); stroke(0); rect(-80,-80,40,160); rect(40,-80,40,170); //head and neck pushMatrix(); translate(80,-120); rotate(-PI/4); //neck rect(-10,-10,60,60); //head quad(40,-10,120,-10,80,110,40,110); // rect(20,-5,40,60); //ear triangle(60,-10,100,-10,90,-40); fill(0); ellipse(70,20,20,20); ellipse(70,90,10,10); popMatrix(); fill(BROWN); //body rect(-120,-120,240,120); //saddle fill(DARKBROWN); arc(0,-120,160,160,0,PI); pushMatrix(); //tail fill(YELLOW); translate(-130,-120); // println(-a/PI); for(TailAngle ta : tails){ pushMatrix(); ta.move(); rotate(ta.ta); rect(0,0,10,120); popMatrix(); } popMatrix(); fill(RED); arc(0,80,400,160,0,PI); line(-200,80,200,80); fill(YELLOW); pushMatrix(); translate(80,-120); rotate(-PI/4); //mane float over = 0.0; for(TailAngle m : mane){ m.move(); pushMatrix(); translate(over,-10); rotate(m.ta); rect(0,0,6,40); popMatrix(); over += 20; } popMatrix(); popMatrix(); if(! mousePressed){ as-= a/20; a += as; as *= .97; } else { if(a < wa) { a+= .05; } if(a > wa) { a-= .05; } } } void mousePressed(){ wa = constrain(map(mouseX,0,width,-PI/3,PI/3),-PI/3,PI/3); //println(a/PI+" "+sin(a)+" "+cos(a)); as = 0; } void mouseDragged(){ wa = constrain(map(mouseX,0,width,-PI/3,PI/3),-PI/3,PI/3); } class TailAngle{ float ta = 0; float twa = 0; float tag; float tas; boolean stop; TailAngle(float ps, boolean pstop){ tag = ps; stop = pstop; } void move(){ twa = -a; if(! stop){ twa += PI/4; tas *= .9; } if(ta < twa){ tas += tag; } if(ta > twa){ tas -= tag; } ta += tas; if(stop){ if(ta < 0){ ta = 0; tas *= -.2; } } if(stop && ta < 0.01 && tas < 0.01){ ta = 0.0; tas = 0.0; } if(!stop && tas < .01 && abs(ta - twa) < 0.01){ ta = twa; tas = 0.0; } } }