topical media & game development
graphic-processing-learning-18-example-18-3-Bubble.pde / pde
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
// Example 18-3: Creating objects from a text file
// A Class to describe a "Bubble"
class Bubble {
float x,y;
float diameter;
float speed;
float r,g;
// The constructor initializes color and size
// Location is filled randomly
Bubble(float r_, float g_, float diameter_) {
x = random(width);
y = height;
r = r_;
g = g_;
diameter = diameter_;
}
// Display the Bubble
void display() {
stroke(0);
fill(r,g,255,150);
ellipse(x,y,diameter,diameter);
}
// Move the bubble
void drift() {
y += random(-3,-0.1);
x += random(-1,1);
if (y < -diameter*2) {
y = height + diameter*2;
}
}
}
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.