Kinect Laser harpa (6 / 10 steg)
Steg 6: programmering
import SimpleOpenNI.*;
import ddf.minim.*;
import ddf.minim.ugens.*;
SimpleOpenNI kinect;
int closestValue;
int closestX;
int closestY;
Minim minim;
AudioOutput ut;
void setup() {
storlek (640, 480);
Kinect = nya SimpleOpenNI (denna);
kinect.enableDepth();
Minim = nya Minim (denna);
ut = minim.getLineOut();
}
void draw() {
closestValue = 8000;
Kinect.Update();
int [] depthValues = kinect.depthMap();
för (int y = 0; y < 480; y ++) {
för (int x = 0; x < 640; x ++) {
int jag = x + y * 640;
int currentDepthValue = depthValues [i];
om (currentDepthValue > 0 & & currentDepthValue < closestValue) {
closestValue = currentDepthValue;
closestX = x;
closestY = y;
}
}
}
Image(Kinect.depthImage(), 0, 0);
fyllning (255, 0, 0, 155);
rect (20, 0, 40, 480);
fyllning (255, 128, 0, 155);
rect (100, 0, 40, 480);
fyllning (255, 255, 0, 155);
rect (180, 0, 40, 480);
fyllning (0, 255, 0, 155);
rect (260, 0, 40, 480);
fyllning (0, 255, 255, 155);
rect (340, 0, 40, 480);
fyllning (0, 0, 255, 155);
rect (420, 0, 40, 480);
fyllning (128, 0, 255, 155);
rect (500, 0, 40, 480);
fyllning (255, 0, 255, 155);
rect (580, 0, 40, 480);
Fill(155);
ellips (closestX, closestY, 20, 20);
om (closestX < 60 & & closestX > 20) {
out.playNote ("C4");
}
om (closestX < 140 & & closestX > 100) {
out.playNote ("D4");
}
om (closestX < 220 & & closestX > 180) {
out.playNote ("E4");
}
om (closestX < 300 & & closestX > 260) {
out.playNote ("F4");
}
om (closestX < 380 & & closestX > 340) {
out.playNote ("G4");
}
om (closestX < 460 & & closestX > 420) {
out.playNote ("A4");
}
om (closestX < 540 & & closestX > 500) {
out.playNote ("B4");
}
om (closestX < 620 & & closestX > 580) {
out.playNote ("C5");
}
}
void stop() {
Minim.stop();
Super.stop();
}
I detta program, kan du notera och oktav genom att skriva en ny. Till exempel, om du ville höja den senaste noteringen upp en oktav, skulle du ersätta ("C5") med ("C6").