/** * PushPop Cubes * by Ira Greenberg. * * Array of rotating cubes creates * dynamic field patterns. Color * controlled by light sources. Example * of pushMatrix() and popMatrix(). */ import kaleidoscope.*; //import kaleidoscope.WebCamera; import toxi.geom.Vec3D; import toxi.geom.Ray3D; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; import java.awt.AWTException; import java.awt.Point; //WebCamera cam; Camera cam; // Cube class required float ang; int rows = 21; int cols = 21; int cubeCount = rows*cols; int colSpan, rowSpan; float rotspd = 4; Cube[] cubes = new Cube[cubeCount]; float[] angs = new float[cubeCount]; float[] rotvals = new float[cubeCount]; Cube handcube = new Cube( 8, 8, 8, 0, 0, 0 ); void setup(){ size(400, 400, P3D); //cam = new WebCamera( thisr ); cam = new WebCamera( this, "MAYA" ); cam.setPosition( new Vec3D(265.75122, 242.4822, 20.08956 ) ); cam.setTarget( new Vec3D(266.02484, 243.41382, 20.321554 ) ); cam.setRotation( new Vec3D( -68.940315, -4009.706, 0.0 ) ); cam.setMoveSpeed( 0.5f ); cam.setCenterOfRotation( new Vec3D( 200, 200, 0 ) ); //frameRate(30); colSpan = width/(cols-1); rowSpan = height/(rows-1); noStroke(); frameRate( 400 ); // instantiate cubes for (int i = 0; i< cubeCount; i++){ cubes[i] = new Cube(8, 8, 8, 0, 0, 0); /* 3 different rotation options - 1st option: cubes each rotate uniformly - 2nd option: cubes each rotate randomly - 3rd option: cube columns rotate as waves To try the different rotations, leave one of the rotVals[i] lines uncommented below and the other 2 commented out. */ //rotvals[i] = rotspd; //rotvals[i] = random(-rotspd*2, rotspd*2); rotvals[i]=rotspd+=.02; } } void draw(){ //println( "Position: " + cam.Position.x + " : " + cam.Position.y + " : " + cam.Position.z ); //println( "Target: " + cam.Target.x + " : " + cam.Target.y + " : " + cam.Target.z ); //println( "Rotation: " + cam.Rotation.x + " : " + cam.Rotation.y + " : " + cam.Rotation.z ); int cubeCounter = 0; background(30); fill(200); //set up some different colored lights pointLight(51, 102, 255, width/3, height/2, 100); pointLight(200, 40, 60, width/1.5, height/2, -150); //raise overall light in scene ambientLight(170, 170, 100); //translate, rotate and draw cubes for (int i=0; i