Skip to content

Add Color Palette Generator App with Random Color Generation, Lock, and Copy Features #1090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Public/color-palette-generator.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Color Palette Generator</title>
<link rel="stylesheet" href="../assets/css/color-palette-generator.css">
</head>
<body>
<div class="palette-container">
<div class="color-box" id="color1">
<span class="hex-code" id="hex1">#FFFFFF</span>
<button class="lock-btn" onclick="toggleLock(1)">🔓</button>
<button class="copy-btn" onclick="copyToClipboard(1)">📋</button>
</div>
<div class="color-box" id="color2">
<span class="hex-code" id="hex2">#FFFFFF</span>
<button class="lock-btn" onclick="toggleLock(2)">🔓</button>
<button class="copy-btn" onclick="copyToClipboard(2)">📋</button>
</div>
<div class="color-box" id="color3">
<span class="hex-code" id="hex3">#FFFFFF</span>
<button class="lock-btn" onclick="toggleLock(3)">🔓</button>
<button class="copy-btn" onclick="copyToClipboard(3)">📋</button>
</div>
<div class="color-box" id="color4">
<span class="hex-code" id="hex4">#FFFFFF</span>
<button class="lock-btn" onclick="toggleLock(4)">🔓</button>
<button class="copy-btn" onclick="copyToClipboard(4)">📋</button>
</div>
<div class="color-box" id="color5">
<span class="hex-code" id="hex5">#FFFFFF</span>
<button class="lock-btn" onclick="toggleLock(5)">🔓</button>
<button class="copy-btn" onclick="copyToClipboard(5)">📋</button>
</div>
</div>
<div class="controls">
<button id="generateBtn" onclick="generateColors()">Generate Palette</button>
</div>
<script src="../assets/Js/color-palette-generator.js"></script>
</body>
</html>
40 changes: 40 additions & 0 deletions assets/Js/color-palette-generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
let lockedColors = [false, false, false, false, false];

// Generate random color in hex format
function generateRandomColor() {
const hexChars = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += hexChars[Math.floor(Math.random() * 16)];
}
return color;
}

// Update the color of each box
function generateColors() {
for (let i = 1; i <= 5; i++) {
if (!lockedColors[i - 1]) {
const color = generateRandomColor();
document.getElementById(`color${i}`).style.backgroundColor = color;
document.getElementById(`hex${i}`).innerText = color;
}
}
}

// Toggle lock for color
function toggleLock(index) {
lockedColors[index - 1] = !lockedColors[index - 1];
const lockBtn = document.querySelector(`#color${index} .lock-btn`);
lockBtn.innerText = lockedColors[index - 1] ? '🔒' : '🔓';
}

// Copy color to clipboard
function copyToClipboard(index) {
const colorCode = document.getElementById(`hex${index}`).innerText;
navigator.clipboard.writeText(colorCode).then(() => {
alert(`Copied: ${colorCode}`);
});
}

// Initialize with a random palette
window.onload = generateColors;
77 changes: 77 additions & 0 deletions assets/css/color-palette-generator.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #0c0303;
}

.palette-container {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 20px;
}

.color-box {
width: 150px;
height: 150px;
margin: 10px;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
border-radius: 10px;
position: relative;
color: white;
font-weight: bold;
text-transform: uppercase;
}

.color-box .hex-code {
font-size: 18px;
margin-top: 15px;
}

.lock-btn, .copy-btn {
background: transparent;
border: none;
color: white;
cursor: pointer;
font-size: 20px;
margin: 5px;
}

.controls {
margin-top: 20px;
}

#generateBtn {
padding: 10px 20px;
background-color: #333;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 18px;
}

#generateBtn:hover {
background-color: #555;
}


@media screen and (max_width: 600px) {
.palette-container {
flex-direction: column;

}
}