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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:28:04+00:00 2026-05-20T23:28:04+00:00

if I draw to the canvas a lot in quick succession, e.g. a context.fillRect

  • 0

if I draw to the canvas a lot in quick succession, e.g. a context.fillRect in a loop, browsers seem to wait until the loop has finished before any of the drawing is displayed (possibly via double-buffering)

Is there any way to force the browser to update the display, either explicitly or implicitly after each draw operation?

  • 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-20T23:28:04+00:00Added an answer on May 20, 2026 at 11:28 pm

    It is not really because of any double-buffering that you don’t see the results, but rather because JavaScript in the web browser is single-threaded. If you similarly create a single loop in JavaScript that repeatedly does something like myDiv.style.top = parseInt(myDiv.style.top) + 1 +"px"; you will see that nothing will visibly change in the browser—even over many seconds—until your JavaScript has finished executing.

    To draw changes and see the results on the screen, you need to use setInterval or setTimeout to yield control back to the browser but ask to run code at some point in the future.

    For example, to draw a new random, randomly-colored rectangle on the canvas 15 times a second:

    var canvas = document.getElementsByTagName('canvas')[0];
    var ctx = canvas.getContext('2d');
    setInterval(function(){
      ctx.clearRect(0,0,canvas.width,canvas.height);
      var r=Math.random()*255, g=Math.random()*255, b=Math.random()*255;
      ctx.fillStyle = 'rgb('+r+','+g+','+b+')';
      var w=Math.random()*canvas.width,     h=Math.random()*canvas.height;
      var x=Math.random()*(canvas.width-w), y=Math.random()*(canvas.height-h);
      ctx.fillRect(x,y,w,h);
    },1000/15);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Context: There's an application where you draw things on canvas. Where user clicks there's
I have a view inflated, I can draw it on canvas, but can't seem
I have to draw a lot of Shape (about 1/2 hundred thousand) as [Canvas][2]'s
i have a JavaScript project (using jquery), inside it i draw a canvas by
I draw picture in canvas in place where I click. This is code: public
I am trying to draw over a canvas by clicking and dragging the mouse.
How can i draw text on canvas as shown in below image highlighted in
If I define a canvas and draw few shapes onto it, then how can
I want to draw text on canvas., how to do it any sample example?
I am creating a web application using HTML5 canvas to draw images ( like

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.