Helion Bestsellery

OSINT w praktyce. Jak gromadzić i analizować dane dostępne w sieci
  • Autor: Dale Meredith
  • Zniżka: 40%
  • Cena: 67.00 40.20 zł
  • Marka: Helion
  • Status: Dostępna
  • Typ: Książka
  • EAN: 9788328920422
  • ISBN: 978-83-289-2042-2
Dodaj OSINT w praktyce. Jak gromadzić i analizować dane dostępne w sieci do koszyka

Helion Książka Dnia

Superinteligencja. Scenariusze, strategie, zagrożenia
  • Autor: Nick Bostrom
  • Zniżka: 50%
  • Cena: 69.00 34.50 zł
  • Marka: Helion
  • Status: Dostępna
  • Typ: Książka
  • EAN: 9788328903272
  • ISBN: 978-83-289-0327-2
Dodaj Superinteligencja. Scenariusze, strategie, zagrożenia do koszyka

rotate()

[ Leksykon ] [ JavaScript ] [ Metody ] [ Właściwości ] [ canvas ] [ CanvasRenderingContext2D ]

CanvasRenderingContext2D.rotate()

[_] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z]

rotate(angle)

 

Przykłady:

<script>

window.onload = () => {

const szer = 600;
const wys = 600;

const canvas = document.getElementById("canvas");
canvas.width = szer;
canvas.height = wys;
const ctx = canvas.getContext("2d");

ctx.arc(0, 0, 10, 0, 2 * Math.PI);
ctx.fillStyle = "black";
ctx.fill();

ctx.fillStyle = "orange";
ctx.fillRect(300, 50, 25, 25);
ctx.fillStyle = "yellow";
ctx.fillRect(300, 150, 25, 25);

ctx.rotate((45 * Math.PI) / 180);

ctx.fillStyle = "orange";
ctx.fillRect(300, 50, 25, 25);
ctx.fillStyle = "yellow";
ctx.fillRect(300, 150, 25, 25);

ctx.setTransform(1, 0, 0, 1, 0, 0);

ctx.fillStyle = "orange";
ctx.fillRect(350, 50, 25, 25);
ctx.fillStyle = "yellow";
ctx.fillRect(350, 150, 25, 25);

ctx.translate(425, 75);
ctx.rotate((45 * Math.PI) / 180);
ctx.translate(-425, -75);
ctx.fillStyle = "orange";
ctx.fillRect(400, 50, 25, 25);

ctx.setTransform(1, 0, 0, 1, 0, 0);

ctx.translate(425, 175);
ctx.rotate((45 * Math.PI) / 180);
ctx.translate(-425, -175);
ctx.fillStyle = "yellow";
ctx.fillRect(400, 150, 25, 25);

return;

};

</script>

<canvas id="canvas" width="100" height="100"></canvas>

 

  

Opis:
Metoda CanvasRenderingContext2D.rotate() dodaje obrót do macierzy transformacji. Parametry angle - kąt obrotu, zgodnie z ruchem wskazówek zegara, w radianach, można użyć degree * Math.PI / 180 do obliczenia radiana na podstawie stopnia. Środkowym punktem obrotu jest zawsze początek płótna x = 0, y = 0. Aby zmienić punkt środkowy, należy przesunąć płótno za pomocą metody translate().

Zobacz też:
translate()

 

 

 

 

 

Please publish modules in offcanvas position.