Kll and I basically use the same way, just that i packed it in a class (and now even in a Manager cause it makes it simpler and i needed some practice with managers Anyway).
Easier than kll‘s method probably doesn’t exist. It‘s just drawing, setting 2 variables and an if statement that resets it all.
@kll To be honest, i can‘t get my Head around how to do this either, without using a Class or separate variables for each circle and then resetting them with intervals (like reset Circle 1 at 0, c2 at 60 frameCount, c3 at 120 and then c1 again, or something like that…), which just seems way too inefficient compared to using classes…
Anyway, i added a CircleManager class, just for fun and thought i‘d post it too, just in case someone‘s interested.
Note, i‘ll put it in a Spoiler, since we‘re still here to help you learn how to Code, not to do everything… but i really wanna share it, now that i made it
CircleManager
CircleManager cM;
void setup() {
size(800, 600);
cM = new CircleManager(5, 40, 1, 3, 200, 300, 20, color(255, 0, 0));
// the parameters are :
// 5 = circleArrayLength (doubt you need more than 5)
// 40 = frequency
// 1 = growth
// 3 = diffusion (color fading)
// 200, 300 position x, y
// 20 = initial size
// color is obvious
}
void draw() {
background(255);
cM.update();
}
class CircleManager {
Circle circles;
PVector pos;
float cSize;
color cFill;
int frequency;
float growth;
float diffusion;
CircleManager (int circleLength, int f, float g, float d, float x, float y, float s, color cF) {
circles = new Circle[circleLength];
frequency = f;
growth = g;
diffusion = d;
pos = new PVector(x, y);
cFill = cF;
cSize = s;
createCircles();
}
void createCircles() {
for (int i = 0; i < circles.length; i++) {
circles[i] = new Circle(pos.x,pos.y,cSize, cFill);
}
}
void update() {
stroke(255,255,0,100);
fill(255,255,0,100);
ellipse(pos.x, pos.y, 100, 100);
for (int i = 0; i < circles.length; i++) {
circles[i].display();
//circles[i].move(0, -1);
circles[i].scale(growth); //speed of expansion
circles[i].fade(diffusion); // speed of diffusion
}
fill(255,0,0,255);
stroke(255,0,0,255);
ellipse(pos.x, pos.y, 20, 20);
if (frameCount%frequency == 0) {
//frequency of new circles
pushCircles();
}
}
void pushCircles () {
for (int i = 0; i < circles.length-1; i++) {
circles[i] = circles[i+1];
}
circles[circles.length-1] = new Circle(pos.x,pos.y,cSize,cFill);
}
}
class Circle {
PVector pos;
float s;
color cFill;
Circle (float x, float y, float s_, color f) {
pos = new PVector(x, y);
s = s_;
cFill = f;
}
void move(float x, float y) {
pos.add(new PVector(x, y));
}
void scale(float s_) {
s += s_;
}
void fade(float a) {
cFill = color(red(cFill), green(cFill) + a <= 255 ? green(cFill) + a : 255, blue(cFill), alpha(cFill) - a >= 0 ? alpha(cFill) - a : 0);
}
void display() {
stroke(cFill);
fill(cFill);
ellipse(pos.x, pos.y, s, s);
}
}