File tree Expand file tree Collapse file tree
08 - Fun with HTML5 Canvas Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 11115 . [x] ~~ Flex Panel Gallery~~
12126 . [x] ~~ Type Ahead~~
13137 . [x] ~~ Array Cardio, Day 2~~
14- 8 . [ ] Fun with HTML5 Canvas
14+ 8 . [x] ~~ Fun with HTML5 Canvas~~
15159 . [ ] Dev Tools Domination
161610 . [ ] Hold Shift and Check Checkboxes
171711 . [ ] Custom Video Player
You can’t perform that action at this time.
0 commit comments