Skip to content

Commit e02189a

Browse files
authored
Merge pull request #797 from HarshitVashisht11/codespace-miniature-computing-machine-w657jvxgqxwhv94
Created Random Collor Palette Generator
2 parents 2722ebc + 22d3891 commit e02189a

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Random Color Palette Generator
2+
3+
screenshot:
4+
5+
![Alt text](<Screenshot (113).png>)
38.4 KB
Loading
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
<link rel="stylesheet" href="style.css">
7+
<title>Random Color Palette Generator</title>
8+
</head>
9+
<body>
10+
<div class="palette">
11+
<!-- Color cards will be added dynamically here -->
12+
</div>
13+
<button id="generateButton">Generate Colors</button>
14+
<script src="script.js"></script>
15+
</body>
16+
</html>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const palette = document.querySelector('.palette');
2+
const generateButton = document.getElementById('generateButton');
3+
4+
function getRandomColor() {
5+
const letters = '0123456789ABCDEF';
6+
let color = '#';
7+
for (let i = 0; i < 6; i++) {
8+
color += letters[Math.floor(Math.random() * 16)];
9+
}
10+
return color;
11+
}
12+
13+
function createColorCard() {
14+
const colorCard = document.createElement('div');
15+
colorCard.classList.add('color-card');
16+
const hexCode = getRandomColor();
17+
colorCard.style.backgroundColor = hexCode;
18+
colorCard.innerHTML = `
19+
<div class="hex-code">${hexCode}</div>
20+
`;
21+
palette.appendChild(colorCard);
22+
23+
colorCard.addEventListener('click', () => {
24+
const tempInput = document.createElement('input');
25+
tempInput.value = hexCode;
26+
document.body.appendChild(tempInput);
27+
tempInput.select();
28+
document.execCommand('copy');
29+
document.body.removeChild(tempInput);
30+
alert(`Hex code ${hexCode} copied to clipboard!`);
31+
});
32+
}
33+
34+
function generatePalette(numColors) {
35+
palette.innerHTML = '';
36+
for (let i = 0; i < numColors; i++) {
37+
createColorCard();
38+
}
39+
}
40+
41+
generateButton.addEventListener('click', () => {
42+
const numColors = Math.floor(Math.random() * 4 + 1) * 2 * 2; // 10, 12, 14, or 16 colors
43+
generatePalette(numColors);
44+
});
45+
46+
generatePalette(10);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
body {
2+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
3+
text-align: center;
4+
display: flex;
5+
flex-direction: column;
6+
align-items: center;
7+
justify-content: center;
8+
height: 100vh;
9+
margin: 0;
10+
}
11+
12+
.palette {
13+
display: flex;
14+
flex-wrap: wrap;
15+
justify-content: center;
16+
gap: 10px;
17+
}
18+
19+
.color-card {
20+
width: 100px;
21+
height: 100px;
22+
border: 2px solid #000;
23+
text-align: center;
24+
display: flex;
25+
flex-direction: column;
26+
justify-content: center;
27+
}
28+
29+
.hex-code {
30+
font-size: 16px;
31+
}
32+
33+
#generateButton {
34+
margin-top: 20px;
35+
padding: 10px 20px;
36+
font-size: 18px;
37+
}

0 commit comments

Comments
 (0)