float rotation = 0; LivingBox[] boxen; void setup () { boxen = new LivingBox[1000]; boxen[0] = new LivingBox(0, 0, 0.95, 0.95, 1); boxen[1] = new LivingBox(0, 0, 0.1, 0.1, 0.1); boxen[2] = new LivingBox(0, 0, 0.5, 0.5 ,0.4); size(600, 400, P3D); framerate(50); colorMode(RGB, 1.0); noStroke(); } void draw () { background(0.55, 0.53, 0.5); ambientLight(0.75, 0.75, 0.75); directionalLight(1, 1, 1, 200, 200, 0); translate(300, 200, 0); rotateX(rotation); rotateY(rotation / 2); rotateZ(rotation / 3); pushMatrix(); boxen[0].move(); boxen[1].move(); boxen[2].move(); popMatrix(); rotation += 0.05; } // Classes class LivingBox { int stepSize = 5; int trailLen = 400; float posX; float posY; float[] oldPosX; float[] oldPosY; float thisRed; float thisGreen; float thisBlue; LivingBox(float x, float y, float r, float g, float b) { posX = x; posY = y; thisRed = r; thisGreen = g; thisBlue = b; oldPosX = new float[trailLen]; oldPosY = new float[trailLen]; for( int i = 0; i < trailLen; i++ ) { oldPosX[i] = 0; oldPosY[i] = 0; } } void move() { int direction = int(random(4)); if( direction == 0 ) { posX += stepSize; } if( direction == 1 ) { posX -= stepSize; } if( direction == 2 ) { posY += stepSize; } if( direction == 3 ) { posY -= stepSize; } oldPosX[0] = posX; oldPosY[0] = posY; for( int i = trailLen-1; i >= 1; i-- ) { oldPosX[i] = oldPosX[i-1]; oldPosY[i] = oldPosY[i-1]; } for( int i = 0; i < trailLen; i++ ) { pushMatrix(); fill(thisRed, thisGreen, thisBlue); rotateX(oldPosX[i]/50); rotateY(oldPosY[i]/50); translate(150, 0); box(150*i/trailLen, 20*i/trailLen, 20*i/trailLen); popMatrix(); } } }