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

  • Home
  • SEARCH
  • 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 4532944
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:05:36+00:00 2026-05-21T14:05:36+00:00

I have a script that draws a bunch of lines on canvas, but it’s

  • 0

I have a script that draws a bunch of lines on canvas, but it’s pretty intense so while rendering freezes browser for a few seconds. I added setTimeout() so that the browser wouldn’t freeze and it effectively messed up my script. It’s difficult to explain how, so I have two examples online:

Without setTimeout() : http://www.modwebsolutions.com/test1

With setTimeout() : http://www.modwebsolutions.com/test2

Note, that I only change a single line in the whole script, that is line 69:
without setTimeout(): vLoop();
with setTimeout(): setTimeout(vLoop,1);

  • 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-21T14:05:37+00:00Added an answer on May 21, 2026 at 2:05 pm

    The problem here, as hinted at by others, is that you are drawing the lines a quadrant at a time. As soon as the SetTimeout method is called and the first vLoop returns, the code carries on running into the next drawVertical which changes all the global variables and so on.

    What you need to do is synchronise how you’re calling vLoop and how you are changing the globals.

    This is basically the solution:

     

    Replace …

    drawVertical(c,-1*step,-1*stepInt,-1*bigStep,xStart,xEnd,y/2+50,y);
    drawVertical(c,step,stepInt,bigStep,xStart,xEnd,y/2+50,y);
    drawVertical(c,-1*step,-1*stepInt,-1*bigStep,xStart,xEnd,y/2-50,0); 
    drawVertical(c,step,stepInt,bigStep,xStart,xEnd,y/2-50,0);
    

    … with …

    var q = new Array();
    q[0] = [c,-1*step,-1*stepInt,-1*bigStep,xStart,xEnd,y/2+50,y];
    q[1] = [c,step,stepInt,bigStep,xStart,xEnd,y/2+50,y];
    q[2] = [c,-1*step,-1*stepInt,-1*bigStep,xStart,xEnd,y/2-50,0];
    q[3] = [c,step,stepInt,bigStep,xStart,xEnd,y/2-50,0];
    
    drawQuadrant(q, 0);
    

     

    Replace your drawVertical function with …

    function drawQuadrant(q, i)
    {
        var r = q[i];
    
        c__ = r[0];
        step__ = r[1];
        stepInt__ = r[2];
        bigStep__ = r[3];
        xStart__ = r[4];
        xEnd__ = r[5];
        yStart__ = r[6];
        yEnd__ = r[7]; 
    
    
        vLoop(q,i);
    }
    

     

    change the vLoop function prototype to look like this …

    function vLoop(q,i)
    

     

    and finally replace your recursive vLoop call (from within vLoop) with …

    if ((xStart__ > 0) && (xStart__ < window.innerWidth))
    {
        setTimeout( function(){vLoop(q,i)}, 1 );
    }
    else if (++i < 4)
    {
        setTimeout( function(){drawQuadrant(q,i)}, 1 );
    }
    

    The last block is where it ensures that the quadrants are not stepping over each other.

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

Sidebar

Related Questions

I have a script that draws an image on a canvas and allows people
I made a script that draws a series of lines on a canvas that
I have a script that has a few timeouts, draws a menu using Raphael
I have this script that run to fix my menu bar to the browser
I have a PHP script that creates a very tall image and draws a
I have a script that selects and drags several elements. It works fine but
I have a PHP script (let's call it execute.php ) that draws the whole
I have script that reads remote file content and writes it to local server.
I have a script that recursively loops through all the sub directories and compresses
I have a script that submits data via an ajax POST. It is called

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.