/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://hewitt.sketchpad.cc/sp/pad/view/ro.bAGluJpinWB/rev.3
*
* authors:
* Rebecca Meyer
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
int numCircles = 500;
Circle[] circles = new Circle[numCircles]; // define the array
float distance;
PFont myFont;
void setup()
{
size(1000, 700);
myFont = loadFont("Impact-30.vlw");
textFont(myFont, 27);
smooth();
noStroke();
for (int i=0; i<numCircles; i++) {
circles[i] = new Circle(random(width), random(height)); // fill the array with circles at random positions
}
}
void draw() {
background(205);
for (int i=0; i<numCircles; i++) {
circles[i].display(); // display all the circles
}
fill(0, 0, 255);
text("To change the color of the large circle, press r, g, b, y, t, or p and click and drag.", 30, 40);
}
class Circle {
float x, y; // location
float dim; // dimension
color c; // color
Circle(float x, float y) {
this.x = x;
this.y = y;
dim = random(20, 50);
c = color(random(255));
}
void display() {
float distance = dist(x, y, mouseX, mouseY); // distance between circle and mouse
if (distance < 255 && mousePressed)
{ // if distance is smaller than 255
fill(255-distance, 0, 0);
if (key == 'r')
{
fill(255-distance, 0, 0);
}
if (key == 'g')
{
fill(0, 255-distance, 0);
}
if (key == 'b')
{
fill(0, 0, 255-distance);
}
if (key == 't')
{
fill(0, 255-distance, 255-distance);
}
if (key == 'p')
{
fill(255-distance, 0, 255-distance);
}
if (key == 'y')
{
fill(255-distance, 255-distance, 0);
}
}
else if (distance < 255 && !mousePressed)
{ // if distance is bigger than 255
fill(255-distance);
}
else
{
fill(c);
}
ellipse(x, y, dim, dim); // a circle at position xy
}
}