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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:44:44+00:00 2026-05-27T19:44:44+00:00

So I was under the impression that rendering designs on the HTML5 canvas would

  • 0

So I was under the impression that rendering designs on the HTML5 canvas would be quite fast. I’m using the following code and I would think it would take less than a second to render, but it takes about 2 minutes total.

Code:

 <script>
var canvas = document.getElementById("canvas")
    ctx = canvas.getContext('2d')
    maxW = window.innerWidth
    maxH = window.innerHeight
    x = -1
    numLeft = 15

//maxW = 300
//maxH = 300
canvas.setAttribute("width", maxW)
canvas.setAttribute("height", maxH)
ctx.fillStyle = "rgba(0,0,0,.5)"

for(var j = 0; j < maxH; j++){
  for(var i = 0; i < maxW; i++){
    if(numLeft < 0){
      if(x == -1){
        ctx.fillStyle = "rgba(127,127,127,.5)"
        //numLeft += 12
        numLeft += 5
      }
      else{
        ctx.fillStyle = "rgba(0,0,0,.5)"
        //numLeft += 24
        numLeft += 15
      }
      x *= -1
    }
    ctx.fillRect(i,j,i+1,j+1)
    numLeft--
  }
  //numLeft -= 5 this one's crazy :D
  numLeft -= 3
}

It’s supposed to draw diagonal stripes in black and grey. But again, it’s taking forever to render and would crash most people’s browsers. Any hints as to how to speed this up?

  • 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-27T19:44:45+00:00Added an answer on May 27, 2026 at 7:44 pm

    Since comments can’t be accepted as answers as far as I know, I’m posting @pimvdb comment as an answer. The problem was the way fillRect() was being called, it was being called as if the all the parameters were coordinates (x, y, x2, y2) when in fact the parameters were a combination of coordinates and dimension (x, y, w, h).

    I confirmed that this was a major performance problem in your code with with this jsFiddle.

    As mentioned there are other performance improvements you can make like pre-rendering and using line gradients but this addresses the immediate performance problem. In my test on Chrome performance went from 6 seconds to less than one.

    Have you tried the performance suggests on html5rocks.com?

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

Sidebar

Related Questions

I was under the impression that using the Resolve method returned a new instance
I was under the impression that if I deployed my application (using Ant) then
I was under the impression that this code #include <windows.h> #include <stdio.h> int WINAPI
I was under the impression that using an annotation like this: <Required()> <DisplayName(Choose a
I was under the impression that using setjmp() and longjmp() in C++ was almost
I was under impression that in F# the following two lines are supposed to
I was under the impression that not calling Response.Flush would ensure that Connection: Close
I was under the impression that specialization composes, but in the following example that
I was under the impression that a tag would act like a commit in
I was under the impression that if you put a line of code 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.