Created
April 19, 2025 06:44
-
-
Save greggman/6e638063dc0c7f409714743a188a53b0 to your computer and use it in GitHub Desktop.
Canvas 2D Matrix Math
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
canvas { | |
background-color: #888; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<canvas></canvas> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ctx = document.querySelector('canvas').getContext('2d'); | |
// Canvas 2d starts with CSS pixel space so we don't need to transform to clip space | |
ctx.translate(25, 25); | |
ctx.rotate(45 * Math.PI / 180); | |
ctx.translate(-25, -25); | |
ctx.fillRect(0, 0, 50, 50); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"name":"Canvas 2D Matrix Math","settings":{},"filenames":["index.html","index.css","index.js"]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment