svgcanvas/test/tests/rotate.js

16 lines
431 B
JavaScript
Raw Normal View History

2021-06-04 22:54:18 +08:00
// Example from https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/rotate
2021-06-10 20:39:09 +08:00
export default function rotate(ctx) {
2021-06-04 22:54:18 +08:00
ctx.fillStyle = 'gray';
ctx.fillRect(80, 60, 140, 30);
// Matrix transformation
ctx.translate(150, 75);
ctx.rotate(Math.PI / 2);
ctx.translate(-150, -75);
// Rotated rectangle
ctx.fillStyle = 'red';
ctx.fillRect(80, 60, 140, 30);
2021-06-04 23:49:08 +08:00
ctx.resetTransform();
2021-06-04 22:54:18 +08:00
}