File tree 2 files changed +27
-1
lines changed
08 - Fun with HTML5 Canvas
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 14
14
margin : 0 ;
15
15
}
16
16
</ 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 ;
17
28
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 >
18
44
</ body >
19
45
</ html >
Original file line number Diff line number Diff line change 11
11
5 . [x] ~~ Flex Panel Gallery~~
12
12
6 . [x] ~~ Type Ahead~~
13
13
7 . [x] ~~ Array Cardio, Day 2~~
14
- 8 . [ ] Fun with HTML5 Canvas
14
+ 8 . [x] ~~ Fun with HTML5 Canvas~~
15
15
9 . [ ] Dev Tools Domination
16
16
10 . [ ] Hold Shift and Check Checkboxes
17
17
11 . [ ] Custom Video Player
You can’t perform that action at this time.
0 commit comments