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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:46:27+00:00 2026-06-05T06:46:27+00:00

I’m having trouble implementing an erase feature for the objects I draw. I draw

  • 0

I’m having trouble implementing an “erase” feature for the objects I draw. I draw objects like so:

function draw_obj1(context) {
    context.lineTo(...)
    context.arc(...)
    //etc
}

And these are drawn overtop of an image background I have for the canvas (via context.createPattern, fillStyle = pattern, etc).

So say the above function traces out a triangle using various lineTo calls. Now to “erase”, or “undo” this drawing, one plan I had was to re-draw the ‘xor’ version of the same object on top of it, to undo it. I do this via context.globalCompositeOperation (see: https://developer.mozilla.org/samples/canvas-tutorial/6_1_canvas_composite.html).

This almost works, except the final result comes up not completely blank against my light-blue background. It comes out as a light-greyish triangle, versus the original black-lined triangle.

EDIT – forgot to mention another idea I tried. Doing ‘clearRect’ on the area I need gone makes a white hole in my light-blue background which is no good.

So how should I go about undoing lines/arcs that I’ve drawn?

Cheers

  • 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-05T06:46:28+00:00Added an answer on June 5, 2026 at 6:46 am

    This won’t be possible using only your Canvas content.
    Canvas element reacts like a real canvas: since things are drawn, they are merged and bound to the full picture.

    This is because canvas, in most graphic APIs, is just an array of bytes.
    Computer can’t know, alone, how to identify and differ the objects composing the current frame.

    The best way to do this is to implement something like a “scene graph”, a graph tree.
    You could then append objects to this graph tree and construct your own algorythm for drawing each object on the canvas.

    You could have a history data structure to allow undo/redo appending/removing objects from the scene graph and redrawing each object in a small timeslice (nano-milliseconds).

    That’s a holistic view over your problem. Hope you know how to handle graphs programmatically.

    More on here: How to add undo-functionality to HTML5 Canvas?

    and here: http://www.abidibo.net/blog/2011/10/12/development-undo-and-redo-functionality-canvas/

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.