Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

277
Views
Canvas ctx.rotate() with very small angles (less than 0.014) not working on Chrome, Edge

I just realized that Chrome (Edge too) does not perform canvas rotations ctx.rotate() if the angle is under 0.014 degrees. It works fine on Firefox (Windows 10).

Any ideas for a workaround? I am using 0.01 degrees in my design. Using bigger angles is not an option as it changes the design.

const canvas = document.querySelector('canvas'), ctx = canvas.getContext('2d');

let cw = canvas.width = canvas.height = 600;
ctx.fillStyle = '#000000'; ctx.fillRect(0, 0, cw, cw);

let angle = 0.01;       

for (let i = 1; i <= 5000; i++) {
  ctx.translate(cw / 2, cw / 2); ctx.rotate(angle * Math.PI / 180); ctx.translate(-cw / 2, -cw / 2);

  ctx.beginPath();
  ctx.moveTo(100, 200);
  ctx.lineTo(500, 200);
  ctx.lineWidth = 10;
  ctx.strokeStyle = '#FFFFFF';
  ctx.stroke();
}
<canvas></canvas>

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

That's a very weird bug that I did report thanks to you.
For the time being, a very quick workaround is to use a DOMMatrix to set the transform, this API doesn't seem to be affected by this bug.

const canvas = document.querySelector('canvas'), ctx = canvas.getContext('2d');

let cw = canvas.width = canvas.height = 600;
ctx.fillStyle = '#000000'; ctx.fillRect(0, 0, cw, cw);

let angle = 0.01;       
const mat = new DOMMatrix();
for (let i = 1; i <= 5000; i++) {
  mat.translateSelf(cw / 2, cw / 2);
  mat.rotateSelf(angle); // DOMMatrix.rotate is in angle...
  mat.translateSelf(-cw / 2, -cw / 2);
  ctx.setTransform(mat);
  
  ctx.beginPath();
  ctx.moveTo(100, 200);
  ctx.lineTo(500, 200);
  ctx.lineWidth = 10;
  ctx.strokeStyle = '#FFFFFF';
  ctx.stroke();
}
<canvas></canvas>

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!