Can

28 Jan 2013

I made this on my desktop mac mini, it doesn’t have a camera, so I used Kinect instead. The idea is the same. You can adjust the tilt using the arrow keys, and the threshold using “a” , “s” , “z” and “x” keys.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//TEXT RAIN KINECT//
//IACD ASSIGNMENT//
//CAN (JOHN) OZBAY//
//2013//
 
import org.openkinect.*;
import org.openkinect.processing.*;
 
Kinect kinect; //kinect settings
int kWidth = 640;
int kHeight = 480;
int kAngle = 0;
 
PImage depthImg; //depth settings
int minDepth = 60;
int maxDepth = 660;
 
String alphabet = "abcdefghijklmnopqrstuvqxyz";
String [] letters = new String [100];
float [] x = new float [100];
float [] y = new float [100];
boolean [] falling = new boolean[100];
int savedTime; //when the function was last called
int interval = 300; //how often we want to call the function(milis)
int bThreshold = 70;
 
void setup () {
smooth();
noStroke();
size(640, 480);
fill(0);
savedTime = millis();
 
size(kWidth, kHeight);
kinect = new Kinect(this);
kinect.start();
kinect.enableDepth(true);
kinect.tilt(kAngle);
depthImg = new PImage(kWidth, kHeight);
}
 
void draw () {
//depth threshold
int[] rawDepth = kinect.getRawDepth();
for (int i=0; i < kWidth*kHeight; i++) {
if (rawDepth[i] >= minDepth && rawDepth[i] <= maxDepth) { 
depthImg.pixels[i] = 0xFFFFFFFF;
} 
else { 
depthImg.pixels[i] = 0;
}
}
// draw threshold image
depthImg.updatePixels();
image(depthImg, 0, 0);
stroke(255,0,0);
line(10,434,160,434);
fill(255, 0, 0);
text("Tilt: " + kAngle, 10, 450);
text("Depth Thresh: [" + minDepth + ", " + maxDepth + "]", 10, 466);
for (int i=0; i savedTime+interval) { 
makeLetter(); 
savedTime = millis();
}
}
 
//name speaks for itself
void moveLetter (int tempI) {
y[tempI]++;
if (y[tempI] > height) { 
falling[tempI] = false;
}
}
//self explanatory 
void drawLetter (String tempS, float tempX, float tempY, int tempI) {
fill(0,200,255); 
text(tempS, tempX, tempY);
}
 
//Making of "The Letter"
void makeLetter () {
boolean madeLetter = false;
int randomNumber = int(random(alphabet.length()));
String tempChar = alphabet.substring(randomNumber, randomNumber+1);
for (int i=0; i 0 && loc <pixels.length) {
//get its brightness
float b = brightness(pixels[loc]);
if (b > bThreshold) {
isPixelDark = true;
}
}
return isPixelDark;
}
 
void keyPressed() {
if (key == CODED) {
//UP & DOWN ARROW KEYS, FOR KINECT TILT
if (keyCode == UP) {
kAngle++;
} 
else if (keyCode == DOWN) {
kAngle--;
}
kAngle = constrain(kAngle, 0, 30);
kinect.tilt(kAngle);
}
 
//A, S, Z, X - SET min Depth and max Depth
else if (key == 'a') {
minDepth = constrain(minDepth+20, 0, maxDepth);
} 
else if (key == 's') {
minDepth = constrain(minDepth-20, 0, maxDepth);
}
 
else if (key == 'z') {
maxDepth = constrain(maxDepth+20, minDepth, 2047);
} 
else if (key =='x') {
maxDepth = constrain(maxDepth-20, minDepth, 2047);
}
}
 
//don't forget to stop
void stop() {
kinect.quit();
super.stop();
}