cerberus-kinect
This commit is contained in:
parent
5181c26289
commit
0ab81136c3
|
@ -0,0 +1,68 @@
|
|||
import org.openkinect.processing.*;
|
||||
import processing.sound.*;
|
||||
|
||||
SinOsc sinex;
|
||||
SinOsc siney;
|
||||
SinOsc sinez;
|
||||
float freqx;
|
||||
float freqy;
|
||||
float freqz;
|
||||
float amp = 1;
|
||||
Kinect kinect;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(640,480);
|
||||
kinect = new Kinect(this);
|
||||
kinect.initDepth();
|
||||
kinect.initVideo();
|
||||
kinect.enableIR(false);
|
||||
textSize(32);
|
||||
sinex = new SinOsc(this);
|
||||
siney = new SinOsc(this);
|
||||
sinez = new SinOsc(this);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
int[] depth = kinect.getRawDepth();
|
||||
int step = 1;
|
||||
int point_count = 0;
|
||||
float depth_avg = 0;
|
||||
float x_avg = 0;
|
||||
float y_avg = 0;
|
||||
noStroke();
|
||||
loadPixels();
|
||||
for (int x = 0; x < 640; x+=step)
|
||||
for (int y = 0; y < 480; y+=step)
|
||||
{
|
||||
int c = (depth[x + y * 640] / 4);
|
||||
if (depth[x + y * 640] > 0 && depth[x + y * 640] < 900)
|
||||
{
|
||||
point_count++;
|
||||
depth_avg += depth[x + y * 640];
|
||||
x_avg += x;
|
||||
y_avg += y;
|
||||
}
|
||||
else
|
||||
c = 0;
|
||||
pixels[x + y * 640] = color(c,0,0);
|
||||
}
|
||||
if (point_count > 3000)
|
||||
{
|
||||
depth_avg /= point_count;
|
||||
x_avg /= point_count;
|
||||
y_avg /= point_count;
|
||||
amp = 1;
|
||||
freqx = (1 - (x_avg / 640)) * (62 - 28.5) + 28.5;
|
||||
freqy = (1 - (y_avg / 240)) * (62 - 28.5) + 28.5;
|
||||
freqz = map(constrain(depth_avg / 900, 0, 1), 0, 1, 30, 60);
|
||||
}
|
||||
else
|
||||
amp = 0;
|
||||
sinex.play(freqx, amp, 0, -1);
|
||||
siney.play(freqy, amp, 0, -1);
|
||||
sinez.play(freqz, amp, 0, -1);
|
||||
updatePixels();
|
||||
}
|
Loading…
Reference in New Issue