/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://processing-101.sketchpad.cc/sp/pad/view/ro.fikEFLRZLgC/rev.1
*
* authors:
* Brett Bowman
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
Ball [] b;
void setup ()
{
size (400, 400);
smooth();
noStroke();
b= new Ball[100];
for (int i=0; i < 100; i++) // this array allows us to initialize 100 instances of b
{
b[i]=new Ball(i, i, 10);
}
}
void draw ()
{
//background (100);
//frameRate(30);
//noStroke();
//if (mousePressed)
{
for (int i=0; i < 100; i++)
{
b[i].display();
b[i].updatePosition();
}
}
}
class Ball
{
float x, y, d;
float dx, dy;
color c;
Ball (int xPosition, int yPosition, int dia) // constructor
{
x=xPosition;
y=yPosition;
d=dia;
c = color(random(200), random(100), random(200), random(50,150));
dx = random (5, 10);
dy = random (5, 10);
}
void sparkle ()
{
fill (255, 255, 255, 20);
ellipse (x, y, d+10, d+10);
}
void display ()
{
fill (c);
ellipse(x, y, d, d);
}
void updatePosition ()
{
x=x+dx;
y=y+dy;
if (x>width)
{
dx=-dx;
}
if (x<0)
{
dx=-dx;
}
if (y>height)
{
dy=-dy;
}
if (y<0)
{
dy=-dy;
}
}
}