6 Commits 30e77b2afd ... b73fd7a3aa

Author SHA1 Message Date
  UltrasonicMadness b73fd7a3aa Made the key presses for the new options case-insensitive 2 years ago
  UltrasonicMadness aba93aaa86 Updated documentation to reflect new options 2 years ago
  UltrasonicMadness 3ecf4167ed Updated copyright date to 2021 2 years ago
  UltrasonicMadness 77795acd27 Added option to make the bubbles multicoloured 2 years ago
  UltrasonicMadness 95aabe7594 Enabled instant colour changing with the number keys 2 years ago
  UltrasonicMadness 44020a3a3d Added ability to pause the rainbow 2 years ago
3 changed files with 94 additions and 13 deletions
  1. 6 1
      README.md
  2. 24 5
      RainbowBubble/Bubble.pde
  3. 64 7
      RainbowBubble/RainbowBubble.pde

+ 6 - 1
README.md

@@ -18,7 +18,12 @@ Download and install a Java Runtime Environment and run the RainbowBubble script
 OS and processor (probably application.*something*64) or alternatively, open __RainbowBubble.pde__ in the
 Processing IDE and click the __Run__ button on the top-left.
 
-Once the program is working, press the spacebar to toggle the bubbles on and off.
+Once the program is running, it can be influenced with the following keys
+
+* Spacebar: Toggle the bubbles on and off.
+* P: Pause the background rainbow. Press P again to resume colour cycling.
+* T: Toggle Bubble Tea Mode - Make the bubbles different colours.
+* 1-6: Set the background rainbow to a certain colour depending on the number key pressed.
 
 ## License
 Rainbow Bubble is licensed under the [Apache License 2.0](http://apache.org/licenses/LICENSE-2.0).

+ 24 - 5
RainbowBubble/Bubble.pde

@@ -1,5 +1,5 @@
 /*
- * Copyright 2018 UltrasonicMadness
+ * Copyright 2021 UltrasonicMadness
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,9 +16,12 @@
 
 public class Bubble
 {
-    // X and Y position of bubble
+    private final int[] COLORS = {0x80FF0000, 0x80FFFF00, 0x8000FF00, 0x8000FFFF, 0x800000FF, 0x80FF00FF};
+  
+    // Color and X and Y position of bubble
     private int xPos;
     private int yPos;
+    private int bubbleColor;
   
     // X offset, max X offset and whether bubble is moving to the right
     private int xOffset;
@@ -30,10 +33,12 @@ public class Bubble
     private int speed;
     private boolean active;
   
-    public Bubble(int initXPos, int initYPos, int initSize)
+    public Bubble(int initXPos, int initYPos, int initSize, boolean bubbleTeaMode)
     {
         xPos = initXPos;
         yPos = initYPos + initSize;
+        updateColor(bubbleTeaMode);
+        
         size = initSize;
         active = false;
     
@@ -49,7 +54,7 @@ public class Bubble
     
     public void draw()
     {
-        fill(196,196,255,128);
+        fill(bubbleColor);
         stroke(0,0,0,128);
         ellipse(xPos + xOffset, yPos, size, size);
     }
@@ -89,7 +94,7 @@ public class Bubble
         }
     }
   
-    public void activate()
+    public void activate(boolean bubbleTeaMode)
     {
         // If this bubble is not currently active.
         if (!active)
@@ -98,6 +103,20 @@ public class Bubble
     
             xPos = int(random(-size, width + size));
             yPos = height + size;
+            updateColor(bubbleTeaMode);
+        }
+    }
+    
+    private void updateColor(boolean bubbleTeaMode)
+    {
+        if (bubbleTeaMode)
+        {
+            bubbleColor = COLORS[int(random(0, COLORS.length))];
+        }
+        else
+        {
+            // The non-rainbow color
+            bubbleColor = 0x80C4C4FF;
         }
     }
 }

+ 64 - 7
RainbowBubble/RainbowBubble.pde

@@ -1,5 +1,5 @@
 /*
- * Copyright 2018 UltrasonicMadness
+ * Copyright 2021 UltrasonicMadness
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,15 @@ Bubble[] bubbles = new Bubble[256];
 // The bubbles can be turned off.
 boolean bubblesOn = true;
 
+// Which stage the rainbow is at currently (0-1535, i.e. 256 * 6)
+int rainbowFrame = 0;
+
+// If true, hold on a steady color
+boolean rainbowPaused = false;
+
+// If true, generate rainbow-colored bubbles
+boolean bubbleTeaMode = false;
+
 void setup()
 {
     size(800,600);
@@ -31,12 +40,24 @@ void setup()
      */
     for (int bubbleCounter = 0; bubbleCounter < bubbles.length; bubbleCounter++)
     {
-        bubbles[bubbleCounter] = new Bubble(int(random(0, width)), height, int(random(15,25)));
+        bubbles[bubbleCounter] = new Bubble(int(random(0, width)), height, int(random(15,25)), bubbleTeaMode);
     }
 }
 
 void draw()
 {
+    if (!rainbowPaused)
+    {
+        if (rainbowFrame >= 1535)
+        {
+            rainbowFrame = 0;
+        }
+        else
+        {
+            rainbowFrame++;
+        }
+    }
+    
     genBackground();
     genRainbow(196);
     
@@ -46,7 +67,7 @@ void draw()
         // Small chance of activating the bubble if the bubbles are on.
         if (int(random(0,64)) == 3 && bubblesOn)
         {
-            bubbles[bubbleCounter].activate();
+            bubbles[bubbleCounter].activate(bubbleTeaMode);
         }
       
         bubbles[bubbleCounter].advance();
@@ -64,8 +85,8 @@ void genBackground()
 
 void genRainbow(int alpha)
 {
-    int counter = frameCount % 256;
-    int colorTransitionId = (frameCount / 256) % 6;
+    int counter = rainbowFrame % 256;
+    int colorTransitionId = (rainbowFrame / 256) % 6;
     noStroke();
     
     switch (colorTransitionId)
@@ -100,8 +121,44 @@ void genRainbow(int alpha)
 
 void keyPressed()
 {
-    if (key == ' ')
+    switch (key)
     {
-        bubblesOn = !bubblesOn;
+        case ' ':
+            bubblesOn = !bubblesOn;
+            break;
+        
+        case 'P':
+        case 'p':
+            rainbowPaused = !rainbowPaused;
+            break;
+        
+        case 'T':
+        case 't':
+            bubbleTeaMode = !bubbleTeaMode;
+            break;
+        
+        case '1':
+            rainbowFrame = 0;
+            break;
+        
+        case '2':
+            rainbowFrame = 256;
+            break;
+        
+        case '3':
+            rainbowFrame = 512;
+            break;
+        
+        case '4':
+            rainbowFrame = 768;
+            break;
+        
+        case '5':
+            rainbowFrame = 1024;
+            break;
+        
+        case '6':
+            rainbowFrame = 1280;
+            break;
     }
 }