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 7704481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:41:25+00:00 2026-05-31T23:41:25+00:00

If I define a canvas and draw few shapes onto it, then how can

  • 0

If I define a canvas and draw few shapes onto it, then how can I pinpoint each of the shape or image so as to declare events and other properties on the each shape. Consider I have a Rectangle and a triangle. SO can I have some mechanism so as to define them as specific entity and can I deal with them individually. I know about KineticJS but I would like to implement this functionality on my own(For learning purpose). Can anyone pinpoint the way to do it. Or may be an algorithmic approach??

  • 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-05-31T23:41:27+00:00Added an answer on May 31, 2026 at 11:41 pm

    You can’t use any existing functionality in the DOM for that. So you have to write it yourself. You could start by making an object model like this:

    function Shape(x, y) {
      var obj = {};
      obj.x = x;
      obj.y = y;
    
      obj.paint = function(canvasTarget) {
      }
    
      return obj;
    }
    
    function Rectangle(x, y, width, height) {
      var obj = Shape(x, y);
      obj.width = width;
      obj.height = height;
    
      obj.paint = function(canvasTarget) {
         //paint rectangle on the canvas
      }
    
      return obj;
    }
    
    function Canvas(target) {
      var obj = {};
      obj.target = target
      obj.shapes = [];
    
      obj.paint = function() {
         //loop through shapes and call paint
      }
    
      obj.addShape(shape) {
         this.shapes.push(shape);
      }        
    }
    

    After making the object model you could use it to draw the shapes like this:

    var cnv = new Canvas();
    cnv.addShape(new Rectangle(10,10,100,100));
    cnv.paint();
    

    Then you can handle the onclick event on the canvas and determine which shape is clicked on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to draw some text onto my canvas and want to clear everything
When drawing on a canvas in firefox, if you attempt to draw at or
I need to define canvas width and height in centimeters, so basically I have
When drawing lines with the HTML5 canvas element, is it possible to define the
I'm developing an application where users draw euclidean constructions on the HTML5 canvas. As
Consider a simple canvas as $(document).ready(function(){ draw(); }); function draw() { var canvas =
I would like to show an image on Canvas(HTML5) so that I will be
Here is the relevant code: Canvas.cpp #ifndef CANVAS #define CANVAS #include graphicsDatatypes.h class Canvas
How can I stretch draw an area of a gdk pixbuf to a cairo
I have a Graphics2D object which I use to draw on my Canvas .

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.