File tree 1 file changed +10
-1
lines changed
1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 2
2
const DEFAULT_SIZE = 16 ;
3
3
const DEFAULT_COLOR = '#000000' ;
4
4
5
+ // List of variables
6
+ let currentColor = DEFAULT_COLOR ;
7
+
5
8
// Create a grid of squares on the canvas
6
9
const canvas = document . querySelector ( '.canvas' ) ;
7
10
function createGrid ( size ) {
@@ -32,7 +35,7 @@ canvas.addEventListener('mousedown', (e) => {
32
35
canvas . addEventListener ( 'mousemove' , ( e ) => {
33
36
console . log ( e ) ;
34
37
if ( e . buttons === 1 && e . target . classList . contains ( 'square' ) ) {
35
- e . target . style . backgroundColor = DEFAULT_COLOR ;
38
+ e . target . style . backgroundColor = currentColor ;
36
39
}
37
40
} ) ;
38
41
@@ -45,4 +48,10 @@ resetButton.addEventListener('click', () => {
45
48
} ) ;
46
49
} ) ;
47
50
51
+ // Update the current color when the color picker is changed
52
+ const colorPicker = document . querySelector ( '#colorPicker' ) ;
53
+ colorPicker . addEventListener ( 'change' , ( ) => {
54
+ currentColor = colorPicker . value ;
55
+ } ) ;
56
+
48
57
createGrid ( DEFAULT_SIZE ) ;
You can’t perform that action at this time.
0 commit comments