Skip to content

Commit c542dd6

Browse files
Add white to black transition
1 parent 0a178fe commit c542dd6

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<meta http-equiv="X-UA-Compatible" content="IE=edge">
77
<meta name="viewport" content="width=device-width, initial-scale=1.0">
88
<title>Etch a sketch</title>
9+
<link href="https://fonts.googleapis.com/css2?family=Roboto&amp;display=swap" rel="stylesheet">
910
<link rel="stylesheet" href="style.css">
1011
</head>
1112

main.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,32 @@ const button = document.getElementById("resolution");
33

44
const gridWidth = 960;
55

6-
var random = function(number) {
6+
function random(number) {
77
// random number from 0 to number
88
return Math.floor(Math.random() * (number + 1));
99
}
1010

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-
1611

1712
var drawCanvas = function(boxesPerSide) {
1813
for (let i = 1; i <= boxesPerSide; i++) {
1914
for (let j = 1; j <= boxesPerSide; j++) {
2015
const box = document.createElement("div");
2116
box.classList.add("col" + j.toString());
2217
box.classList.add("row" + i.toString());
18+
box.classList.add("l100");
19+
2320
boxGrid.appendChild(box);
2421

2522
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}%)`;
2732
});
2833
}
2934
}
@@ -41,7 +46,7 @@ var clearCanvas = function() {
4146
var askResolution = () => {
4247
const res = prompt("Enter resolution size", "10");
4348
if (res === null) return;
44-
if (res >= 100) {
49+
if (res > 100) {
4550
alert("Number too big, max: 100");
4651
askResolution();
4752
return;

style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
body {
22
margin: 0;
3-
font-family: 'Open Sans', 'Helvetica Neue', sans-serif;
3+
font-family: 'Roboto', 'Open Sans', sans-serif;
44
}
55

66
#boxgrid div {

0 commit comments

Comments
 (0)