File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
08 - Fun with HTML5 Canvas Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 77< body >
88< canvas id ="draw " width ="800 " height ="800 "> </ canvas >
99< script >
10+ const canvas = document . querySelector ( '#draw' ) ;
11+ const ctx = canvas . getContext ( '2d' ) ;
12+ canvas . width = window . innerWidth ;
13+ canvas . height = window . innerHeight ;
14+ ctx . strokeStyle = '#BADA55' ;
15+ ctx . lineJoin = 'round' ;
16+ ctx . lineCap = 'round' ;
17+
18+ let isDrawing = false ;
19+ let lastX = 0 ;
20+ let lastY = 0 ;
21+
22+ function draw ( e ) {
23+ if ( ! isDrawing ) return ; // stop the function from running when they are not moused down
24+ console . log ( e ) ;
25+ } ;
26+
27+ canvas . addEventListener ( 'mousemove' , draw ) ;
28+ canvas . addEventListener ( 'mousedown' , ( ) => isDrawing = true ) ;
29+ canvas . addEventListener ( 'mouseup' , ( ) => isDrawing = false ) ;
30+ canvas . addEventListener ( 'mouseout' , ( ) => isDrawing = false ) ;
1031</ script >
1132
1233< style >
You can’t perform that action at this time.
0 commit comments