Skip to content

Commit de5d901

Browse files
authored
Merge pull request #727 from AckermanLevi1/RandomColorPaletteGenerator-AckermanLevi1
Random color palette generator ackerman levi1
2 parents eea52f3 + c9b0d27 commit de5d901

File tree

1 file changed

+94
-0
lines changed
  • RandomColorPaletteGenerator/AckermanLevi1

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Random Color Palette Generator</title>
7+
<style>
8+
body {
9+
display: flex;
10+
flex-direction: column;
11+
justify-content: center;
12+
align-items: center;
13+
height: 100vh;
14+
margin: 0;
15+
background-color: #f0f0f0;
16+
}
17+
18+
#colorPalette {
19+
display: flex;
20+
flex-direction: column;
21+
align-items: center;
22+
margin-top: 20px;
23+
}
24+
25+
.colorBox {
26+
width: 100px;
27+
height: 100px;
28+
margin: 10px;
29+
border: 2px solid #333;
30+
}
31+
32+
.colorCode {
33+
font-size: 16px;
34+
}
35+
36+
.heading {
37+
font-size: 24px;
38+
font-weight: bold;
39+
}
40+
41+
.instructions {
42+
font-size: 18px;
43+
}
44+
</style>
45+
</head>
46+
<body>
47+
<br>
48+
<br>
49+
<div class="heading">Random Color Palette Generator</div>
50+
<div class="instructions">Hit space bar to change color</div>
51+
52+
<div id="colorPalette">
53+
<!-- Color boxes with hex codes will be added here -->
54+
</div>
55+
56+
<script>
57+
function getRandomColor() {
58+
const letters = "0123456789ABCDEF";
59+
let color = "#";
60+
for (let i = 0; i < 6; i++) {
61+
color += letters[Math.floor(Math.random() * 16)];
62+
}
63+
return color;
64+
}
65+
66+
function generateRandomPalette() {
67+
const colorPalette = document.getElementById("colorPalette");
68+
colorPalette.innerHTML = '';
69+
70+
for (let i = 0; i < 5; i++) {
71+
const colorBox = document.createElement("div");
72+
colorBox.className = "colorBox";
73+
const color = getRandomColor();
74+
colorBox.style.backgroundColor = color;
75+
colorPalette.appendChild(colorBox);
76+
77+
const colorCode = document.createElement("div");
78+
colorCode.className = "colorCode";
79+
colorCode.textContent = color;
80+
colorPalette.appendChild(colorCode);
81+
}
82+
}
83+
84+
document.body.addEventListener("keydown", function (event) {
85+
if (event.code === "Space") {
86+
generateRandomPalette();
87+
}
88+
});
89+
90+
// Initial generation
91+
generateRandomPalette();
92+
</script>
93+
</body>
94+
</html>

0 commit comments

Comments
 (0)