-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconveyor.js
422 lines (304 loc) · 8.97 KB
/
conveyor.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
/*
Cupcake Conveyor
Abby Mueller
CSC1 3725 - Bowdoin
*/
//constants/globals
int SQUARE_DIMENSION = 63;
cupcake[] theCupcakes = new cupcake[8];
Plate[] thePlates = new plates[8];
boolean[] show = new boolean[8];
//keep track of which color icing cupcakes have
boolean[][] cupcake_iced = new boolean[8][5];
//frosting colors: pink, teal, purple, none
color[] frosting_colors = {color(255, 192, 203), color(53, 252, 219), color(159, 53, 252), color(255,255,255)};
int num_colors = 4;
int num_mouse_presses = 0;
int num_frosting_changes = 0;
color frosting_color = frosting_colors[0];
int curr_cupcake = 0;
boolean running = false;
//for the second decoration mode
boolean decoratingMode = false;
boolean frostingMode = false;
boolean sprinklesMode = false;
ArrayList<PVector> listMousePositions = new ArrayList<PVector>();
ArrayList<PVector> sprinklesPos = new ArrayList<PVector>();
void setup() {
size(500, 500, P2D);
frameRate(30);
}
void mousePressed() {
num_mouse_presses += 1;
if (running && !decoratingMode) {
fill(55);
rect(250, 100, 275, 200);
if (mouseX > 250 && mouseX < 275 && mouseY > 100 && mouseY < 150) {
num_frosting_changes += 1;
frosting_color = frosting_colors[num_frosting_changes % num_colors];
}
}
}
void keyPressed() {
if(!decoratingMode){
if (keyCode == '66' || keyCode == 66) {
show[curr_cupcake] = true;
if (curr_cupcake + 1 < 8) {
curr_cupcake += 1;
}
}
if (keyCode == 83) {
noLoop();
setTimeout(loop, 3000);
}
if(keyCode == 88){
decoratingMode = !decoratingMode; //toggle
}
for (int k = 0; k < 8; k++) {
if (keyCode == (49 + k) && show[k] == true) {
cupcake_iced[k] = [true, false, false, false, false];
int bit_set = num_frosting_changes % num_colors;
cupcake_iced[k][bit_set+1] = true;
}
}
} else {
//else if decorating
if(keyCode == 88){
decoratingMode = !decoratingMode; //toggle
}
if(keyCode == 70){ //f = frost
frostingMode = true;
}
if(keyCode == 85){ //u = unfrost
frostingMode = false;
}
//d for sprinkles
if(keyCode == 68){
sprinklesMode = !sprinklesMode;
}
if(sprinklesMode){
if(keyCode == 49){
sprinklesPos.add(new PVector(mouseX, mouseY));
}
}
}
}
//https://bjango.com/articles/processingperfectloops/
float timeLoop(float totalframes, float offset) {
return (frameCount + offset) % totalframes / totalframes;
}
class cupcake {
private float x;
private float y;
private int index;
private PApplet canvas;
private color frostingOnCreation;
cupcake(PApplet canvas, float x, float y, int curr) {
this.canvas = canvas;
this.x = x;
this.y = y;
this.index = curr;
this.frostingOnCreation = color(255, 192, 203);
}
void move() {
//this.canvas.stroke(50,50,50);
noStroke();
float offset = (7.5 * min(index, 7));
//wrapper
fill(204, 204, 255);
quad(timeLoop(60, offset) * width, y, timeLoop(60, offset) * width + 30, y, timeLoop(60, offset) * width + 25, y + 20, timeLoop(60, offset) * width + 5, y + 20);
//cake
fill(237, 209, 149);
ellipse(timeLoop(60, offset) * width + 15, y, 30, 15);
//frosting
if(!cupcake_iced[index][0]){
fill(frostingOnCreation);
ellipse(timeLoop(60, offset) * width + 15, y - 5, 30, 10);
}
if (cupcake_iced[index][0] && cupcake_iced[index][1]) {
fill(frosting_colors[0]);
ellipse(timeLoop(60, offset) * width + 15, y - 5, 30, 10);
}
else if (cupcake_iced[index][0] && cupcake_iced[index][2]) {
fill(frosting_colors[1]);
ellipse(timeLoop(60, offset) * width + 15, y - 5, 30, 10);
}
else if (cupcake_iced[index][0] && cupcake_iced[index][3]) {
fill(frosting_colors[2]);
ellipse(timeLoop(60, offset) * width + 15, y - 5, 30, 10);
}
else if (cupcake_iced[index][0] && cupcake_iced[index][3]) {
fill(frosting_colors[3]);
ellipse(timeLoop(60, offset) * width + 15, y - 5, 30, 10);
//fill(frosting_colors[2]);
}
}
}
class Plate {
private float x;
private float y;
private int index;
private PApplet canvas;
Plate(PApplet canvas, float x, float y, int curr) {
this.canvas = canvas;
// Store x and y.
this.x = x;
this.y = y;
this.index = curr;
}
void drawPlate() {
this.canvas.fill(255, 255, 255);
this.canvas.stroke(211, 211, 211);
this.canvas.ellipse(x, y, 40, 30);
this.canvas.ellipse(x, y, 30, 20);
}
void move() {
offset = (7.5 * min(index, 7));
this.canvas.fill(255, 255, 255);
this.canvas.stroke(211, 211, 211);
this.canvas.ellipse(timeLoop(60, offset) * width + 15, y, 40, 30);
this.canvas.ellipse(timeLoop(60, offset) * width + 15, y, 30, 20);
}
}
class pipingBag {
private float x;
private float y;
private PApplet canvas;
pipingBag(PApplet canvas, float x, float y) {
this.canvas = canvas;
// Store x and y.
this.x = x;
this.y = y;
}
void draw() {
fill(211, 211, 211);
//rect(x, y, x+40, y+5);
//fill(frosting_color[0], frosting_color[1], frosting_color[2]);
fill(frosting_color);
quad(x, y, x + 40, y, x + 35, y + 50, x + 5, y + 50);
fill(100, 100, 100);
triangle(x + 5, y + 50, x + 35, y + 50, x + 20, y + 60);
fill(50, 50, 50);
triangle(x + 15, y + 55, x + 25, y + 55, x + 20, y + 68);
textSize(8);
string s = "frosting";
fill(255, 255, 255);
text(s, x + 5, y + 10);
}
}
class conveyorBelt {
private float x;
private float y;
private PApplet canvas;
conveyorBelt(PApplet canvas, float x, float y) {
this.canvas = canvas;
// Store x and y.
this.x = x;
this.y = y;
this.canvas.fill(211, 211, 211);
this.canvas.stroke(173, 173, 173);
this.canvas.rect(x, y, SQUARE_DIMENSION, SQUARE_DIMENSION);
this.canvas.rect(timeLoop(60, 0) * width, y, SQUARE_DIMENSION, SQUARE_DIMENSION);
this.canvas.rect(timeLoop(60, 7.5) * width, y, SQUARE_DIMENSION, SQUARE_DIMENSION);
this.canvas.rect(timeLoop(60, 15) * width, y, SQUARE_DIMENSION, SQUARE_DIMENSION);
this.canvas.rect(timeLoop(60, 22.5) * width, y, SQUARE_DIMENSION, SQUARE_DIMENSION);
this.canvas.rect(timeLoop(60, 30) * width, y, SQUARE_DIMENSION, SQUARE_DIMENSION);
this.canvas.rect(timeLoop(60, 37.5) * width, y, SQUARE_DIMENSION, SQUARE_DIMENSION);
this.canvas.rect(timeLoop(60, 45) * width, y, SQUARE_DIMENSION, SQUARE_DIMENSION);
this.canvas.rect(timeLoop(60, 52.5) * width, y, SQUARE_DIMENSION, SQUARE_DIMENSION);
}
}
void draw() {
background(255);
if(num_mouse_presses == 0){
textSize(30);
string s = "Welcome to the cupcake factory! You can design cupcakes by following the instructions.";
strng s2 = "There is a twist, though- the cupcakes are coming on a conveyor belt, so you must click deliberately! Click to get started.";
fill(200);
text(s, 50, 50, 450, 200);
text(s2, 50, 250, 450, 200);
}
if (num_mouse_presses >= 1 && !decoratingMode) {
running = true;
background(255);
fill(196, 164, 132);
noStroke();
rect(0, 250, width, 250);
//instructions on top of rect.
//
string i1 = "Key instructions:";
string i2 = "b- bake a new cupcake";
string i3 = "keys 1-8, frost that number cupcake";
string i4 = "click icing bag- toggle icing color";
string i5 = "s- stop belt for 3 seconds so you can screenshot";
string i6 = "x - enter custom decorating mode";
textSize(12);
fill(255);
text(i1, 10, 350);
text(i2, 10, 375);
text(i3, 10, 400);
text(i4, 10, 425);
text(i5, 10, 450);
text(i6, 10, 475);
conveyorBelt cb = new conveyorBelt(this, 0, 250);
//cupcake height is 20 + some for frosting,
//create the cupcakes and plates
for (int i = 0; i < 8; i++) {
theCupcakes[i] = new cupcake(this, 10, 255, i);
thePlates[i] = new Plate(this, 25, 275, i);
}
pipingBag pipe = new pipingBag(this, 250, 100);
pipe.draw();
for (int j = 0; j < 8; j++) {
if (show[j] == true) {
thePlates[j].move();
theCupcakes[j].move();
}
}
}
if(decoratingMode){
background(255);
textSize(12);
fill(0);
string si = "f - to frost";
string sii = "u- to stop frosting";
string siii = "x- go back to conveyor belt mode";
string s4 = "d- enter and exit sprinkles mode!";
string s5 = "while in sprinkles mode, hit 1 to place a sprinkle at your mouse";
text(si, 10, 300);
text(sii, 10, 325);
text(siii, 10, 350);
text(s4, 10, 375);
text(s5, 10, 400);
//big cupcake
//wrapper
//30 -> 200 -> 6.66 scale
fill(204, 204, 255);
quad(50, 100, 250, 100, 216, 100 + 133, 50+33, 100+133);
//cake
fill(237, 209, 149);
ellipse(50 + 15*6.5, 100, 200, 40);
noStroke();
fill(frosting_colors[0]);
if (frostingMode){
ellipse(mouseX, mouseY, 20,20);
//mouse pos = https://discourse.processing.org/t/how-to-save-a-previous-mouse-position/24434/2
if(mouseX != pmouseX){
listMousePositions.add(new PVector(mouseX, mouseY));
}
for(PVector pv : listMousePositions ) {
ellipse(pv.x,pv.y, 20, 20);
}
} else {
for(PVector pv : listMousePositions ) {
ellipse(pv.x,pv.y, 20, 20);
}
for(PVector pv : sprinklesPos ) {
fill(random(0,255), random(0,255), random(0,255));
ellipse(pv.x,pv.y, 5, 5);
fill(frosting_colors[0]);
}
}
//}
}
}