@@ -54,16 +54,22 @@ int xdirection = 1;
5454int ydirection = 1 ;
5555
5656// 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 ;
5960
60- float pizza_pos, cat_pos;
61+ PImage [] cats = new PImage [catCount];
62+ PImage [] pizzas = new PImage [pizzaCount];
6163
62- int img_w = 10 ;
64+ float [] moveX = new float [emojiCount];
65+ float [] moveY = new float [emojiCount];
6366
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];
6773
6874// variables for dancingTriangles animation
6975int x1;
@@ -98,6 +104,23 @@ void setup()
98104 cat_img = loadImage (" cat.png" );
99105 pizza_img = loadImage (" pizza.png" );
100106
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+
101124 // connecting to socket to communicate with Blinka script
102125 myClient = new Client (this , " 127.0.0.1" , 12345 );
103126
@@ -116,27 +139,31 @@ void draw()
116139 // the encoder pos is stored in index
117140 String [] q = splitTokens (inString);
118141 index = int (q[1 ]);
142+ println (index);
119143 }
120144 // if the string begins with 'red'
121145 // aka is from the red neoslider
122146 if (inString. startsWith(" red" )) {
123147 // the red value is stored in red
124148 String [] r = splitTokens (inString);
125149 red = int (r[1 ]);
150+ println (red);
126151 }
127152 // if the string begins with 'green'
128153 // aka is from the green neoslider
129154 if (inString. startsWith(" green" )) {
130155 // the green value is stored in green
131156 String [] g = splitTokens (inString);
132157 green = int (g[1 ]);
158+ println (green);
133159 }
134160 // if the string begins with 'blue'
135161 // aka is from the blue neoslider
136162 if (inString. startsWith(" blue" )) {
137163 // the blue value is stored in blue
138164 String [] b = splitTokens (inString);
139165 blue = int (b[1 ]);
166+ println (blue);
140167 }
141168 // if the string begins with flight
142169 // aka is from the VL53L4CD
@@ -147,7 +174,7 @@ void draw()
147174 }
148175 }
149176 // the encoder's position corresponds with which animation plays
150- if (index == 0 ) {
177+ if (index == 3 ) {
151178 circles();
152179 }
153180
@@ -157,7 +184,7 @@ void draw()
157184 if (index == 2 ) {
158185 dancingTriangles();
159186 }
160- if (index == 3 ) {
187+ if (index == 0 ) {
161188 pizzaCat();
162189 }
163190 }
@@ -208,30 +235,78 @@ void cube() {
208235}
209236
210237// 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
212239// emojis are from the OpenMoji emoji library (https://openmoji.org/)
213240// 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
215244void pizzaCat () {
216245 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+ }
218275
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+ }
221302
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;
233306}
234307
308+
309+
235310// the dancingTriangles animation
236311// triangles are randomly generated in the center of the screen
237312// the background is affected by the sliders
0 commit comments