Created
October 17, 2019 10:15
-
-
Save subzey/44ba0a1aaf05bbce396556524798842a to your computer and use it in GitHub Desktop.
stroke vs fill lines
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.moveTo(x, y - 6); | |
c.lineTo(x, y + 6) | |
c.lineWidth = 2; | |
c.strokeStyle = 'black'; | |
c.stroke(); | |
} | |
function drawWithFills(c, x, y) { | |
c.fillStyle ='black'; | |
c.fillRect(x - 1, y - 6, 2, 12); | |
} | |
function frame(now){ | |
const shift = (now / 70 + Math.cos(now / 500) * 10) % 14; | |
c.canvas.width |= 0; | |
const drawingFunction = (useStrokesEl.checked | |
? drawWithStrokes | |
: drawWithFills | |
); | |
for (let x = -4; x < 804; x += 4) { | |
for (let y = -14; y < 614; y += 14) { | |
drawingFunction(c, x, 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