Created
November 12, 2024 20:22
-
-
Save greggman/875a015fc080586923a33695bff0299f to your computer and use it in GitHub Desktop.
Canvas 2D: Test stroke with color vs stroke with pattern
This file contains 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
/*bug-in-github-api-content-can-not-be-empty*/ |
This file contains 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 width="64" height="64" style=" | |
width: 512px; | |
height: 512px; | |
image-rendering: pixelated; | |
image-rendering: crisp-edges; | |
"></canvas> |
This file contains 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'); | |
const patternCanvas = document.createElement('canvas'); | |
patternCanvas.width = 1; | |
patternCanvas.height = 1; | |
const pCtx = patternCanvas.getContext('2d'); | |
pCtx.fillStyle = '#00F'; | |
pCtx.fillRect(0, 0, 1, 1); | |
const pattern = ctx.createPattern(patternCanvas, 'repeat'); | |
ctx.beginPath(); | |
ctx.arc(16, 16, 12, 0, Math.PI * 2); | |
ctx.strokeStyle = '#F00'; | |
ctx.stroke(); | |
ctx.beginPath(); | |
ctx.arc(48, 48, 12, 0, Math.PI * 2); | |
ctx.strokeStyle = pattern; | |
ctx.stroke(); | |
This file contains 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: Test stroke with color vs stroke with pattern","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