Skip to content

Instantly share code, notes, and snippets.

@rjlutz
Last active August 17, 2017 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjlutz/33c812ef29b3d5bba40ee9a9669cd9ce to your computer and use it in GitHub Desktop.
Save rjlutz/33c812ef29b3d5bba40ee9a9669cd9ce to your computer and use it in GitHub Desktop.
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