Hi, i’ve got this sketch where i want to create a new circle whenever a mousePressed() event occurs. It’s been fine for me but now i want it to appear whenever my mouse is located so it continues its path and don’t follow my mouse. i’ve tried to defined it in my class part and in my mousePressed() event but doesn’t work. I’d appreciate your help.
Circulo[] circulos = new Circulo[20];
int cantidad = 0;
void setup() {
size(400,400);
for (int i= 0; i < circulos.length; i++) {
circulos[i] = new Circulo(32);
}
}
void mousePressed() {
cantidad = cantidad +1;
}
void draw() {
background(0);
//fill(150,50);
if (frameCount % 10 == 0) {
fill(frameCount*3 % 255, frameCount*5 % 255, frameCount
*7 % 255, 50);
}
//translate(mouseX, mouseY); //centra figura
for (int i= 0; i < cantidad; i++) {
circulos[i].display();
circulos[i].escala();
circulos[i].tope();
}
}
And this is my class part:
<class Circulo {
float r;
float x;
float y;
float diametro;
Circulo(float radio) {
//x = width/2;
//y = height/2;
diametro = radio;
}
void display() {
stroke(255);
//ellipseMode(CENTER);
ellipse(mouseX,mouseY,r,r);
}
void escala() {
r+=0.4;
//x = x + random (-2,2); // efecto
}
void tope() {
if (y < diametro/2) {
y = diametro/2;
}
}
}