// UdK Computational design // Marius Watz 2003 // http://www.evolutionzone.com/udk/ // // UDK02_02_direction_changing // // Changing both speed and direction every frame. float x,y,xD,yD; float dir,speed,minSpeed,maxSpeed; float fract,fractD; void setup() { size(300,400); ellipseMode(CENTER_DIAMETER); fractD=0.05f; fract=1; minSpeed=0.1; maxSpeed=2; speed=(maxSpeed-minSpeed)/2+minSpeed; dir=random(radians(360)); x=random(width); y=random(height); } void loop() { background(150,140,140); dir=dir+random(-radians(3),radians(3)); speed=speed+random(-0.1,0.1); if(speedmaxSpeed) speed=maxSpeed; xD=cos(dir)*speed; yD=sin(dir)*speed; x=x+xD; y=y+yD; if(x<0) x=width; else if(x>width) x=0; if(y<0) y=height; else if(y>height) y=0; noStroke(); fill(255,170,0); ellipse(x,y, 20,20); }