Paso 6: programación
Import SimpleOpenNI.*;
Import ddf.minim.*;
Import ddf.minim.ugens.*;
SimpleOpenNI kinect;
int closestValue;
int closestX;
int closestY;
Mínima mínima;
AudioOutput
void setup() {}
tamaño (640, 480);
Kinect = new SimpleOpenNI (this);
kinect.enableDepth();
mínima = nuevas mínima (este);
a = minim.getLineOut();
}
void draw() {}
closestValue = 8000;
Kinect.Update();
int [] depthValues = kinect.depthMap();
para (int y = 0 y < 480; y ++) {}
para (int x = 0; x < 640; x ++) {}
int i = x + y * 640;
int currentDepthValue = depthValues [i];
Si (currentDepthValue > 0 & & currentDepthValue < closestValue) {}
closestValue = currentDepthValue;
closestX = x;
closestY = y;
}
}
}
Image(Kinect.depthImage(), 0, 0);
relleno (255, 0, 0, 155);
Rect (20, 0, 40, 480);
relleno (255, 128, 0, 155);
Rect (100, 0, 40, 480);
relleno (255, 255, 0, 155);
Rect (180, 0, 40, 480);
relleno (0, 255, 0, 155);
Rect (260, 0, 40, 480);
relleno (0, 255, 255, 155);
Rect (340, 0, 40, 480);
relleno (0, 0, 255, 155);
Rect (420 0, 40, 480);
relleno (128, 0, 255, 155);
Rect (500, 0, 40, 480);
relleno (255, 0, 255, 155);
Rect (580, 0, 40, 480);
Fill(155);
elipse (closestX, closestY, 20, 20);
Si (closestX < 60 & & closestX > 20) {}
out.playNote ("C4");
}
Si (closestX < 140 & & closestX > 100) {}
out.playNote ("D4");
}
Si (closestX < 220 & & closestX > 180) {}
out.playNote ("E4");
}
Si (closestX < 300 & & closestX > 260) {}
out.playNote ("F4");
}
Si (380 < closestX & & closestX > 340) {}
out.playNote ("G4");
}
Si (460 < closestX & & closestX > 420) {}
out.playNote ("A4");
}
Si (closestX < 540 & & closestX > 500) {}
out.playNote ("B4");
}
Si (closestX < 620 & & closestX > 580) {}
out.playNote ("C5");
}
}
void stop() {}
Minim.STOP();
Super.STOP();
}
En este programa, usted puede elegir la nota y la octava simplemente tecleando una nueva. Por ejemplo, si desea aumentar la última nota a una octava, reemplazar ("C5") con ("C6").