• fullscreen
  • Bubbles.pde
  • PortHole.pde
  • bubble_porthole.pde
  • class Bubbles {
      float x, y; 
      float xMove, yMove;
      float s = random(2,7);
    
      Bubbles() {
        x = random(width);
        y = random(height);
        yMove = random(2,5);
      }
    
      void move() {
        y -= yMove;
        x -= xMove;
        xMove = random(-2, 2);
        if (y < -20) {
          y = height + 10;
        }
      }
    
      void display() {
        stroke(255);
        noFill();
        ellipse(x, y, s, s);
      }
    }
    
    
    class PortHole {
      float x, y;
    
      PortHole() {
      }
    
      void display() {
        fill(0);
        rect(-10, -10, width+20, height+20);
        fill(46, 53, 216);
        ellipse(mouseX, mouseY, 300, 300);
        stroke(0);
        strokeWeight(5);
        line(mouseX,mouseY-145,mouseX,mouseY+145);
        line(mouseX-145,mouseY,mouseX+145,mouseY);
        line(mouseX-20,mouseY-10,mouseX-10,mouseY-10);
        line(mouseX-20,mouseY-20,mouseX-10,mouseY-20);
        line(mouseX-20,mouseY-30,mouseX-10,mouseY-30);
        line(mouseX-20,mouseY-40,mouseX-10,mouseY-40);
        line(mouseX-40,mouseY-50,mouseX-10,mouseY-50);
        line(mouseX-20,mouseY-60,mouseX-10,mouseY-60);
        line(mouseX-20,mouseY-70,mouseX-10,mouseY-70);
        line(mouseX-20,mouseY-80,mouseX-10,mouseY-80);
        line(mouseX-20,mouseY-90,mouseX-10,mouseY-90);
        line(mouseX-40,mouseY-100,mouseX-10,mouseY-100);
        line(mouseX-20,mouseY-110,mouseX-10,mouseY-110);
        line(mouseX-20,mouseY-120,mouseX-10,mouseY-120);
        line(mouseX-20,mouseY-130,mouseX-10,mouseY-130);
        line(mouseX-20,mouseY-140,mouseX-10,mouseY-140);
      }
    }
    
    
    Bubbles[] bubble;
    PortHole hole;
    
    void setup() {
      size(600, 600);
      smooth();
      noCursor();
      hole = new PortHole();
      bubble = new Bubbles[100];
      for (int i = 0; i < 100; i++) {
        bubble[i] = new Bubbles();
      }
    }
    
    void draw() {
      background(46, 53, 216);
      hole.display();
      for (int i = 0; i < 100; i++) {
        if (dist(mouseX, mouseY, bubble[i].x, bubble[i].y) <= 149) {
          bubble[i].display();
        }
        bubble[i].move();
      }
    }
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Joshua Moody

    Porthole with Bubbles

    Add to Faves Me Likey@!
    You must login/register to add this sketch to your favorites.

    A distance formula helps keep all bubbles outside the scope invisible while a fun little loop keeps the submersible fun going on and on

    You need to login/register to comment.