Skip to content

Commit c52b83f

Browse files
author
Jin Xu
committed
course wesbos#8 finished
1 parent bd8ee13 commit c52b83f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

08 - Fun with HTML5 Canvas/index-START.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,32 @@
1414
margin:0;
1515
}
1616
</style>
17+
<script>
18+
let isDrawing = false;
19+
const canvas = document.querySelector('#draw');
20+
const ctx = canvas.getContext('2d');
21+
ctx.lineJoin = 'round';
22+
ctx.lineCap = 'round';
23+
24+
let draw = e => {
25+
if(e.type === 'mousedown') isDrawing = true;
26+
if(!isDrawing) return;
27+
isDrawing = true;
1728

29+
let hue = Math.floor(Math.random() * 360 + 1);
30+
ctx.lineWidth = Math.floor(Math.random() * 60 + 1);
31+
32+
ctx.strokeStyle = `hsl(${hue}, 100%, 50%)`;
33+
ctx.beginPath();
34+
ctx.lineTo(e.offsetX, e.offsetY);
35+
ctx.stroke();
36+
}
37+
38+
canvas.addEventListener('mousedown', draw);
39+
canvas.addEventListener('mousemove', draw);
40+
canvas.addEventListener('mouseup', () => isDrawing = false);
41+
canvas.addEventListener('mouseout', () => isDrawing = false);
42+
43+
</script>
1844
</body>
1945
</html>

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
5. [x] ~~Flex Panel Gallery~~
1212
6. [x] ~~Type Ahead~~
1313
7. [x] ~~Array Cardio, Day 2~~
14-
8. [ ] Fun with HTML5 Canvas
14+
8. [x] ~~Fun with HTML5 Canvas~~
1515
9. [ ] Dev Tools Domination
1616
10. [ ] Hold Shift and Check Checkboxes
1717
11. [ ] Custom Video Player

0 commit comments

Comments
 (0)