Last active
August 17, 2017 13:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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