boolean newFrame = false; int xm = 176; int ym = 144; int zm = 50; boolean col = true; int con = 3; BImage swap; BImage a; void setup() { size (800,600); /* try{ quicktime.QTSession.open(); quicktime.std.sg.SequenceGrabber sg = new quicktime.std.sg.SequenceGrabber(); quicktime.std.sg.SGVideoChannel sc = new quicktime.std.sg.SGVideoChannel(sg); quicktime.std.sg.VideoDigitizer vd = sc.getDigitizerComponent(); println( "dv.getNumberOfInputs :" ); println( vd.getNumberOfInputs() ); println(); vd.setInput(2); } catch (Exception e) { e.printStackTrace(); } */ beginVideo(xm, ym, 12); //a = loadImage("c.gif"); //swap = a; } void videoEvent() { newFrame = true; } void loop() { if(newFrame) { newFrame = false; swap = video; } background(255); push(); translate(width/2,height/2,300); rotateY((TWO_PI/width)*mouseX); rotateX((TWO_PI/width)*mouseY); //rotateX(PI); drawCube(); cubeBrown(); pop(); } void mousePressed(){ col = !col; } void keyPressed(){ con = (con+1)%5; } void cubeBrown(){ strokeWeight(1); stroke(15,15,15,100); line(-(xm/2),-(ym/2),-(zm/2),(xm/2),-(ym/2),-(zm/2)); line(-(xm/2),-(ym/2),-(zm/2),-(xm/2),(ym/2),-(zm/2)); line(-(xm/2),-(ym/2),-(zm/2),-(xm/2),-(ym/2),(zm/2)); line((xm/2),-(ym/2),-(zm/2),(xm/2),(ym/2),-(zm/2)); line((xm/2),-(ym/2),-(zm/2),(xm/2),-(ym/2),(zm/2)); line(-(xm/2),(ym/2),-(zm/2),(xm/2),(ym/2),-(zm/2)); line(-(xm/2),-(ym/2),(zm/2),(xm/2),-(ym/2),(zm/2)); line(-(xm/2),-(ym/2),(zm/2),-(xm/2),(ym/2),(zm/2)); line(-(xm/2),(ym/2),(zm/2),(xm/2),(ym/2),(zm/2)); line(-(xm/2),(ym/2),(zm/2),-(xm/2),(ym/2),-(zm/2)); line((xm/2),(ym/2),(zm/2),(xm/2),(ym/2),-(zm/2)); line((xm/2),(ym/2),(zm/2),(xm/2),-(ym/2),(zm/2)); } void drawCube(){ for (int ix = 1; ix < xm-1; ix++){ for (int iy = 1; iy < ym-1; iy++){ float zee = zm; int c1 = int((zee/255.0)*grey(swap.pixels[ix + iy*xm])); int c2 = int((zee/255.0)*grey(swap.pixels[ix + 1 + iy*xm])); int c3 = int((zee/255.0)*grey(swap.pixels[ix + (iy + 1)*xm])); int c4 = int((zee/255.0)*grey(swap.pixels[ix + 1 + (iy + 1)*xm])); if (col){ stroke(swap.pixels[ix + iy*xm]); }else{ stroke(grey(swap.pixels[ix + iy*xm])); } switch(con){ case 0: strokeWeight(3); point(ix-(xm/2),iy-(ym/2),c1-(zm/2));break; case 1: line(ix-(xm/2),iy-(ym/2),c1-(zm/2), ix-(xm/2)+1,iy-(ym/2),c2-(zm/2)); break; case 2: line(ix-(xm/2),iy-(ym/2),c1-(zm/2), ix-(xm/2)+1,iy-(ym/2),c2-(zm/2)); line(ix-(xm/2),iy-(ym/2),c1-(zm/2), ix-(xm/2),iy-(ym/2)+1,c3-(zm/2));break; case 3: noStroke(); if (col){ fill(swap.pixels[ix + iy*xm]); }else{ fill(grey(swap.pixels[ix + iy*xm])); } beginShape(QUADS); vertex(ix-(xm/2),iy-(ym/2),c1-(zm/2)); vertex((ix+1)-(xm/2),iy-(ym/2),c2-(zm/2)); vertex((ix+1)-(xm/2),(iy+1)-(ym/2),c4-(zm/2)); vertex(ix-(xm/2),(iy+1)-(ym/2),c3-(zm/2)); endShape();break; } } } if (con==4){ noStroke(); fill(255); beginShape(QUADS); texture(swap); vertex(-(xm/2),-(ym/2),0, 0,0); vertex((xm/2),-(ym/2),0, 176,0); vertex((xm/2),(ym/2),0, 176,144); vertex(-(xm/2),(ym/2),0, 0,144); endShape(); } } float grey(color p){ float r = red(p); float g = green(p); float b = blue(p); return (r+g+b)/3; }