diff --git a/Texture/Texture.pde b/Texture/Texture.pde new file mode 100644 index 0000000..8de8b77 --- /dev/null +++ b/Texture/Texture.pde @@ -0,0 +1,188 @@ + +import org.openkinect.freenect.*; +import org.openkinect.processing.*; +import processing.sound.*; + +SoundFile drone1; +SoundFile drone2; +SoundFile drone3; +SoundFile drone4; + +Kinect kinect; + +PImage touchImg; +int tintCount = 0; +int tintDir = 0; + +int minDepth = 795; +int maxDepth = 805; + +float deg; + +boolean ir = false; +boolean colorDepth = true; +boolean mirror = false; +float freqs[] = {0, 0, 0, 0}; + +void setup() { + //size(1024, 768, P3D); + //size(800, 600, P3D); + fullScreen(2); + + touchImg = loadImage("touch.png"); + + kinect = new Kinect(this); + kinect.initDepth(); + kinect.initVideo(); + //kinect.enableIR(ir); + kinect.enableColorDepth(colorDepth); + kinect.enableMirror(mirror); + + deg = kinect.getTilt(); + + drone1 = new SoundFile(this, "drone1.wav"); + drone2 = new SoundFile(this, "drone2.wav"); + drone3 = new SoundFile(this, "drone3.wav"); + drone4 = new SoundFile(this, "drone5.wav"); + + drone1.amp(0.1); + drone2.amp(0.1); + drone3.amp(0.1); + drone4.amp(0.1); + + drone1.loop(); + drone2.loop(); + drone3.loop(); + drone4.loop(); + + colorMode(HSB, 255, 100, 100); + background(255); + noStroke(); + smooth(); + //frameRate(15); +} + + +void draw() { + background(255); + //image(kinect.getVideoImage(), 0, 0); + //image(kinect.getDepthImage(), 640, 0); + + PImage img = kinect.getDepthImage(); + int[] rawDepth = kinect.getRawDepth(); + color c = color(255); + int skip = 10; + int freqsCnt[] = {0, 0, 0, 0}; + + //fill(c, 20); + //rect(0, 0, width, height); + + //image(img, 0, 0); + + for(int x = 0; x < img.width; x += skip){ + for(int y = 0; y < img.height; y += skip){ + int index = x + y * img.width; + float cDepth = 30-map(rawDepth[index], minDepth, maxDepth, 0, 30); + float cColor = map(rawDepth[index], minDepth, maxDepth, 0, 255); + + c = color(cColor, 100, 100); + + if (rawDepth[index] >= minDepth && rawDepth[index] <= maxDepth) { + fill(c, 150); + ellipse(x*1.55, y*1.40, cDepth*2, cDepth*2); + + if(cColor <= 64){ + freqsCnt[0]++; + } + if(cColor > 64 && cColor <= 128){ + freqsCnt[1]++; + } + if(cColor > 128 && cColor <= 196){ + freqsCnt[2]++; + } + if(cColor > 196){ + freqsCnt[3]++; + } + } + } + } + + drone1.amp(map(freqsCnt[0],0,300,0.01,.9)); + drone2.amp(map(freqsCnt[1],0,300,0.01,1)); + drone3.amp(map(freqsCnt[2],0,300,0.01,.6)); + drone4.amp(map(freqsCnt[3],0,300,0.01,.7) ); + + + if(freqsCnt[0] == 0 && freqsCnt[1] == 0 && freqsCnt[2] == 0 && freqsCnt[3] == 0) { + tint(255, tintCount); + image(touchImg, (width/2)-touchImg.width/2, (height/2)-touchImg.height/2); + if(tintDir==0) { + tintCount++; + } else { + tintCount--; + } + if(tintCount >= 255) {tintDir = 1;} + if(tintCount <= 0) {tintDir = 0;} + println(freqsCnt[0] + " - " + freqsCnt[1] + " - " + freqsCnt[2] + " - " + freqsCnt[3] + " - " + tintCount + " - " + tintDir); + } else { + if(tintCount > 0) { + tintCount--; + tint(255, tintCount); + image(touchImg, (width/2)-touchImg.width/2, (height/2)-touchImg.height/2); + } + } + + /* + fill(0); + text("TILT: " + deg, 10, 20); + text("THRESHOLD: [" + minDepth + ", " + maxDepth + "]", 10, 36); + text("FREQS: [" + freqsCnt[0] + ", " + freqsCnt[1] + ", " + freqsCnt[2] + ", " + freqsCnt[3] + "]", 10, 52); + */ + + /* + fill(255); + text( + "Press 'i' to enable/disable between video image and IR image, " + + "Press 'c' to enable/disable between color depth and gray scale depth, " + + "Press 'm' to enable/diable mirror mode, "+ + "UP and DOWN to tilt camera " + + "Framerate: " + int(frameRate), 10, 515); + */ +} + +void keyPressed() { + if (key == 'i') { + ir = !ir; + kinect.enableIR(ir); + } else if (key == 'c') { + colorDepth = !colorDepth; + kinect.enableColorDepth(colorDepth); + } else if(key == 'm'){ + mirror = !mirror; + kinect.enableMirror(mirror); + } else if (key == 'a') { + minDepth = constrain(minDepth+10, 0, maxDepth); + println("minDepth: "+minDepth); + } else if (key == 's') { + minDepth = constrain(minDepth-10, 0, maxDepth); + println("minDepth: "+minDepth); + } else if (key == 'z') { + maxDepth = constrain(maxDepth+10, minDepth, 2047); + println("maxDepth: "+maxDepth); + } else if (key =='x') { + maxDepth = constrain(maxDepth-10, minDepth, 2047); + println("maxDepth: "+maxDepth); + } + + if (key == CODED) { + if (keyCode == UP) { + deg++; + } else if (keyCode == DOWN) { + deg--; + } + } + + deg = constrain(deg, 0, 30); + kinect.setTilt(deg); + +} diff --git a/Texture/data/drone1.wav b/Texture/data/drone1.wav new file mode 100644 index 0000000..347125a Binary files /dev/null and b/Texture/data/drone1.wav differ diff --git a/Texture/data/drone2.wav b/Texture/data/drone2.wav new file mode 100644 index 0000000..924dbec Binary files /dev/null and b/Texture/data/drone2.wav differ diff --git a/Texture/data/drone3.wav b/Texture/data/drone3.wav new file mode 100644 index 0000000..62b9b65 Binary files /dev/null and b/Texture/data/drone3.wav differ diff --git a/Texture/data/drone4.wav b/Texture/data/drone4.wav new file mode 100644 index 0000000..8809644 Binary files /dev/null and b/Texture/data/drone4.wav differ diff --git a/Texture/data/drone5.flac b/Texture/data/drone5.flac new file mode 100644 index 0000000..b8b65ec Binary files /dev/null and b/Texture/data/drone5.flac differ diff --git a/Texture/data/drone5.wav b/Texture/data/drone5.wav new file mode 100644 index 0000000..54dee11 Binary files /dev/null and b/Texture/data/drone5.wav differ diff --git a/Texture/data/drone6.wav b/Texture/data/drone6.wav new file mode 100644 index 0000000..508116c Binary files /dev/null and b/Texture/data/drone6.wav differ diff --git a/Texture/data/touch.png b/Texture/data/touch.png new file mode 100644 index 0000000..dd885ae Binary files /dev/null and b/Texture/data/touch.png differ