float base = 0; float sz = 50; import gifAnimation.*; GifMaker gifExport; void setup() { size(225,425); gifExport = new GifMaker(this, "easer.gif"); gifExport.setRepeat(0); // make it an "endless" animation // gifExport.setTransparent(255,255,255); // black is transparent textAlign(CENTER,CENTER); } void draw(){ if(base > 1.0){ gifExport.setDelay(10); gifExport.addFrame(); gifExport.finish(); noLoop(); return; } background(255); fill(255,0,0); //noStroke(); doTriangle(50,50,base, "Linear"); doTriangle(150,50,beesEase(base),"Bees (3x^2-2x^3)"); doTriangle(50,200,ease(base,1),"Easing g=1"); doTriangle(150,200,ease(base,2),"Easing g=2"); doTriangle(50,350,ease(base,4),"Easing g=4"); doTriangle(150,350,ease(base,8),"Easing g=8"); gifExport.setDelay(1); gifExport.addFrame(); base += .025; } void doTriangle(float x,float y,float rot, String t){ pushMatrix(); translate(x,y); pushMatrix(); rotate(2 * PI * rot); triangle(cos(0) * sz, sin(0)*sz, cos((4*PI)/3 ) * sz, sin((4*PI)/3)*sz, cos((2*PI)/3) * sz, sin((2*PI)/3)*sz ); popMatrix(); text(t,0,60); popMatrix(); } float beesEase(float x){ return 3 * x *x - 2 * x * x *x; } float ease(float p, float g){ if (p < 0.5) return 0.5 * pow(2*p, g); else return 1 - 0.5 * pow(2*(1 - p), g); }