/* Pulsating grid of translucent cubes, loosely based on the 'CubicGrid' example. */ int xCubes = 10; int yCubes = 8; int zCubes = 6; float cubeSize = 50; float depth = 400; int colorScale = 25; void setup () { size ( 700, 500, P3D ); noStroke (); } void draw () { background ( 0 ); // set viewing position translate ( width/2, height/2, -depth/2 ); rotateY ( frameCount*PI/193 ); rotateX ( frameCount*PI/233 ); rotateZ ( frameCount*PI/401 ); float sin133 = sin(frameCount*PI/133); float sin177 = sin(frameCount*PI/177); float sin203 = sin(frameCount*PI/203); float cos67 = cos(frameCount*PI/67); float cos183 = cos(frameCount*PI/183); float cos277 = cos(frameCount*PI/277); // build grid by translation in each dimension for ( int x = 0; x < xCubes; ++x ) { float xBase = (x - xCubes / 2.0f) * cubeSize * 2; float xf = cos( x * PI / xCubes ); for ( int y = 0; y < yCubes; ++y ) { float yBase = (y - yCubes / 2.0f) * cubeSize * 2; float yf = sin( y * PI / yCubes ); for ( int z = 0; z < zCubes; ++z ) { float zBase = (z - zCubes / 2.0f) * cubeSize * 2; float zf = sin( z * PI / zCubes ); color cubeFill = color( y * colorScale, z * colorScale, x * colorScale, 50 ); pushMatrix(); translate ( sin177 * xBase + sin133 * yBase * zf, sin203 * yBase + cos67 * zBase * xf, cos183 * zBase + cos277 * xBase * yf ); fill ( cubeFill ); box ( cubeSize ); popMatrix (); } } } }