Instead of just telling Processing to draw a circle, let’s instead create a circle object. The circle object will encapsulate everything there is to know about itself, which at the moment isn’t much more than the x,y of its center point, and its radius.
class Circle {
float x, y;
float radius;
color linecol, fillcol;
float alph;
Circle () {
x = random(width);
y = random(height);
radius = random(100) + 10;
linecol = color(random(255), random(255), random(255));
fillcol = color(random(255), random(255), random(255));
alph = random(255);
}
}
Then we need to change our drawCircles function to this:
void drawCircles() {
for (int i=0; i<_num; i++) {
Circle thisCirc = new Circle();
}
}
Still no circles been draw because we haven't put the draw function into the circle class:
class Circle {
float x, y;
float radius;
color linecol, fillcol;
float alph;
Circle () {
x = random(width);
y = random(height);
radius = random(100) + 10;
linecol = color(random(255), random(255), random(255));
fillcol = color(random(255), random(255), random(255));
alph = random(255);
}
void drawMe() {
noStroke();
fill(fillcol, alph);
ellipse(x, y, radius*2, radius*2);
stroke(linecol, 150);
noFill();
ellipse(x, y, 10, 10);
}
}
And finally we must update the drawCircles() function
void drawCircles() {
for (int i=0; i<_num; i++) {
Circle thisCirc = new Circle();
thisCirc.drawMe();
}
}
Leave a Reply