// UdK Computational design // Marius Watz 2003 // http://www.evolutionzone.com/udk/ // // UDK02_01_accel_02 // // Moving to a new position with acceleration. float fract,fractD; float x,y,xD,yD,newX,newY; float steps; void setup() { size(300,400); ellipseMode(CENTER_DIAMETER); steps=60; fractD=1.0/(steps-1); x=random(width); y=random(height); newMove(); } void loop() { float time; background(150,140,140); fract+=fractD; if(fract>=1) { x=newX; y=newY; newMove(); } stroke(255); line(x,y, newX,newY); noStroke(); fill(255,170,0); // time=linear(fract); // time=sinAccel(fract); // time=squareDecel(fract); // time=squareAccel(fract); time=quadAccel(fract); ellipse(x+xD*time,y+yD*time, 20,20); } void newMove() { newX=random(width); newY=random(height); xD=newX-x; yD=newY-y; fract=0; } // Linear movement, no acceleration or deceleration float linear(float theFract) { return theFract; } // Pretty slow start, pretty fast finish float squareAccel(float theFract) { return theFract*theFract; } // Very slow start, very fast finish float quadAccel(float theFract) { return theFract*theFract*theFract*theFract; } // Starts quick then slows down float sinAccel(float theFract) { return sin(PI*0.5*theFract); } // Same as squareAccel, but decelerates float squareDecel(float theFract) { return (1-(theFract-1)*(theFract-1)); }