import processing.opengl.*; int segmentCount = 20; float a = 0; float b= 0; float currentZ = 0; color[] colors = new color[5]; float[] rotation1 = new float[segmentCount]; float[] rotation2 = new float[segmentCount]; int[] rotationDir = new int[segmentCount]; void setup () { size(1280, 1024, OPENGL); frameRate(60); fill(255,128,0); noStroke(); smooth(); background(0); colors[0] = #cc00e6; colors[1] = #ef1702; colors[2] = #ff6e02; colors[3] = #1769cd; colors[4] = #ffed00; for (int i = 0; i < segmentCount; i++) { rotation1[i] = random(1); println(rotation1[i]); rotation2[i] = random(1); // rotationDir[i] = (int)random(3); rotationDir[i] = (int) random(2); println(rotationDir[i]); } } void draw() { lights(); background(0); a = a + 0.005; b = sin(a/10); translate(500,500,currentZ); pushMatrix(); rotateZ(a); rotateX(a*0.2); box(20); for ( int j = 0; j < 20; j++) { fill( colors[j%5] ); for( int i = 0; i < 10; i++) { if ( rotationDir[j] == 0 ) { rotateX(rotation1[j]*b); rotateZ(0.05); // if (random(100) < 98) { rect(0,0,10,10); } translate(0,15); // rotateY(rotation2[j]*b); } else if ( rotationDir[j] == 1) { rotateY(rotation1[j]*b); rect(0,0,10,10); translate(15,0); // rotateZ(rotation2[j]*b); } else { rotateX(rotation1[j]*b); // rotateZ(rotation1[j]*b); } } } popMatrix(); } void keyPressed() { if (key == CODED) { if (keyCode == UP) { currentZ += 5; } else if (keyCode == DOWN) { currentZ -=5; } } }