/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://processing-101.sketchpad.cc/sp/pad/view/ro.4$cuUO-fD1H/rev.11
*
* authors:
* Pino Trogu
* Ben Chun
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
class Ball
{
int x;
int y;
int d;
color c;
// constructor - like a setup function for this class
Ball(int xPosition, int yPosition, int dia)
{
x = xPosition;
y = yPosition;
d = dia;
c = color(random(255), random(255), random(255));
}
void display()
{
fill(c);
ellipse(x, y, d, d);
}
void updatePosition()
{
x = x+1;
if(x > width)
{
x = 0;
}
}
}
Ball ball1;
Ball ball2;
void setup()
{
size(400,400);
smooth();
ball1 = new Ball(200, 200, 10);
ball1.c = color(255);
ball2 = new Ball(100, 100, 50);
}
void draw()
{
background(0);
ball1.display();
ball1.updatePosition();
ball2.display();
ball2.updatePosition();
}