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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:33:27+00:00 2026-06-01T03:33:27+00:00

We have an array of points through which we would like to draw a

  • 0

We have an array of points through which we would like to draw a quadratic curve on an HTML5 canvas, but we would like to draw the curve slowly, instead of all at once. Kind of like replaying the drawing of the curve.

Original curve: http://jsfiddle.net/NWBV4/12/

Curve replay: http://jsfiddle.net/NWBV4/15/

In the curve replay, if we change SEGMENT_PER_POINTS to something very large (e.g., 1000), it draws perfectly in one shot.

But as you can tell, with smaller numbers, there are gaps in the replay of the curve.

Any clues on how we can fix this? We’re pretty stuck!

  • 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-01T03:33:28+00:00Added an answer on June 1, 2026 at 3:33 am

    You should add a sleep primitive in your drawing code. However in javascript, rather than with sleep or wait primitives, this is accomplished in an event-directed manner with setInterval or setTimeout. As demonstrated:

    var sec = 1000; // milliseconds
    
    var totalDrawingTime = 5*sec;
    var numPointsToDraw = [calculate this];
    var waitTimePerPoint = totalDrawingTime/numPointsToDraw;
    
    function slowlyDrawCurve(...) {
        var x = ...;
    
        function drawNextPointAndWait() {
            x += ...;
            if (x < MAX_CANVAS_SIZE) {
                y = f(x);
                point = [x,y];
                dispatch_to_canvas_function(point);
                setTimeout(helper, waitTimePerPoint);
            }
        }
        drawNextPointAndWait();
    }
    

    edit

    Demonstration here: http://jsfiddle.net/eJVnU/4/

    This was actually a little more interesting. Namely, if you are drawing at intervals on order of a few milliseconds (1000 points means 1 millisecond per update!), you need to be careful how you deal with javascript’s timers. The javascript events scheduled with setTimeout may not trigger for a few milliseconds or more, making them unreliable! Therefore what I did was figure out when each segment should be completed by. If we were running ahead of schedule by more than a few milliseconds, we did a setTimeout, BUT, if we were otherwise running behind schedule, we directly performed a recursive call to the segment-drawing routine, shortcutting the event-handling system. This also ensures that the drawing is done smoothly to the human eye, as long as the segments are of roughly equal length.

    (If you wanted it done even more smoothly, you could calculate the length of the segment drawn, keep the sum total of arclength drawn, and divide that by some fixed constant rate arclength_per_second to figure out how long things should have taken.)

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

Sidebar

Related Questions

I have an array of points in unknown dimensional space, such as: data=numpy.array( [[
I have a very simple array (please focus on the object with "points.bean.pointsBase" as
I have a string like this: TEST.DATA.Data.COR.Point,2;TEST.DATA.Data.COR.Point,5;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.WordTOFIND,18 I have a list of array with
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
I have two arrays of x - y coordinates, and I would like to
Hey Guys I have four integer array lists which were created after parsing a
I have a function that has to accept an array of points, or an
If I have a 2D array, it is trivial to loop through the entire
I would like to define tasks using NSDictionary, which I'd like to save in

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.