import processing.opengl.*; float currentZ = 865; float currentX = 10.442629; long currentFrame = 0; int xCount = 30; int yCount = 30; int segmentCount = xCount * yCount; color[] colors = new color[5]; int[] framesUntilLaunch = new int[segmentCount]; int currentIndex = 0; float[] velocity = new float[segmentCount]; float[] zPos = new float[segmentCount]; boolean[] hasBeenKicked = new boolean[segmentCount]; boolean[] inMotion = new boolean[segmentCount]; int[] colorIndex = new int[segmentCount]; float[] rotationSpeed = new float[segmentCount]; float a = 0; void setup () { for(int j = 0; j < yCount; j++) { for (int i = 0; i < xCount; i++) { currentIndex = j*yCount + i; framesUntilLaunch[currentIndex] = (int) ((float)60 * ((float)j/(float)yCount)) + (int)random(60); colorIndex[currentIndex] = (int) random(colors.length); rotationSpeed[currentIndex] = random(10); } } size(1280, 1024, OPENGL); frameRate(60); fill(255,128,0); noStroke(); smooth(); colors[0] = #fcfff4; colors[1] = #ccd8cd; colors[2] = #85a2aa; colors[3] = #3e6171; colors[4] = #172841; } void draw() { lights(); currentFrame++; a += 0.01; background(255); translate(100,500,currentZ); rotateX(currentX); for ( int j = 0; j < yCount; j++) { for( int i = 0; i < xCount; i++) { currentIndex = j*yCount + i; pushMatrix(); if (inMotion[currentIndex]) { fill(colors[colorIndex[currentIndex]], 255); zPos[currentIndex] = zPos[currentIndex] + velocity[currentIndex]; velocity[currentIndex] = velocity[currentIndex] - .02; if (zPos[currentIndex] <= 0) { zPos[currentIndex] = 0; inMotion[currentIndex] = false; } } else { fill(50,10); } translate(i*30,j*30,zPos[currentIndex]); if ( framesUntilLaunch[currentIndex] < currentFrame ) { if ( !hasBeenKicked[currentIndex] ) { hasBeenKicked[currentIndex] = true; velocity[currentIndex] = random(5); inMotion[currentIndex] = true; } } if (inMotion[currentIndex] ) { rotateY(a * rotationSpeed[currentIndex]); rotateX(a * rotationSpeed[currentIndex] * 2); rotateZ(a* rotationSpeed[currentIndex] * 0.5); } rect(0,0,20,20); popMatrix(); } } } void mousePressed() { currentFrame = 0; for( int i = 0; i < segmentCount; i++) { hasBeenKicked[i] = false; zPos[i] = 0; } } void keyPressed() { if (key == ENTER) { currentFrame = 0; for( int i = 0; i < segmentCount; i++) { hasBeenKicked[i] = false; zPos[i] = 0; } } if (key == CODED) { if (keyCode == UP) { currentZ += 5; } else if (keyCode == DOWN) { currentZ -=5; } else if (keyCode == LEFT) { currentX -= 0.01; } else if ( keyCode == RIGHT) { currentX += 0.01; } } }