hi, i have a simple question: i need to calculate when the mouse collide with objects and also when it doesnt collide and i need to use this to control the color of a ellipse, im making this calculating distance, but im having problems because when the mouse collide with an object it change the color but the thing is that at the same time the other objects are not colliding with the object so it change the color back to its previous value.
how can i solve this problem?
and can i make this instedea using class / objects?
please see the code so you can understand better, when i touch the little red ellipses with the mouse its suppose to change the color of the big ellipse too, but it doesnt do that. any idea?
how can i solve this problem?
and can i make this instedea using class / objects?
please see the code so you can understand better, when i touch the little red ellipses with the mouse its suppose to change the color of the big ellipse too, but it doesnt do that. any idea?
int numAgente= 3;
float colorono = 0;
Agente[] arreglo =new Agente[numAgente];
void setup(){
size(600,400);
noStroke();
background(238, 282, 299);
for (int i=0; i<numAgente; i++){
arreglo[i] = new Agente();
}
}
void draw(){
background(238, 282, 299);
fill(colorono,250, 0);
ellipse(100 , 100 ,55,55);
for (int k=0; k<numAgente; k++){
arreglo[k].dibuja();
}
}
class Agente{
float x= random(500);
float y= random (400 );
float dista;
color coloryo ;
void dibuja(){
fill(coloryo);
ellipse(x , y ,15,15);
for (int i=0; i<numAgente; i++){
int collisionCount = 0;
dista = dist(mouseX, mouseY , arreglo[i].x , arreglo[i].y );
if (dista < 20){
arreglo[i].coloryo = color(2, 40, 0);
colorono = 250;
}
else
{
coloryo = color(222, 40, 0);
colorono = 0;
}
}
}
}
1