Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

281
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda