A bubble tube sketch written in Processing. http://www.ultrasonicmadness.org/software/rainbow-bubble/

[[ 🗃 ^zrebo rainbow-bubble ]] :: [📥 Inbox] [📤 Outbox] [🐤 Followers] [🤝 Collaborators] [🛠 Commits]

Clone

HTTPS: git clone https://vervis.peers.community/repos/zrebo

SSH: git clone USERNAME@vervis.peers.community:zrebo

Branches

Tags

v0.0.1 :: RainbowBubble /

RainbowBubble.pde

/*
 * Copyright 2017 UltrasonicMadness
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Array of 256 bubbles
Bubble[] bubbles = new Bubble[256];

void setup()
  {
    size(800,600);
    noCursor();
    
    /*
     * Initialize the bubbles with a random x position, a y position
     * 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();
      }
  }

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;
      
        case 1: // yellow to green, red descending, green at 255, blue at 0
          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;
    
        case 3: // cyan to blue, red at 0, green descending, blue at 255
          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;
      
        case 5: // pink to red, red at 255, green at 0, blue descending 
          fill(255, 0, 255 - counter, alpha);
          break;
      }
  
    rect(0,0,width,height);
  }
[See repo JSON]