最近JavaScript版のProcessing.jsもjsdo.itで夜な夜ないじってますが、
今回はただのProcessingでLifeCam Cinemaを使ったみた。
import JMyron.*; import ddf.minim.*; Minim minim; AudioInput in; PImage tex; float rotx = PI/4; float roty = PI/4; JMyron m;//a camera object int sz; int nn; int delay=160; void setup() { size(1280, 900, P3D); m = new JMyron();//make a new instance of the object m.start(320,240);//start a capture at 320x240 m.findGlobs(0);//disable the intelligence to speed up frame rate tex = createImage(320,240,RGB); tex.loadPixels(); textureMode(NORMALIZED); fill(255); stroke(color(44,48,32)); minim = new Minim(this); minim.debugOn(); // get a line in from Minim, default bit depth is 16 in = minim.getLineIn(Minim.STEREO, 512); } void draw() { m.update();//update the camera view m.imageCopy(tex.pixels); tex.updatePixels(); background(0); noStroke(); translate(width/2.0, height/2.0, -100); rotx=rotx+in.left.get(0)/40.0; rotateX(rotx); roty=roty+in.left.get(0)/80; rotateY(roty); nn = int(in.left.get(0)*in.left.get(0)*in.left.get(0)*500); sz +=(nn-sz)/delay; scale(250+sz); TexturedCube(tex); } void TexturedCube(PImage tex) { beginShape(QUADS); texture(tex); // Given one texture and six faces, we can easily set up the uv coordinates // such that four of the faces tile "perfectly" along either u or v, but the other // two faces cannot be so aligned. This code tiles "along" u, "around" the X/Z faces // and fudges the Y faces - the Y faces are arbitrarily aligned such that a // rotation along the X axis will put the "top" of either texture at the "top" // of the screen, but is not otherwised aligned with the X/Z faces. (This // just affects what type of symmetry is required if you need seamless // tiling all the way around the cube) // +Z "front" face vertex(-1-in.left.get(0)*2, -1-in.left.get(0)*2, 1, 0, 0); vertex( 1+in.left.get(0)*2, -1-in.left.get(0)*2, 1, 1, 0); vertex( 1+in.left.get(0)*2, 1+in.left.get(0)*2, 1, 1, 1); vertex(-1-in.left.get(0)*2, 1+in.left.get(0)*2, 1, 0, 1); // -Z "back" face vertex( 1+in.left.get(0)*2, -1-in.left.get(0)*2, -1, 0, 0); vertex(-1-in.left.get(0)*2, -1-in.left.get(0)*2, -1, 1, 0); vertex(-1-in.left.get(0)*2, 1+in.left.get(0)*2, -1, 1, 1); vertex( 1+in.left.get(0)*2, 1+in.left.get(0)*2, -1, 0, 1); // +Y "bottom" face vertex(-1-in.left.get(0)*2, 1+in.left.get(0)*2, 1, 0, 0); vertex( 1+in.left.get(0)*2, 1+in.left.get(0)*2, 1, 1, 0); vertex( 1+in.left.get(0)*2, 1+in.left.get(0)*2, -1, 1, 1); vertex(-1-in.left.get(0)*2, 1+in.left.get(0)*2, -1, 0, 1); // -Y "top" face vertex(-1-in.left.get(0)*2, -1-in.left.get(0)*2, -1, 0, 0); vertex( 1+in.left.get(0)*2, -1-in.left.get(0)*2, -1, 1, 0); vertex( 1+in.left.get(0)*2, -1-in.left.get(0)*2, 1, 1, 1); vertex(-1-in.left.get(0)*2, -1-in.left.get(0)*2, 1, 0, 1); // +X "right" face vertex( 1+in.left.get(0)*2, -1-in.left.get(0)*2, 1, 0, 0); vertex( 1+in.left.get(0)*2, -1-in.left.get(0)*2, -1, 1, 0); vertex( 1+in.left.get(0)*2, 1+in.left.get(0)*2, -1, 1, 1); vertex( 1+in.left.get(0)*2, 1+in.left.get(0)*2, 1, 0, 1); // -X "left" face vertex(-1-in.left.get(0)*2, -1-in.left.get(0)*2, -1, 0, 0); vertex(-1-in.left.get(0)*2, -1-in.left.get(0)*2, 1, 1, 0); vertex(-1-in.left.get(0)*2, 1+in.left.get(0)*2, 1, 1, 1); vertex(-1-in.left.get(0)*2, 1+in.left.get(0)*2, -1, 0, 1); endShape(); } void mouseDragged() { float rate = 0.01; rotx += (pmouseY-mouseY) * rate; roty += (mouseX-pmouseX) * rate; }
関連記事