Final processing code 2

From DigitalCraft_Wiki
Jump to navigation Jump to search

PGraphics canvas; SyphonServer server;

import SimpleOpenNI.*; import java.awt.Color; import java.util.Iterator; import processing.video.*;

SingleUserKinect kinect; Movie movie2, movie3 ; PVector userPosRealWorld = new PVector(); // 3d user position float comZ; // Center of Mass X int teSpelenFilmpje; boolean USE_KINECT = true;


void setup() {

 // size of the window
 //size(400,400);// use size "(displayWidth, displayHeight)" for fullscreen  
 size(displayWidth, displayHeight, P3D);
 canvas = createGraphics(displayWidth, displayHeight, P3D);

server = new SyphonServer(this, "Processing Syphon"); }

 movie3 = new Movie(this, "Sequence 03.mp4");
 movie3.loop();
 movie2 = new Movie(this, "Sequence 02.mp4");
 movie2.loop();


 // user SingleUserKinect for tracking.
 if (USE_KINECT) {
   kinect = new SingleUserKinect(this);
 }

}

// draw is repeatedly executed, as fast as possible, or according to frameRate setting void draw() {

 background(0); // draw a black background
 
 canvas.beginDraw();
 canvas.background(mouseY);
 canvas.stroke(mouseX);
 canvas.line(50, 50, mouseX, MouseY);
 canvas(endDraw();
 image(canvas, 0, 0);
 
 server.sendImage(canvas);

}


 if (USE_KINECT) {
   kinect.update();
 }
 if (USE_KINECT) {  
   if (kinect.trackedUserId != 0) { 
     kinect.getCoM(userPosRealWorld);    
     comZ = userPosRealWorld.z;
   }
   if (kinect.trackedUserId == 0) { 
     comZ = -1;
   }
 }
/*
 if (comZ>3500) { 
   teSpelenFilmpje = 3;
   
    }
 else if (comZ>0) { 
   teSpelenFilmpje = 2;
 } else teSpelenFilmpje=3; //niemand in beeld
 */
 
 float fadewaarde = map(comZ,2000,2500,0,255);
 if(comZ<2000) fadewaarde =0;
 if(comZ>2500) fadewaarde =255;
 

tint(255, 255-fadewaarde);

image(movie3, 0, 0, width, height);

tint(255, fadewaarde);

image(movie2, 0, 0, width, height);

// textSize(32); // text(comZ, 10, 100); // text(teSpelenFilmpje, 10, 300); }


void movieEvent(Movie m) {

 m.read();

}

// ----------------------------------------------------------------- // SimpleOpenNI user events // ----------------------------------------------------------------- // onNewUser is triggered when the kinect registers a new user void onNewUser(SimpleOpenNI curContext, int userId) {

 // let our SingleUserKinect Class take care of this
 kinect.registerNewUser(curContext, userId);

}

// onLostUser is triggered when the kinect deregisters a user void onLostUser(SimpleOpenNI curContext, int userId) {

 // let our SingleUserKinect Class take care of this
 kinect.deRegisterUser(curContext, userId);

}