Created
October 17, 2019 09:41
-
-
Save subzey/28fa8ca132015e6b15e81d7140d0a129 to your computer and use it in GitHub Desktop.
fills vs. strokes
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<canvas id="a" width="800" height="600"></canvas> | |
<p> | |
<label><input type="checkbox" id="strokes"> Draw with strokes </label> | |
</p> | |
<script> | |
const c = document.getElementById('a').getContext('2d'); | |
const useStrokesEl = document.getElementById('strokes'); | |
function drawWithStrokes(c, x, y) { | |
c.beginPath(); | |
c.arc(x, y, 6, 0, 2 * Math.PI); | |
c.closePath(); | |
c.fillStyle = 'blue'; | |
c.fill(); | |
c.lineWidth = 2; | |
c.strokeStyle = 'black'; | |
c.stroke(); | |
} | |
function drawWithFills(c, x, y) { | |
c.beginPath(); | |
c.arc(x, y, 7, 0, 2 * Math.PI); | |
c.fillStyle ='black'; | |
c.fill(); | |
c.beginPath(); | |
c.arc(x, y, 5, 0, 2 * Math.PI); | |
c.fillStyle ='blue'; | |
c.fill(); | |
} | |
function frame(now){ | |
const shift = (now / 100) % 14; | |
c.canvas.width |= 0; | |
const drawingFunction = (useStrokesEl.checked | |
? drawWithStrokes | |
: drawWithFills | |
); | |
for (let x = -14; x < 814; x += 14) { | |
for (let y = -14; y < 614; y += 14) { | |
drawingFunction(c, x + shift, y + shift); | |
} | |
} | |
requestAnimationFrame(frame); | |
} | |
requestAnimationFrame(frame); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment