-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
478 lines (421 loc) · 11.6 KB
/
sketch.js
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
var video;
var squarein, squareout;
var img, img1, img2, img3, flashlight, got,book, bgm, b51;
var clickSound = [];
var mouthlight = false;
var sure = false;
var on1 = true;
var on2 = false;
var on3 = false;
var onintro1 = true;
var onintro2 = true;
var scene2 = false;
var button_clicked = false;
var two = false;
var say = false;
var sectwo = false;
var the = false;
var is = false;
var to = false;
var plus = false;
var four = false;
var that = false;
var freedom = false;
var make = false;
var all = false;
var lookfor = false;
var p1=false;
var p2=false;
var p3=false;
var p4=false;
var p5=false;
var p6=false;
var p7=false;
var p8=false;
var p9=false;
var p10=false;
var p11=false;
var vScale = 16;
var slider;
var font,
fontsize = 16;
var input, button;
var counter = 0;
var countup = 0;
var p;
var pages = [];
var pbright;
function preload() {
img1 = loadImage("img/page1.png");
img2 = loadImage("img/page2.png");
img3 = loadImage("img/page3.png");
squarein = loadImage("img/squarein.png")
squareout = loadImage("img/squareout.png")
flashlight = loadImage("img/flashlight.png");
got = loadImage("img/gotit.png");
b51 = loadImage("img/b51.png");
font = loadFont("ffffont/Courier-Prime-4.ttf");
bgm = loadSound("sound/msc.mp3");
for (var i = 0; i < 14; i++) {
clickSound[i] = loadSound("sound/m" + i + ".mp3");
}
}
function setup() {
//createCanvas(1024, 768);
createCanvas(windowWidth, windowHeight);
// if you work on Hi-density display you need to add the following line
pixelDensity(1);
frameRate(30);
video = createCapture(VIDEO);
video.size(width / vScale, height / vScale);
video.hide();
// input = createInput();
//input.hide();
// button = createButton('send');
// button.position(input.x + input.width, height - 75);
// button.mouseClicked(replace);
img1.loadPixels();
img2.loadPixels();
img3.loadPixels();
slider = createSlider(0, 255, 8);
textFont(font);
textSize(fontsize);
textAlign(LEFT, CENTER)
pages = [img1, img2, img3];
img = pages[0];
bgm.loop();
//bgm.playMode('restart');
}
function draw() {
background(0);
// intro();
// if (scene2 == true && on1 == false) {
// // image(b51, 0, 0, width, height);
// // image(bgd, 600, 100, bgd.width / 5, bgd.height / 5);
// // image(tube, 30, 250, 680, 680);
// // image(pipe, 0, 250, 700, 700);
// boothscene();
// } else if (lookfor == true) {
if (all == false) {
if (mouthlight == true) {
backuplight();
} else {
inspect();
}
} else {
message();
}
//}
}
function mousePressed() {
//detect if go with flashlight or cameralight
if (mouseX > (width - 100) && mouseY < 90) {
mouthlight = !mouthlight;
soundEffect();
} else if (scene2 == true && mouseX > 750 && mouseX < 810 && mouseY > height - 150 && mouseY < height - 130) {
button_clicked = true;
soundEffect();
} else if (mouseX > width - 100 && mouseX < width - 50 && mouseY > 335 && mouseY < 375) {
img = pages[0];
on1 = true;
on2 = false;
on3 = false;
soundEffect();
} else if (mouseX > width - 100 && mouseX < width - 50 && mouseY > 385 && mouseY < 425) {
img = pages[1];
on1 = false;
on2 = true;
on3 = false;
soundEffect();
} else if (mouseX > width - 100 && mouseX < width - 50 && mouseY > 435 && mouseY < 475) {
img = pages[2];
on1 = false;
on2 = false;
on3 = true;
soundEffect();
} else if (p1==false&&on1 == true && mouseX > 660 && mouseX < 780 && mouseY > 60 && mouseY < 120) {
two = true;
soundEffect();
} else if (p2==false&&on1 == true && mouseX > 1100 && mouseX < 1200 && mouseY > 160 && mouseY < 215) {
say = true;
soundEffect();
} else if (p3==false&&on1 == true && mouseX > 340 && mouseX < 390 && mouseY > 410 && mouseY < 570) {
sectwo = true;
soundEffect();
} else if (p4==false&&on1 == true && mouseX > 810 && mouseX < 890 && mouseY > 710 && mouseY < 760) {
the = true;
soundEffect();
} else if (p5==false&&on2 == true && mouseX > 890 && mouseX < 950 && mouseY > 140 && mouseY < 200) {
is = true;
soundEffect();
} else if (p6==false&&on2 == true && mouseX > 1070 && mouseX < 1130 && mouseY > 290 && mouseY < 345) {
to = true;
soundEffect();
} else if (p7==false&&on2 == true && mouseX > 360 && mouseX < 410 && mouseY > 640 && mouseY < 700) {
plus = true;
soundEffect();
} else if (p8==false&&on3 == true && mouseX > 340 && mouseX < 410 && mouseY > 5 && mouseY < 60) {
four = true;
soundEffect();
} else if (p9==false&&on3 == true && mouseX > 430 && mouseX < 530 && mouseY > 400 && mouseY < 460) {
that = true;
soundEffect();
} else if (p10==false&&on3 == true && mouseX > 620 && mouseX < 815 && mouseY > 800 && mouseY < 860) {
freedom = true;
soundEffect();
} else if (p11==false&&on3 == true && mouseX > 340 && mouseX < 410 && mouseY > 860 && mouseY < 920) {
make = true;
soundEffect();
} else if (onintro1 == true && onintro2 == true && mouseX > 20 && mouseX < 70 && mouseY > 200 && mouseY < 225) {
sure = true;
onintro1 = false;
soundEffect();
} else if (onintro1 == false && onintro2 == true && mouseX > 0 && mouseX < (width - 100) && mouseY > 200 && mouseY < height) {
onintro2 = false;
scene2 = true;
soundEffect();
} else if (onintro1 == false && onintro2 == true && mouseX > (width - 90) && mouseX < (width - 30) && mouseY > 95 && mouseY < 150) {
lookfor = true;
onintro2 = false;
on1 = true;
soundEffect();
} else if (scene2 == true && on1 == false && mouseX > (width - 90) && mouseX < (width - 30) && mouseY > 95 && mouseY < 150) {
lookfor = true;
onintro2 = false;
on1 = true;
scene2 = false;
input.hide();
soundEffect();
}
}
function soundEffect() {
var r = int(random(14));
clickSound[r].play();
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function inspect() {
frameRate(15);
background(0);
video.loadPixels();
loadPixels();
var centerX, centerY;
for (var y = 0; y < video.height; y++) {
for (var x = 0; x < video.width; x++) {
var indexLoc = (x + (y * video.width)) * 4;
var r = video.pixels[indexLoc + 0]; // r value from the video
var g = video.pixels[indexLoc + 1]; // g value from the video
var b = video.pixels[indexLoc + 2]; // b value from the video
pbright = (r + b + g) / 3;
if (pbright > 253) {
centerX = (video.width - x + 1) * vScale;
break;
}
}
if (pbright > 253) {
centerY = y * vScale;
// fill(255);
// ellipse(centerX, centerY,30,30);
// img1.loadPixels();
for (var i = 0; i < img.width; i++) {
for (var j = 0; j < img.height; j++) {
//var pixloc = (y*img.width + x)*4;
var maxdist = 100;
var d = dist(i, j, centerX, centerY);
var loc = (i + j * img.width) * 4;
var light = img.pixels[loc];
var adjustbrightness = 255 * (maxdist - d) / maxdist;
light += adjustbrightness;
light = constrain(light, 0, 255);
var pixloc = (i + j * width) * 4;
pixels[pixloc + 0] = light;
pixels[pixloc + 1] = light;
pixels[pixloc + 2] = light;
pixels[pixloc + 3] = 255; // alpha value
}
}
break;
}
}
updatePixels();
getOne();
navigation();
getAll();
}
function backuplight() {
background(0);
for (var x = 0; x < img.width; x++) {
for (var y = 0; y < img.height; y++) {
// Calculate the 1D location from a 2D grid
var loc = (x + y * img.width) * 4;
// Get the R,G,B values from image
var r, g, b;
r = img.pixels[loc];
// Calculate an amount to change brightness based on proximity to the mouse
var maxdist = 80;
var d = dist(x, y, mouseX, mouseY);
var adjustbrightness = 255 * (maxdist - d) / maxdist;
r += adjustbrightness;
// Constrain RGB to make sure they are within 0-255 color range
r = constrain(r, 0, 255);
// Make a new color and set pixel in the window
//color c = color(r, g, b);
var pixloc = (y * width + x) * 4;
pixels[pixloc] = r;
pixels[pixloc + 1] = r;
pixels[pixloc + 2] = r;
pixels[pixloc + 3] = 255;
}
}
updatePixels();
getOne();
navigation();
getAll();
}
function navigation() {
if (on1 == true) {
image(squarein, width - 90, 340, 30, 30);
image(squareout, width - 90, 390, 30, 30);
image(squareout, width - 90, 440, 30, 30);
image(flashlight, width - 100, 20, 70, 70);
}
if (on2 == true) {
image(squareout, width - 90, 340, 30, 30);
image(squarein, width - 90, 390, 30, 30);
image(squareout, width - 90, 440, 30, 30);
image(flashlight, width - 100, 20, 70, 70);
}
if (on3 == true) {
image(squareout, width - 90, 340, 30, 30);
image(squareout, width - 90, 390, 30, 30);
image(squarein, width - 90, 440, 30, 30);
image(flashlight, width - 100, 20, 70, 70);
}
if (onintro1 == false && onintro2 == true) {
image(book, width - 90, 100, 45, 45);
}
if (scene2 == true && on1 == false) {
image(book, width - 90, 100, 45, 45);
}
}
function getAll() {
if (countup == 11) {
all = true;
}
// if (two == true && say == true && sectwo == true && the == true && is == true &&
// to == true && plus == true && four == true && that == true &&
// freedom == true && make == true) {
// all = true;
// }
}
function getOne() {
if (two == true && on1 == true) {
p1=true;
countup = countup+1;
two = false;
}
else if (say == true && on1 == true) {
p2=true;
countup = countup+1;
say = false;
}
else if (sectwo == true && on1 == true) {
p3=true;
countup = countup+1;
sectwo = false;
}
else if (the == true && on1 == true) {
p4=true;
countup = countup+1;
the = false;
}
else if (is == true && on2 == true) {
p5=true;
countup = countup+1;
is = false;
}
else if (to == true && on2 == true) {
p6=true;
countup = countup+1;
to = false;
}
else if (plus == true && on2 == true) {
p7=true;
countup = countup+1;
plus = false;
}
else if (four == true && on3 == true) {
p8=true;
countup = countup+1;
four = false;
}
else if (that == true && on3 == true) {
p9=true;
countup = countup+1;
that = false;
}
else if (freedom == true && on3 == true) {
p10=true;
countup = countup+1;
freedom = false;
}
else if (make == true && on3 == true) {
p11=true;
countup = countup+1;
make = false;
}
if (p1 == true&& on1 == true){
image(got, 660, 60, 50, 50);
}
if (p2 == true&& on1 == true){
image(got, 1100, 160, 50, 50);
}
if (p3 == true&& on1 == true){
image(got, 330, 450, 50, 50);
}
if (p4 == true&& on1 == true){
image(got, 810, 710, 50, 50);
}
if (p5 == true&& on2 == true){
image(got, 890, 140, 50, 50);
}
if (p6 == true&& on2 == true){
image(got, 1070, 290, 50, 50);
}
if (p7 == true&& on2 == true){
image(got, 360, 640, 50, 50);
}
if (p8 == true&& on3 == true){
image(got, 340, 5, 50, 50);
}
if (p9 == true&& on3 == true){
image(got, 430, 405, 50, 50);
}
if (p10 == true&& on3 == true){
image(got, 620, 800, 50, 50);
}
if (p11 == true&& on3 == true){
image(got, 340, 860, 50, 50);
}
fill(255);
textSize(16);
textStyle(BOLD);
text(countup + "/11", 30, 30);
}
function message() {
fill(0);
var offset3 = random(9);
var i = width / 2 - 300;
var j = height / 2 - 200;
shake = false;
fill(255);
textSize(16);
textStyle(BOLD);
text("Freedom is the freedom to say that 2 + 2 = 4", i + offset3, j + offset3);
text("SENDING...", i + 80, j + 60);
for (var k = 0; k < 100; k += 1) {
var p = k + "%";
text(p, i + 180, j + 60);
}
}