Skip to content

Instantly share code, notes, and snippets.

@rjlutz rjlutz/Bubble.pde
Last active Aug 17, 2017

Embed
What would you like to do?
A Really Simple Demonstration of Processing Using Active Mode and a Bubble Class
public class Bubble {
int x, y;
float r;
int incrX = (int) random(4,8);
int incrY = (int) random(2,8);
int red, green, blue, alpha;
public Bubble() {
x = (int)random(width);
y = (int) random(height);
r = random(20,200);
red = (int)random(255);
green = (int)random(255);
blue = (int)random(255);
alpha = (int)random(255);
}
public void display() {
x = x + incrX;
y += incrY;
if (x > width || x < 0) incrX = -incrX;
if (y > height || y < 0) incrY = -incrY;
fill(red, green, blue, alpha);
ellipse(x,y,r,r);
}
}
private ArrayList<Bubble> bubbles;
public void setup() {
size(800,600);
bubbles = new ArrayList<Bubble>();
for (int i = 0; i < 10; i++) {
bubbles.add(new Bubble());
}
}
public void draw() {
clear();
for (Bubble b : bubbles)
b.display();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.