// UdK Computational design // Marius Watz 2003 // http://www.evolutionzone.com/udk/ // // UDK02_02_direction // // Changing speed and direction by using states. float x,y,xD,yD; float dir,speed; int state,stateCnt; int SLOW=0,FAST=1; void setup() { size(300,400); ellipseMode(CENTER_DIAMETER); state=SLOW; stateCnt=200; speed=1; dir=random(radians(360)); x=random(width); y=random(height); } void loop() { background(150,140,140); stateCnt--; if(stateCnt==0) newMove(); 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); } void newMove() { stateCnt=100+(int)random(100); if(state==SLOW) { state=FAST; speed=3+random(2); } else { state=SLOW; speed=0.5+random(1); } dir=random(radians(360)); }