From 0ab81136c3f2e9b6d9bf52276d0b8f5b76381ac2 Mon Sep 17 00:00:00 2001 From: gbrochar Date: Sun, 3 Jan 2021 12:41:06 +0100 Subject: [PATCH] cerberus-kinect --- cerberus_kinect/cerberus_kinect.pde | 68 +++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 cerberus_kinect/cerberus_kinect.pde diff --git a/cerberus_kinect/cerberus_kinect.pde b/cerberus_kinect/cerberus_kinect.pde new file mode 100755 index 0000000..fbd3bb1 --- /dev/null +++ b/cerberus_kinect/cerberus_kinect.pde @@ -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(); +}