Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9071647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:57:50+00:00 2026-06-16T17:57:50+00:00

I want to implement on my project this sketch about dragging a box. Instead

  • 0

I want to implement on my project this sketch about dragging a box.

Instead of one box, I have several circles each drawn with different coordinates in the form

  ellipse(lemma23.x, lemma23.y, diameterLemma23, diameterLemma23);

  ellipse(law3.x, law3.y, diameterLaw3, diameterLaw3);

  ellipse(law2.x, law2.y, diameterLaw2, diameterLaw2);

How do I test if the cursor is on one of the circles?

Here’s a screen shot of my project:

enter image description here

I want to test when cursor is on (or near) a circle so that I can change its position by dragging.

The entire sketch is in pastebin.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:57:52+00:00Added an answer on June 16, 2026 at 5:57 pm

    I started with the example in your question. There are a few main differences for drawing multiple shapes:

    1. You have to check whether the cursor is within each shape.
    2. You have to draw each shape.
    3. You may want to worry about overlapping, but I did not.

    In the following code, I build upon the example directly although I removed the few lines which change the color of the box when clicked and I reorganized the code into the MovingEllipse class so that multiple ellipses can be drawn easily. (This code draws two ellipses.)

    Note that the code in draw() checks the position of the mouse for each ellipse, however, I suppose this could be improved upon (i.e. perhaps by creating an array of ellipse positions and looping over the array). Also, for this code to work properly, mousePressed and mouseReleased methods need to be copied like the mouseDragged method. (I was trying to make my example brief.)

    Anyway, this is one way to draw multiple ellipses and detect which one should be moved. Hope it helps!

    int esize = 75;
    
    MovingEllipse e1 = new MovingEllipse(0.0, 0.0, esize, 0.0, 0.0);
    MovingEllipse e2 = new MovingEllipse(0.0, 0.0, esize, 0.0, 0.0);
    
    void setup() 
    {
      size(640, 360);
      e1.eX = width/2.0;    // Center of ellipse 1.
      e1.eY = height/2.0;
    
      e2.eX = width/4.0;    // Center of ellipse 2.
      e2.eY = height/4.0;
    }
    
    void draw() 
    { 
      background(0);
    
      // Test if the cursor is over the ellipse. 
      if (mouseX > e1.eX-esize && mouseX < e1.eX+esize && 
          mouseY > e1.eY-esize && mouseY < e1.eY+esize) {
        e1.overBox = true;  
        e2.overBox = false;
      } else if (mouseX > e2.eX-esize && mouseX < e2.eX+esize && 
          mouseY > e2.eY-esize && mouseY < e2.eY+esize) {
        e2.overBox = true;
        e1.overBox = false;
      } else {
        e1.overBox = false;
        e2.overBox = false;
      }
    
      // Draw the ellipse(s).
      e1.update(e1.eX, e1.eY, e1.overBox);
      e2.update(e2.eX, e2.eY, e2.overBox);
    }
    
    void mouseDragged() {
      e1.mouseDragged();
      e2.mouseDragged();
    }
    // Don't forget to repeat this for mousePressed and mouseReleased!
    // ...
    
    class MovingEllipse {
      float eX, eY;             // Position of ellipse.
      int eSize;                // Radius. For a circle use eSize for both x and y radii.
      float xOffset, yOffset;   // Where user clicked minus center of ellipse. 
      boolean locked, overBox;  // Flags used for determining if the ellipse should move.
    
      MovingEllipse (float ex, float ey, int esize, float xoff, float yoff) {
        eX = ex;
        eY = ey;
        eSize = esize;
        xOffset = xoff;
        yOffset = yoff;
      }
    
      void update(float ex, float ey, boolean over) {
        eX = ex;
        eY = ey;
        overBox = over;
        // Draw the ellipse. By default, (eX, eY) represents the center of the ellipse.
        ellipse(eX, eY, eSize, eSize);
      }
    
      void mousePressed() {
        if(overBox) { 
          locked = true; 
        } else {
          locked = false;
        }
        xOffset = mouseX-eX; 
        yOffset = mouseY-eY; 
      } 
      void mouseDragged() {
        if(locked) {
          eX = mouseX-xOffset; 
          eY = mouseY-yOffset; 
        } 
      }
      void mouseReleased(){
        locked = false;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this idea that I want to implement into my project. I know
I have developed a PHP project. In this I want to implement the font
i starter in jqgrid, i want implement inline edit in jqgrid i have this
Intro We have a project to design and implement this semester. For our project,
I'm trying to implement this project: http://img7.imagebanana.com/img/cnb46ti2/relationships.png I want to let view the skills
I want to implement Campaign Tracking in my application using EasyTracker I have this
I have a project where I want to implement voice recognition into a website.
I want to implement a Mesh class for a CG project, but have run
i have calculated maximum flow using ford fulkerson algorithm,now i want to implement project
I want to implement CI for my project, but I've never done this before.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.