Action when mouse is on object

Hi,

I now have a script with objects (i’m using Fisica library). I would like to have two classes of circles. When the mouse in on a circle, something happens to the other (ex. it scales up). I just don’t know how to code this (in a void mouseSomething? with ‘‘if’’?). in // are various attempts I made but they didn’t work…

Thank you,

import fisica.*;
FCircle c;
ArrayList <FCircle> list = new ArrayList();
FWorld world;

//-----------------------------------
void setup() {
  size(500,500);
  smooth();
  
  Fisica.init(this);
  
  world = new FWorld();
  world.setGravity(0,1);
  world.setEdges();
  
  FCircle c = new FCircle(30);
  c.setPosition(300,300);
  c.setDamping(0.01);
  c.setVelocity(0, 200);
  c.setRestitution(0.6);
  world.add(c);
}

//------------------------------
void draw(){
  background(255);
  world.draw();
  world.step();
}
  
//   // Test if the cursor is over the box 
//  if (mouseX == circle position) { //????
//    onshape = true;  
//    if(!locked) { 
//      stroke(255); 
//      fill(153);
//    } 
//  } else {
//    stroke(153);
//    fill(153);
//    onshape = false;
//  }
//}

//  void mouseMoved() {
//  FBody hovered = world.getBody(mouseX, mouseY);
//   if (hovered == c){
//     FCircle b = new FCircle(2);
//     b.setPosition(random(0,width),random(0,height));
//     world.add(b);

//void mouseMoved(){
//  FBody hovered = world.getBody(mouseX, mouseY);
//   if c.collide (mouseX, mouseY){
//    FCircle b = new FCircle(2);
//    b.setPosition(random(0,width),random(0,height));
//    world.add(b);
//   }
  
  
  
  //void mousePressed() {
  //  FBody pressed = world.getBody (mouseX,mouseY); 
  //  if (F){
  //  float sz = 40;
  //  FCircle b = new FCircle(sz); 
  //  b.setPosition(300,300);
  //  b.setVelocity(0, 200);
  //  b.setRestitution(0.7);
  //  b.setDamping(0.01);
  //  b.setNoStroke();
  //  b.setFill(0);

Hi,

within draw() smth like:

if (dist(mouseX, mouseY, circle.x, circle.y)<circle.radius) {
  theOtherCircle.scale(2.0);
}

This could work! But I get an error message ‘‘x cannot be resolved or is not a field’’ because I’m using Fisica (I’m not sure how they define position of the circles because there arent’t any x and y in the code)…