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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:25:55+00:00 2026-05-27T07:25:55+00:00

i’m developt a new proyect=, it is in html5 using canvas for draw elements.

  • 0

i’m developt a new proyect=, it is in html5 using canvas for draw elements.

I have 6 different canvas in the html and i have to know when the user draws over the canvas and draws at least a 50% of each canvas, and trigger an event when the user draws on all the canvas!

This is my code: http://jsfiddle.net/xtJZ3/

Thanks in advance.

  • 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-27T07:25:55+00:00Added an answer on May 27, 2026 at 7:25 am

    It would be hard and inefficient to calculate exactly when 50% of the image has been “scratched”. What you can do instead, is cheat a little, by dividing the image into “zone”. In this example, I divided your image into 16 vertical strips. Whenever the user clicks into a zone, we just mark it as “scratched”. We then check whether more than 8 zones have been scratched, and if so, do something.

    var zoneNumber = 16;
    var zoneSize = 250 / zoneNumber;
    var zones = [];
    for(var i = 0; i < zoneNumber; i++)
        zones.push(false);
    var done = false;
    

    In the constructor I initialize some variables like the number of zones, their sizes (I hard coded the size of your images), an array of false for whether they have been “scratched” and a variable indicating whether we have reported the image to have been scratched.

    var zone = Math.floor(x / zoneSize);
    zones[zone] = true;
    for(var i = 0, z = 0; i < zones.length; i++) {
        if (zones[i])
            z++;
        if (z >= zoneNumber / 2 && !done) {
            done = true;
            var p = document.createElement("p");
            p.innerHTML = "scratched";
            document.getElementById("main").appendChild(p);
        }
     }
    

    Then, in your scratch function, I use basic math to find out which zone the user is clicking. I set it to true, then count how many are true. If more than half, I show the message.

    Live example

    You could instead want to only show the message when you have 75% of the thing scratched, which would be better in my opinion. You could also make it more accurate by making the zones a 2D grid instead of just stripes.

    If you have any questions, don’t hesitate to ask.

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

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

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.