File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- // Get canvas element and set its dimensions to the size of the screen
21var canvas = document . getElementById ( "canvas" ) ;
32const colorPicker = document . getElementById ( "color-picker" ) ;
43const saveButton = document . getElementById ( "save-button" ) ;
@@ -110,16 +109,12 @@ canvas.addEventListener('touchend', function () {
110109 ctx . stroke ( ) ;
111110 }
112111} ) ;
113- canvas . addEventListener ( 'touchmove ' , function ( e ) {
114- if ( drawing ) {
115- // Draw a line from the last coordinates to the current ones
112+ canvas . addEventListener ( 'touchend ' , function ( e ) {
113+ drawing = false ;
114+ if ( currentTool == " line" ) {
116115 ctx . beginPath ( ) ;
117- ctx . moveTo ( lastX , lastY ) ;
118- ctx . lineTo ( e . touches [ 0 ] . pageX , e . touches [ 0 ] . pageY ) ;
116+ ctx . moveTo ( lineStart . x , lineStart . y ) ;
117+ ctx . lineTo ( e . touches [ 0 ] . pageX - canvas . offsetLeft , e . touches [ 0 ] . pageY - canvas . offsetTop ) ;
119118 ctx . stroke ( ) ;
120-
121- // Update last coordinates
122- lastX = e . touches [ 0 ] . pageX ;
123- lastY = e . touches [ 0 ] . pageY ;
124119 }
125120} ) ;
You can’t perform that action at this time.
0 commit comments