fullscreen Bubble[] bubbles = new Bubble [10]; // An array of 100 Car objects!
float r;
float g;
float b;
float x;
float y;
float p;
boolean appear;
void setup() {
size(800,800);
background (0);
smooth();
}
void draw() {
fill (0, 15);
x=random (3, 10);
y=random (3, 10);
p=random (-1, 1);
rect (0, 0, height, width);
if (appear==true) {
for (int i = 0; i < bubbles.length; i ++ ) {
bubbles [i] = new Bubble (r, g, b, mouseX+i*3*p*x,mouseY+i*3*p*y,i/20.0);
}
for (int i = 0; i < bubbles.length; i ++ ) { // Run each Car using a for loop.
bubbles[i].move();
bubbles [i].display();
}
}
else {
}
}
void mousePressed() {
if (mouseX>0 && mouseX <height && mouseY>0 && mouseY<height) {
//button1switch=!button1switch;}
//this makes it switch every time. ! it inverts. so it says if that's true.
if(appear==true) {
appear=false;
}
else {
appear=true;
}
}
}
class Bubble {
color c;
float xpos;
float ypos;
float xspeed;
float r;
float g;
float b;
Bubble (float y, float u, float i, float tempXpos, float tempYpos, float tempXspeed) { // The Constructor is defined with arguments.
r=y;
u=g;
i=b;
r=random (0, 255);
g=random (0, 255);
b=random (0, 255);
xpos = tempXpos;
ypos = tempYpos;
xspeed = tempXspeed;
}
void display() {
stroke(0);
fill(r, g, b);
ellipseMode(CENTER);
ellipse (xpos,ypos,40,40);
}
void move() {
xpos = xpos + xspeed;
if (xpos > width) {
xpos = 0;
}
}
}
Floating Bubbles follow the mouse.
Click to erase and start over.