|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright 2017 UltrasonicMadness
|
|
|
+ * Copyright 2018 UltrasonicMadness
|
|
|
*
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -17,8 +17,11 @@
|
|
|
// Array of 256 bubbles
|
|
|
Bubble[] bubbles = new Bubble[256];
|
|
|
|
|
|
+// The bubbles can be turned off.
|
|
|
+boolean bubblesOn = true;
|
|
|
+
|
|
|
void setup()
|
|
|
- {
|
|
|
+{
|
|
|
size(800,600);
|
|
|
noCursor();
|
|
|
|
|
@@ -27,63 +30,78 @@ void setup()
|
|
|
* below the screen and a radius between 15 and 25 pixels.
|
|
|
*/
|
|
|
for (int bubbleCounter = 0; bubbleCounter < bubbles.length; bubbleCounter++)
|
|
|
- {
|
|
|
+ {
|
|
|
bubbles[bubbleCounter] = new Bubble(int(random(0, width)), height, int(random(15,25)));
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
void draw()
|
|
|
- {
|
|
|
+{
|
|
|
genBackground();
|
|
|
genRainbow(196);
|
|
|
|
|
|
// Update each bubble
|
|
|
for (int bubbleCounter = 0; bubbleCounter < bubbles.length; bubbleCounter++)
|
|
|
- {
|
|
|
- bubbles[bubbleCounter].update();
|
|
|
- }
|
|
|
- }
|
|
|
+ {
|
|
|
+ // Small chance of activating the bubble if the bubbles are on.
|
|
|
+ if (int(random(0,64)) == 3 && bubblesOn)
|
|
|
+ {
|
|
|
+ bubbles[bubbleCounter].activate();
|
|
|
+ }
|
|
|
+
|
|
|
+ bubbles[bubbleCounter].advance();
|
|
|
+ bubbles[bubbleCounter].draw();
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
void genBackground()
|
|
|
- {
|
|
|
+{
|
|
|
fill(255);
|
|
|
noStroke();
|
|
|
|
|
|
rect(0,0,width,height);
|
|
|
- }
|
|
|
+}
|
|
|
|
|
|
void genRainbow(int alpha)
|
|
|
- {
|
|
|
+{
|
|
|
int counter = frameCount % 256;
|
|
|
int colorTransitionId = (frameCount / 256) % 6;
|
|
|
noStroke();
|
|
|
|
|
|
switch (colorTransitionId)
|
|
|
- {
|
|
|
+ {
|
|
|
case 0: // red to yellow, red at 255, green ascending, blue at 0
|
|
|
- fill(255, counter, 0, alpha);
|
|
|
- break;
|
|
|
+ fill(255, counter, 0, alpha);
|
|
|
+ break;
|
|
|
|
|
|
case 1: // yellow to green, red descending, green at 255, blue at 0
|
|
|
- fill(255 - counter, 255, 0, alpha);
|
|
|
- break;
|
|
|
+ fill(255 - counter, 255, 0, alpha);
|
|
|
+ break;
|
|
|
|
|
|
case 2: // green to cyan, red at 0, green at 255, blue ascending
|
|
|
- fill(0, 255, counter, alpha);
|
|
|
- break;
|
|
|
+ fill(0, 255, counter, alpha);
|
|
|
+ break;
|
|
|
|
|
|
case 3: // cyan to blue, red at 0, green descending, blue at 255
|
|
|
- fill(0, 255 - counter, 255, alpha);
|
|
|
- break;
|
|
|
+ fill(0, 255 - counter, 255, alpha);
|
|
|
+ break;
|
|
|
|
|
|
case 4: // blue to pink, red ascending, green at 0, blue at 255
|
|
|
- fill(counter, 0, 255, alpha);
|
|
|
- break;
|
|
|
+ fill(counter, 0, 255, alpha);
|
|
|
+ break;
|
|
|
|
|
|
case 5: // pink to red, red at 255, green at 0, blue descending
|
|
|
- fill(255, 0, 255 - counter, alpha);
|
|
|
- break;
|
|
|
- }
|
|
|
+ fill(255, 0, 255 - counter, alpha);
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
rect(0,0,width,height);
|
|
|
- }
|
|
|
+}
|
|
|
+
|
|
|
+void keyPressed()
|
|
|
+{
|
|
|
+ if (key == ' ')
|
|
|
+ {
|
|
|
+ bubblesOn = !bubblesOn;
|
|
|
+ }
|
|
|
+}
|