@@ -54,16 +54,22 @@ int xdirection = 1;
54
54
int ydirection = 1 ;
55
55
56
56
// variables for pizzaCat animation
57
- float pizza_speed = 20 ;
58
- float cat_speed = 30 ;
57
+ int pizzaCount = 32 ;
58
+ int catCount = 32 ;
59
+ int emojiCount = 32 ;
59
60
60
- float pizza_pos, cat_pos;
61
+ PImage [] cats = new PImage [catCount];
62
+ PImage [] pizzas = new PImage [pizzaCount];
61
63
62
- int img_w = 10 ;
64
+ float [] moveX = new float [emojiCount];
65
+ float [] moveY = new float [emojiCount];
63
66
64
- int pizza_dir = 1 ;
65
- int cat_dir = 1 ;
66
- int num_cats;
67
+ float last_speed;
68
+
69
+ float [] x_dir = new float [emojiCount];
70
+ float [] y_dir = new float [emojiCount];
71
+ float [] x_speeds = new float [emojiCount];
72
+ float [] y_speeds = new float [emojiCount];
67
73
68
74
// variables for dancingTriangles animation
69
75
int x1;
@@ -98,6 +104,23 @@ void setup()
98
104
cat_img = loadImage (" cat.png" );
99
105
pizza_img = loadImage (" pizza.png" );
100
106
107
+ // adding pizza and cat emojis to their arrays
108
+ for (int slice = 0 ; slice < 15 ; slice ++ ) {
109
+ pizzas[slice] = pizza_img;
110
+ }
111
+ for (int claw = 16 ; claw< catCount; claw++ ) {
112
+ cats[claw] = cat_img;
113
+ }
114
+ // creating arrays of coordinates and speed for pizzaCat
115
+ for (int z = 0 ; z < emojiCount; z ++ ) {
116
+ x_dir[z] = random (width );
117
+ y_dir[z] = random (height );
118
+ x_speeds[z] = random (5 , 20 );
119
+ y_speeds[z] = random (5 , 20 );
120
+ moveX[z] = x_speeds[z];
121
+ moveY[z] = y_speeds[z];
122
+ }
123
+
101
124
// connecting to socket to communicate with Blinka script
102
125
myClient = new Client (this , " 127.0.0.1" , 12345 );
103
126
@@ -116,27 +139,31 @@ void draw()
116
139
// the encoder pos is stored in index
117
140
String [] q = splitTokens (inString);
118
141
index = int (q[1 ]);
142
+ println (index);
119
143
}
120
144
// if the string begins with 'red'
121
145
// aka is from the red neoslider
122
146
if (inString. startsWith(" red" )) {
123
147
// the red value is stored in red
124
148
String [] r = splitTokens (inString);
125
149
red = int (r[1 ]);
150
+ println (red);
126
151
}
127
152
// if the string begins with 'green'
128
153
// aka is from the green neoslider
129
154
if (inString. startsWith(" green" )) {
130
155
// the green value is stored in green
131
156
String [] g = splitTokens (inString);
132
157
green = int (g[1 ]);
158
+ println (green);
133
159
}
134
160
// if the string begins with 'blue'
135
161
// aka is from the blue neoslider
136
162
if (inString. startsWith(" blue" )) {
137
163
// the blue value is stored in blue
138
164
String [] b = splitTokens (inString);
139
165
blue = int (b[1 ]);
166
+ println (blue);
140
167
}
141
168
// if the string begins with flight
142
169
// aka is from the VL53L4CD
@@ -147,7 +174,7 @@ void draw()
147
174
}
148
175
}
149
176
// the encoder's position corresponds with which animation plays
150
- if (index == 0 ) {
177
+ if (index == 3 ) {
151
178
circles();
152
179
}
153
180
@@ -157,7 +184,7 @@ void draw()
157
184
if (index == 2 ) {
158
185
dancingTriangles();
159
186
}
160
- if (index == 3 ) {
187
+ if (index == 0 ) {
161
188
pizzaCat();
162
189
}
163
190
}
@@ -208,30 +235,78 @@ void cube() {
208
235
}
209
236
210
237
// the Pizza Cat animation
211
- // pizza and cat face emojis go back and forth across the screen
238
+ // pizza and cat face emojis bounce around the screen
212
239
// emojis are from the OpenMoji emoji library (https://openmoji.org/)
213
240
// the background color is affected by the sliders
214
- // the speed of the cat emojis are affected by the V53L4CD
241
+ // the speed of the emojis are affected by the V53L4CD
242
+ // green slider affects # of cats
243
+ // blue slider affects # of pizzas
215
244
void pizzaCat () {
216
245
background (red, green, blue);
217
- int num_cats = int (map (flight, 0 , 45 , 65 , 15 ));
246
+ float meow = map (green, 0 , 255 , 32 , 16 );
247
+ float pie = map (blue, 0 , 255 , 15 , 0 );
248
+ float speed = map (flight, 0 , 45 , 0 , 25 );
249
+
250
+ for (int e = 16 ; e < meow; e++ ) {
251
+ if (last_speed != speed) {
252
+ moveX[e] = x_speeds[e] + speed;
253
+ moveY[e] = y_speeds[e] + speed;
254
+ }
255
+ else {
256
+ moveX[e] = moveX[e];
257
+ moveY[e] = moveY[e];
258
+ }
259
+ x_dir[e] += moveX[e];
260
+ if (x_dir[e] < 0 || x_dir[e] > width ) {
261
+ moveX[e] *= - 1 ;
262
+
263
+ }
264
+ if (x_dir[e] > width ) {
265
+ x_dir[e] = (width - 2 );
266
+ }
267
+ y_dir[e] += moveY[e];
268
+ if (y_dir[e] < 0 || y_dir[e] > height ) {
269
+ moveY[e] *= - 1 ;
270
+
271
+ }
272
+ if (y_dir[e] > height ) {
273
+ y_dir[e] = (height - 2 );
274
+ }
218
275
219
- pizza_pos = pizza_pos + ( pizza_speed * pizza_dir );
220
- cat_pos = cat_pos + ( num_cats * cat_dir );
276
+ image (cats[e], x_dir[e], y_dir[e]);
277
+
278
+ }
279
+ for (int p = 1 ; p < pie; p++ ) {
280
+ if (last_speed != speed) {
281
+ moveX[p] = x_speeds[p] + speed;
282
+ moveY[p] = y_speeds[p] + speed;
283
+ }
284
+ else {
285
+ moveX[p] = moveX[p];
286
+ moveY[p] = moveY[p];
287
+ }
288
+ x_dir[p] += moveX[p];
289
+ if (x_dir[p] < 0 || x_dir[p] > width ) {
290
+ moveX[p] *= - 1 ;
291
+ }
292
+ if (x_dir[p] > width ) {
293
+ x_dir[p] = (width - 2 );
294
+ }
295
+ y_dir[p] += moveY[p];
296
+ if (y_dir[p] < 0 || y_dir[p] > height ) {
297
+ moveY[p] *= - 1 ;
298
+ }
299
+ if (y_dir[p] > height ) {
300
+ y_dir[p] = (height - 2 );
301
+ }
221
302
222
- if (pizza_pos + img_w > width || pizza_pos < img_w) {
223
- pizza_dir *= - 1 ;
224
- }
225
- if (cat_pos + img_w > height || cat_pos < img_w) {
226
- cat_dir *= - 1 ;
227
- }
228
-
229
- for (int p = 0 ; p < 25 ; p++ ) {
230
- image (cat_img, pizza_pos- 10 , cat_pos* p);
231
- image (pizza_img, pizza_pos* p, cat_pos+ 10 );
232
- }
303
+ image (pizzas[p], x_dir[p], y_dir[p]);
304
+ }
305
+ last_speed = speed;
233
306
}
234
307
308
+
309
+
235
310
// the dancingTriangles animation
236
311
// triangles are randomly generated in the center of the screen
237
312
// the background is affected by the sliders
0 commit comments