How to find location of random object

so I am trying to make a hot and cold game and i have a randomly generated ellipse and i was wondering how to find the location of the ellipse in relation to my mouse so whenever i click it shows me how far away i am from the randomly generated invisible ellipse. here is the code i have now, any help would be much appreciated as i am very new to processing.

final int ballDiam = 30;
float posX;
float posY;
final int coldDetector = 400;
final int warmDetector = 250;
final int hotDetector = 100;
final int hotColor = color(255,0,0);
final int warmColor = color(255,100,0);
final int coldColor = color(0,0,255);

void setup()
{
 size(500,500); 
 posX = random(width);
  posY = random(height);
}

void draw()
{
  background(200);
 //add stroke (stroke(200); when progrm is finished
  fill(200);
  ellipse(posX,posY,ballDiam,ballDiam);
  noFill();
  ellipse(mouseX,mouseY,50,50);
}

Hi NotConsumable,
Have a look at the dist() function and the mouseReleased() functions.

Also, for future reference, please format your code by selecting it and pressing ctrl + shift + c or by clicking the “</>” button in the editor.

You could indicate how far away from the hidden target (the treasure) the mouse was clicked

Basically get the distance with dist

And the use lerpColor to make a color

Apply the color with fill()

And then say ellipse (mouseX,mouseY, 9,9);

See the reference for details

Chrisir

you can also use noCursor(); to hide the mouse cursor

here is my version


final int ballDiam = 30;
float posX;
float posY;
final int coldDetector = 400;
final int warmDetector = 250;
final int hotDetector = 100;
final int hotColor = color(255, 0, 0);
final int warmColor = color(255, 100, 0);
final int coldColor = color(0, 0, 255);

void setup()
{
  size(500, 500);
  posX = random(ballDiam, width-ballDiam);
  posY = random(ballDiam, height-ballDiam);

  noCursor();
}

void draw()
{

  background(200);
  //add stroke (stroke(200); when progrm is finished
  fill(200);
  stroke(0); 
  ellipse(posX, posY, 
    ballDiam, ballDiam);

  noFill();
  stroke(255, 0, 0); 
  ellipse(mouseX, mouseY, 
    50, 50);
}