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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:33:17+00:00 2026-06-13T08:33:17+00:00

I am simulating a page turn effect in html5 canvas. On each page I

  • 0

I am simulating a page turn effect in html5 canvas.

On each page I am drawing lines to simulate lined paper.

These lines are drawn as the page is turned and in order to give natural perspective I am drawing them using quadratic curves based of several factors (page turn progress, closeness to the center of the page etc.. etc…)

The effect is very natural and looks great but I am looking for ways to optimize this.

Currently I am drawing every line twice, once for the actual line and once for a tiny highlight 1px below this line. I am doing this like so:

// render lines (shadows)

          self.context.lineWidth = 0.35;

          var midpage = (self.PAGE_HEIGHT)/2;

          self.context.strokeStyle = 'rgba(0,0,0,1)';
          self.context.beginPath();

          for(i=3; i < 21; i++){
             var lineX = (self.PAGE_HEIGHT/22)*i;
             var curveX = (midpage - lineX) / (self.PAGE_HEIGHT);
             self.context.moveTo(foldX, lineX);                                       
             self.context.quadraticCurveTo(foldX, lineX + ((-verticalOutdent*4) * curveX), foldX - foldWidth - Math.abs(offset.x), lineX + ((-verticalOutdent*2) * curveX));

          }
          self.context.stroke();

 // render lines (highlights)
         self.context.strokeStyle = 'rgba(255,255,255,0.5)';
         self.context.beginPath();

         for(i=3; i < 21; i++){
              var lineX = (self.PAGE_HEIGHT/22)*i;
              var curveX = (midpage - lineX) / (self.PAGE_HEIGHT);
              self.context.moveTo(foldX, lineX+2);                                       
              self.context.quadraticCurveTo(foldX, lineX + ((-verticalOutdent*4) * curveX) + 1, foldX - foldWidth - Math.abs(offset.x), lineX + ((-verticalOutdent*2) * curveX) + 1);                                          
         }
         self.context.stroke();

As you can see I am opening a path, looping through each line, then drawing the path. Then I repeat the whole process for the ‘highlight’ lines.

Is there any way to combine both of these operations into a single loop without drawing each line individually within the loop which would actually be far more expensive?

This is a micro-optimization, I am well aware of this. However this project is a personal exercise for me in order to learn html5 canvas performance best practices/optimizations.

Thanks in advance for any suggestions/comments

  • 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-13T08:33:18+00:00Added an answer on June 13, 2026 at 8:33 am

    Paths can be stroked as many times as you like, they’re not cleared when you call .stroke(), so:

    1. create your path (as above)
    2. .stroke() it
    3. translate the context
    4. change the colours
    5. .stroke() it again

    EDIT tried this myself – it didn’t work – the second copy of the path didn’t notice the translation of the coordinate space 🙁

    It apparently would work if the path was created using new Path() as documented in the (draft) specification instead of the “current default path” but that doesn’t appear to be supported in Chrome yet.

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

Sidebar

Related Questions

Imagine you are simulating particle physics. You, then, have a position vector for each
I'm simulating some threading in a Windows Service, and the Thread.Start routine for each
Running some user-load tests with jmeter, and noticed that for each page load after
I would like to select text on the page by simulating a left mouse
What's the best way to go about simulating how a current page would render
I am going to start a new online trading simulation game. Server Page: A
I'm simulating a e-commerce platform, user registers and it can be a normal user(buys
I'm simulating a todo list where the textfield's value gets saved in the model
Possible Duplicate: Simulating group_concat MySQL function in MS SQL Server 2005? I have a
I'm writing a physics simulating program, and found after() useful. I once would 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.