@@ -3,27 +3,32 @@ const button = document.getElementById("resolution");
3
3
4
4
const gridWidth = 960 ;
5
5
6
- var random = function ( number ) {
6
+ function random ( number ) {
7
7
// random number from 0 to number
8
8
return Math . floor ( Math . random ( ) * ( number + 1 ) ) ;
9
9
}
10
10
11
- // var random = function(low, high) {
12
- // // random number from low to high
13
- // return Math.floor(Math.random() * (high - low + 1)) + low;
14
- // }
15
-
16
11
17
12
var drawCanvas = function ( boxesPerSide ) {
18
13
for ( let i = 1 ; i <= boxesPerSide ; i ++ ) {
19
14
for ( let j = 1 ; j <= boxesPerSide ; j ++ ) {
20
15
const box = document . createElement ( "div" ) ;
21
16
box . classList . add ( "col" + j . toString ( ) ) ;
22
17
box . classList . add ( "row" + i . toString ( ) ) ;
18
+ box . classList . add ( "l100" ) ;
19
+
23
20
boxGrid . appendChild ( box ) ;
24
21
25
22
box . addEventListener ( "mouseenter" , ( ) => {
26
- box . style . backgroundColor = `hsl(${ random ( 360 ) } , ${ random ( 100 ) } %, ${ random ( 100 ) } %)` ;
23
+ let className = String ( box . classList ) ;
24
+ let lightness = + className . slice ( className . lastIndexOf ( "l" ) + 1 , className . length ) ;
25
+ if ( lightness > 0 ) {
26
+ box . classList . remove ( `l${ lightness } ` ) ;
27
+ lightness -= 10 ;
28
+ box . classList . add ( `l${ lightness } ` ) ;
29
+ }
30
+ // box.style.backgroundColor = `hsl(${random(360)}, ${random(100)}%, ${random(100)}%)`;
31
+ box . style . backgroundColor = `hsl(0, 0%, ${ lightness } %)` ;
27
32
} ) ;
28
33
}
29
34
}
@@ -41,7 +46,7 @@ var clearCanvas = function() {
41
46
var askResolution = ( ) => {
42
47
const res = prompt ( "Enter resolution size" , "10" ) ;
43
48
if ( res === null ) return ;
44
- if ( res >= 100 ) {
49
+ if ( res > 100 ) {
45
50
alert ( "Number too big, max: 100" ) ;
46
51
askResolution ( ) ;
47
52
return ;
0 commit comments