-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
100 lines (78 loc) · 1.77 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
let model_0, model_1, model_2;
let rot = 0;
let video;
let c;
let myColor = "green";
function preload() {
model_0 = loadModel('Thinker.obj');
model_1 = loadModel('unicorn.obj');
model_2 = loadModel('tesla.obj');
}
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
video = createCapture(VIDEO);
//video.loadPixels();
}
function draw() {
lights();
background(0);
rectMode(CENTER);
rect(0, 0, 40, 40);
stroke(255);
line(0, 0, -1 * width / 2, -1 * width / 2);
line(0, 0, -1 * width / 2, 1 * width / 2);
line(0, 0, 1 * width / 2, -1 * width / 2);
line(0, 0, 1 * width / 2, 1 * width / 2);
noStroke();
//c = video.get(video.width / 2, video.height / 2);
if (c[0] > c[1] && c[0] > c[2]) {
myColor = "red"
} else if (c[1] > c[0] && c[1] > c[2]) {
myColor = "green"
} else if (c[2] > c[1] && c[2] > c[0]) {
myColor = "blue"
}
//print(myColor);
switch (myColor) {
case "red":
print("red");
//fill(255, 0, 0);
for (let i = 0; i < 4; i++) {
push();
rotateZ(HALF_PI * i);
translate(0, width/7, 0);
rotateY(rot);
scale(1.5);
model(model_0)
pop();
}
break;
case "green":
print("green");
//fill(0, 255, 0);
for (let i = 0; i < 4; i++) {
push();
rotateZ(HALF_PI * i);
translate(0, width/7, 0);
rotateY(rot);
scale(1);
model(model_1)
pop();
}
break;
case "blue":
print("blue");
//fill(0, 0, 255);
for (let i = 0; i < 4; i++) {
push();
rotateZ(HALF_PI * i);
translate(0, width/7, 0);
rotateY(rot);
scale(1);
model(model_2)
pop();
}
break;
}
rot += 0.01;
}