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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:41:29+00:00 2026-05-28T06:41:29+00:00

Come see the amazing disappearing rectangle! But seriously I have a really simple HTML5

  • 0

Come see the amazing disappearing rectangle!

But seriously I have a really simple HTML5 canvas that just draws a rectangle(using lineTo instead of rect for a reason).

My Problem: I am attempting to rotate the rectangle 90 degrees. The rectangle should be rotated 90 degrees but instead it disappears.

In my webapp project I am getting weird x,y placement errors when I rotate my complex polygons in HTML5 canvas’, so I have created this simple HTML to test rotation & ensure its rotating around its x,y point of 100,100. But even this has weird results when I attempt to rotate a shape.

Can anyone tell me how to get my rectangle visible & how I can rotate my polygons around a specific point without them completely changing x,y values.

Has anyone experienced this issue with HTML5 canvas’ & know solutions to fix this?

<canvas id="testCanvas" width="900px" height="900px" style="background-color: blue;">

</canvas>
<script type="text/javascript">

    var canvas = document.getElementById("testCanvas");
    var dc     = canvas.getContext("2d");

    dc.clearRect(0, 0, canvas.width, canvas.height);

    dc.save();
    dc.fillStyle = "#FF0000";

    dc.rotate( 90*Math.PI/180 );  // rotate 90 degrees
    dc.beginPath();
    dc.moveTo(100, 100);
    dc.lineTo(200, 100);
    dc.lineTo(200,300);
    dc.lineTo(100,300);
    dc.closePath();
    dc.fill();

    dc.restore();
-->
</script>
  • 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-28T06:41:30+00:00Added an answer on May 28, 2026 at 6:41 am

    To rotate around a point you need to do 3 steps.

    • First translate the context to the center you wish to rotate around.
    • Then do the actual rotation.
    • Then translate the context back.

    Like this:

    var canvas = document.getElementById("testCanvas");
    var dc     = canvas.getContext("2d");
    var angle = 0;
    window.setInterval(function(){
        angle = (angle + 1) % 360;
        dc.clearRect(0, 0, canvas.width, canvas.height);
    
        dc.save();
        dc.fillStyle = "#FF0000";
    
        dc.translate(150,200); // First translate the context to the center you wish to rotate around.
        dc.rotate( angle*Math.PI/180 ); // Then do the actual rotation.
        dc.translate(-150,-200); // Then translate the context back.
    
        dc.beginPath();
        dc.moveTo(100, 100);
        dc.lineTo(200, 100);
        dc.lineTo(200,300);
        dc.lineTo(100,300);
        dc.closePath();
        dc.fill();
    
        dc.restore();
    }, 5);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have come across a problem that I cannot see to solve. I have
I have come to see an Installer class item in Visual studio. Why they
Where do the type/member/parameter descriptions that you see in the Intellisense bubble come from?
I'd like to see the colors and formatting that can come with var_dump. In
I have come across Adobe MXML that looks very similar to Microsoft's XAML. Who
I saw the following in some code (see below). Have not come across the
I see that some apps on the market come as a Free version, and
I want to see all the different ways you can come up with, for
How come unserialize isn't restoring my array? See code below.. // prints a:1:{s:8:txn_type;s:32:recurring_payment_profile_cancel;} echo
Come across what looks at first sight like an MT-issue, but I'm trying to

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.