This repository has been archived by the owner on Dec 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProjection_Mapping.pde
171 lines (147 loc) · 4.65 KB
/
Projection_Mapping.pde
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import org.openkinect.freenect.*;
import org.openkinect.processing.*;
// The kinect stuff is happening in another class
Track track;
Kinect kinect;
//Counter for the number of times a red square is found
int counter = 0;
// Tilt of Kinect, which is controlled by keypress ^v
float tilt;
PImage img;
PImage eye;
PImage portrait;
// PNG Sequence arrays which will hold the images for animation
PImage[] evil = new PImage[38];
PImage[] blackEye = new PImage[58];
PImage[] slide = new PImage[85];
// These variables determine whether the animations will run, which one and make sure
// They start from frame 0.
int count = 0;
boolean timer = false;
int ranHit;
int currentFrame = 0;
void setup() {
//Development Size - size(1400, 1500);
size(733, 1000);
kinect = new Kinect(this);
track = new Track();
tilt = kinect.getTilt();
// Images being declared for later use within the sketch
eye = loadImage("eye.png");
portrait = loadImage("portrait.png");
// Series of For statements which declare run through and create the name of the
// Images that will be then stored into the appropriate array
for (int i = 0; i<=37; i++) {
String name = "Flash_" + nf(i, 3)+".png";
evil[i] = loadImage(name);
}
for (int i = 0; i<=57; i++) {
String name = "BlackEyes_" + nf(i, 3)+".png";
blackEye[i] = loadImage(name);
}
for (int i = 0; i<=84; i++) {
String name = "Slide_" + nf(i, 3)+".png";
slide[i] = loadImage(name);
}
}
void draw() {
// Count adds every frame, to act as a timer for when the animations may run
count++;
background(185, 150, 143);
// Run the tracking analysis
track.track();
// Show the image
track.display();
//Raw image location
PVector v1 = track.getPos();
// Po is the left eye, Pe is the right eye, Pa is the eye's Y position
float po = map(v1.x, 0, width, 330, 375);
float pe = map(v1.x, 0, width, 420, 465);
float pa = map(v1.y, 0, height, 225, 250);
noStroke();
image(eye, po, pa, 20, 20);
image(eye, pe, pa+5, 20, 20);
image(portrait, 0, 0);
// Resetting Counter to 0 every frame so number of pixels which are red aren't added
counter=0;
// Runs through the pixel array of the Kinect's DepthMap looking for red pixels
// When there is a red pixel, the counter is increased by 1
for (int i = 0; i<track.display.pixels.length; i++) {
if (track.display.pixels[i] == color(208, 80, 74)) {
counter++;
} else {
}
}
// Count timer being checked. If it hits 2000 (2000/50frames = 40 Seconds)
// Then boolean is equal to true and the RanHit generates either 0, 1, 2
if (count==500) {
timer = true;
ranHit = int(random(3));
}
// If statement checking for both timer to be true and the DepthMap counter to equal
// 30000 red pixels. Once that is then animation will initiate
if (timer ==true && counter>=30000) {
int offset = 0;
// Runs "Evil" animation
if (ranHit == 0) {
currentFrame = (currentFrame+1) % 38;
for (int i = 0; i<=38; i++) {
image(evil[(currentFrame+offset) % evil.length], 0, 0);
// If the frame of the Evil animation is equal to 37, the end, then it will
// Reset count timer to 0, timer to false and currentFrame to 0 so next
// Animation will start at the 0 frame
if ((currentFrame+offset) % evil.length == 37) {
count=0;
timer = false;
currentFrame = 0;
}
}
}
// Runs "Black Eye" animation
if (ranHit == 1) {
currentFrame = (currentFrame+1) % 58;
for (int i = 0; i<=58; i++) {
image(blackEye[(currentFrame+offset) % blackEye.length], 0, 0);
if ((currentFrame+offset) % blackEye.length == 57) {
count=0;
timer = false;
currentFrame = 0;
}
}
}
// Runs the "Slide" animation
if (ranHit == 2 ) {
currentFrame = (currentFrame+1) % 85;
for (int i = 0; i<=149; i++) {
image(slide[(currentFrame+offset) % slide.length], 0, 0);
println((currentFrame+offset) % slide.length);
if ((currentFrame+offset) % slide.length == 84) {
count=0;
timer = false;
currentFrame = 0;
}
}
}
}
}
void keyPressed() {
//Set tilt of Kinect Camera using the Up and Down Arrow Keys
int tr = track.getThreshold();
if (key == CODED) {
if (keyCode == UP) {
tilt++;
} else if (keyCode == DOWN) {
tilt--;
} else if (keyCode == RIGHT) {
//Adds 10 to threshold
tr+=10;
track.setThreshold(tr);
} else if (keyCode == LEFT) {
//Removes 10 to threshold
tr-=10;
track.setThreshold(tr);
}
tilt = constrain(tilt, 0, 30);
kinect.setTilt(tilt);
}
}