// Video Cubes // // Scott "Jerry" Lawrence // 2003-09-11 boolean useVideo = true; // set to true if you have a webcam. boolean backing = true; // set to false to see it break int vw = 80; int vh = 60; // our initialization void setup() { size( 320, 240 ); // screen size if( backing == false ) { noBackground( ); // don't clear the backing store with each frame fill( 0 ); rect( 0, 0, width, height ); } else { background( 0 ); } if( useVideo ) beginVideo( vw, vh, 30 ); // start up video capture noStroke(); } // the main loop... void loop() { if( backing == false ) { // dim out the previous frame noStroke(); fill( 255, 0, 0, 50 ); rect( 0, 0, width, height ); } push(); translate( width/2, height/2 ); scale( width/vh/2 ); rotateY( radians( mouseX * 360/ 256 + 180)); rotateX( radians( -mouseY * 360/ 256 + 180)); boolean mp = mousePressed; for( int y = 0 ; y < vh ; y++ ) { int offset = y*vw; /* if( mp ) beginShape(LINE_STRIP); */ for( int x = 0 ; x < vw ; x++ ) { color ccc; if( useVideo ) ccc = video.pixels[offset]; else ccc = color( x*4 + random( 50 ), y*4 + random( 50 ), abs( x-y)*4 + random( 50 ) ); push(); translate( -vw+x*2, -vh+y*2 ); float bbb = brightness( ccc ); if( mp ) { noStroke(); fill( ccc ); box( bbb/64, bbb/64, bbb/32 ); } else { stroke( ccc ); point( 0, 0, bbb/16); fill( ccc ); /* noStroke(); rect( 0, 0, 3, 3 ); */ } offset++; pop(); } /* if( mp ) endShape(); */ } //imageMode(CENTER_DIAMETER); // pop(); stroke( 0 ); if( keyPressed ) { if( key == 'G' ) screenGrab(); } }