Spaces:
Running

colors / index.html
Designer00m's picture
Make a color palette generator as follows -Common Features in Palette Generators: 1. **Color Selection**: - **Color Wheel**: Allows users to select colors based on traditional color theories. - **HEX/RGB/CMYK Input**: Users can input specific color values. 2. **Palette Generation Modes**: - **Analogous**: Generates colors that are next to each other on the color wheel. - **Complementary**: Generates colors that are opposite each other on the color wheel. - **Triadic**: Generates three colors that are evenly spaced. - **Tetradic**: Generates colors based on two complementary pairs. 3. **Random Generator**: - Provides an option to create random color palettes for inspiration. 4. **Predefined Palettes**: - Offers a selection of trending or popular palettes. 5. **Adjustment Tools**: - Allows users to adjust brightness, saturation, and luminosity of selected colors. 6. **Save and Export Options**: - **Download**: Users can download palettes in various formats (e.g., PNG, JSON). - **Image Export**: Creates a visual representation of the palette for use in presentations or design mockups. - **Cloud Save**: If the tool is web-based, it might offer user accounts to save palettes online. U 7. **Share Functionality**: - Allows for easy sharing on social media or direct links for collaboration. 8. **Preview Feature**: - Visualizes how selected colors work together in various application contexts (like web pages or graphics). 9. **Accessibility Features**: - Includes contrast checking to ensure colors are accessible for users with visual impairments. - Initial Deployment
e124a78 verified
Raw History Blame Contribute Delete
43.4 kB
<!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>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://kit.fontawesome.com/a076d05399.js" crossorigin="anonymous"></script>
<style>
.color-wheel {
width: 250px;
height: 250px;
border-radius: 50%;
background: conic-gradient(
red, yellow, lime, cyan, blue, magenta, red
);
position: relative;
cursor: crosshair;
}
.color-wheel::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 50%;
height: 50%;
border-radius: 50%;
background: white;
}
.color-picker {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
width: 100%;
height: 40px;
background: transparent;
cursor: pointer;
}
.color-picker::-webkit-color-swatch {
border-radius: 8px;
border: 2px solid #e5e7eb;
}
.color-picker::-moz-color-swatch {
border-radius: 8px;
border: 2px solid #e5e7eb;
}
.color-swatch {
transition: all 0.2s ease;
}
.color-swatch:hover {
transform: scale(1.05);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
.contrast-ratio {
font-size: 0.8rem;
padding: 0.2rem 0.4rem;
border-radius: 0.25rem;
}
.contrast-good {
background-color: #10b981;
color: white;
}
.contrast-fair {
background-color: #f59e0b;
color: black;
}
.contrast-poor {
background-color: #ef4444;
color: white;
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="container mx-auto px-4 py-8">
<header class="text-center mb-8">
<h1 class="text-4xl font-bold text-gray-800 mb-2">Color Palette Generator</h1>
<p class="text-gray-600">Create beautiful color schemes for your projects</p>
</header>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<!-- Color Selection Panel -->
<div class="bg-white rounded-xl shadow-md p-6 lg:col-span-1">
<h2 class="text-xl font-semibold mb-4 text-gray-800">Color Selection</h2>
<div class="mb-6">
<label class="block text-sm font-medium text-gray-700 mb-2">Base Color</label>
<div class="flex items-center space-x-4">
<input type="color" id="baseColor" value="#3b82f6" class="color-picker">
<input type="text" id="hexInput" value="#3b82f6" class="border rounded-md px-3 py-2 w-full">
</div>
</div>
<div class="mb-6">
<label class="block text-sm font-medium text-gray-700 mb-2">Color Wheel</label>
<div class="color-wheel mx-auto mb-4" id="colorWheel"></div>
<div class="flex justify-between text-sm text-gray-600">
<span>Hue</span>
<span>Saturation</span>
</div>
</div>
<div class="mb-6">
<label class="block text-sm font-medium text-gray-700 mb-2">Color Mode</label>
<select id="colorMode" class="border rounded-md px-3 py-2 w-full">
<option value="analogous">Analogous</option>
<option value="complementary">Complementary</option>
<option value="triadic">Triadic</option>
<option value="tetradic">Tetradic</option>
<option value="monochromatic">Monochromatic</option>
</select>
</div>
<div class="mb-6">
<label class="block text-sm font-medium text-gray-700 mb-2">Adjustments</label>
<div class="space-y-3">
<div>
<label class="block text-xs text-gray-500 mb-1">Brightness</label>
<input type="range" id="brightness" min="-100" max="100" value="0" class="w-full">
</div>
<div>
<label class="block text-xs text-gray-500 mb-1">Saturation</label>
<input type="range" id="saturation" min="-100" max="100" value="0" class="w-full">
</div>
<div>
<label class="block text-xs text-gray-500 mb-1">Luminosity</label>
<input type="range" id="luminosity" min="-100" max="100" value="0" class="w-full">
</div>
</div>
</div>
<div class="flex space-x-3">
<button id="randomBtn" class="bg-purple-600 hover:bg-purple-700 text-white px-4 py-2 rounded-md flex-1">
Random Palette
</button>
<button id="resetBtn" class="bg-gray-200 hover:bg-gray-300 text-gray-800 px-4 py-2 rounded-md flex-1">
Reset
</button>
</div>
</div>
<!-- Palette Display -->
<div class="bg-white rounded-xl shadow-md p-6 lg:col-span-2">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-semibold text-gray-800">Your Palette</h2>
<div class="flex space-x-2">
<button id="saveBtn" class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-1 rounded-md text-sm">
<i class="fas fa-save"></i> Save
</button>
<button id="exportBtn" class="bg-green-600 hover:bg-green-700 text-white px-3 py-1 rounded-md text-sm">
<i class="fas fa-download"></i> Export
</button>
<button id="shareBtn" class="bg-indigo-600 hover:bg-indigo-700 text-white px-3 py-1 rounded-md text-sm">
<i class="fas fa-share-alt"></i> Share
</button>
</div>
</div>
<div id="paletteContainer" class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4 mb-6">
<!-- Palette colors will be generated here -->
</div>
<div class="mb-6">
<h3 class="text-lg font-medium text-gray-800 mb-3">Preview</h3>
<div class="bg-gray-100 rounded-lg p-4">
<div class="flex items-center justify-between mb-3">
<div class="text-sm font-medium text-gray-700">Website Example</div>
<div class="flex space-x-2">
<button class="preview-btn active" data-theme="light">Light</button>
<button class="preview-btn" data-theme="dark">Dark</button>
</div>
</div>
<div id="websitePreview" class="border rounded-lg overflow-hidden">
<div class="preview-header h-10 flex items-center px-4" style="background-color: var(--primary)">
<div class="flex space-x-2">
<div class="w-3 h-3 rounded-full bg-red-500"></div>
<div class="w-3 h-3 rounded-full bg-yellow-500"></div>
<div class="w-3 h-3 rounded-full bg-green-500"></div>
</div>
<div class="text-sm ml-4">Example Site</div>
</div>
<div class="preview-nav h-8 px-4 flex items-center" style="background-color: var(--secondary)">
<div class="flex space-x-4 text-sm">
<span>Home</span>
<span>Products</span>
<span>About</span>
<span>Contact</span>
</div>
</div>
<div class="preview-content p-4" style="background-color: var(--background)">
<h4 class="text-lg mb-2" style="color: var(--text)">Welcome to our website</h4>
<p class="text-sm mb-3" style="color: var(--text)">This is a preview of how your color palette might look in a website design.</p>
<button class="px-3 py-1 rounded text-sm" style="background-color: var(--accent); color: var(--text)">Call to Action</button>
</div>
</div>
</div>
</div>
<div>
<h3 class="text-lg font-medium text-gray-800 mb-3">Accessibility Check</h3>
<div id="contrastResults" class="grid grid-cols-1 md:grid-cols-2 gap-3">
<!-- Contrast results will be generated here -->
</div>
</div>
</div>
</div>
<!-- Predefined Palettes Section -->
<div class="mt-8 bg-white rounded-xl shadow-md p-6">
<h2 class="text-xl font-semibold mb-4 text-gray-800">Predefined Palettes</h2>
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4">
<div class="palette-option cursor-pointer" data-colors="#3b82f6,#1e40af,#93c5fd,#bfdbfe,#eff6ff">
<div class="flex h-20 rounded-lg overflow-hidden mb-2">
<div class="flex-1" style="background-color: #3b82f6"></div>
<div class="flex-1" style="background-color: #1e40af"></div>
<div class="flex-1" style="background-color: #93c5fd"></div>
<div class="flex-1" style="background-color: #bfdbfe"></div>
<div class="flex-1" style="background-color: #eff6ff"></div>
</div>
<p class="text-sm text-center text-gray-700">Blue Tones</p>
</div>
<div class="palette-option cursor-pointer" data-colors="#10b981,#047857,#6ee7b7,#a7f3d0,#ecfdf5">
<div class="flex h-20 rounded-lg overflow-hidden mb-2">
<div class="flex-1" style="background-color: #10b981"></div>
<div class="flex-1" style="background-color: #047857"></div>
<div class="flex-1" style="background-color: #6ee7b7"></div>
<div class="flex-1" style="background-color: #a7f3d0"></div>
<div class="flex-1" style="background-color: #ecfdf5"></div>
</div>
<p class="text-sm text-center text-gray-700">Green Tones</p>
</div>
<div class="palette-option cursor-pointer" data-colors="#f59e0b,#b45309,#fcd34d,#fde68a,#fffbeb">
<div class="flex h-20 rounded-lg overflow-hidden mb-2">
<div class="flex-1" style="background-color: #f59e0b"></div>
<div class="flex-1" style="background-color: #b45309"></div>
<div class="flex-1" style="background-color: #fcd34d"></div>
<div class="flex-1" style="background-color: #fde68a"></div>
<div class="flex-1" style="background-color: #fffbeb"></div>
</div>
<p class="text-sm text-center text-gray-700">Warm Tones</p>
</div>
<div class="palette-option cursor-pointer" data-colors="#ec4899,#be185d,#f472b6,#f9a8d4,#fce7f3">
<div class="flex h-20 rounded-lg overflow-hidden mb-2">
<div class="flex-1" style="background-color: #ec4899"></div>
<div class="flex-1" style="background-color: #be185d"></div>
<div class="flex-1" style="background-color: #f472b6"></div>
<div class="flex-1" style="background-color: #f9a8d4"></div>
<div class="flex-1" style="background-color: #fce7f3"></div>
</div>
<p class="text-sm text-center text-gray-700">Pink Tones</p>
</div>
<div class="palette-option cursor-pointer" data-colors="#6366f1,#4f46e5,#a5b4fc,#c7d2fe,#eef2ff">
<div class="flex h-20 rounded-lg overflow-hidden mb-2">
<div class="flex-1" style="background-color: #6366f1"></div>
<div class="flex-1" style="background-color: #4f46e5"></div>
<div class="flex-1" style="background-color: #a5b4fc"></div>
<div class="flex-1" style="background-color: #c7d2fe"></div>
<div class="flex-1" style="background-color: #eef2ff"></div>
</div>
<p class="text-sm text-center text-gray-700">Purple Tones</p>
</div>
</div>
</div>
</div>
<!-- Export Modal -->
<div id="exportModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
<div class="bg-white rounded-lg p-6 w-full max-w-md">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-semibold">Export Palette</h3>
<button id="closeExportModal" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700 mb-2">Format</label>
<select id="exportFormat" class="border rounded-md px-3 py-2 w-full">
<option value="png">PNG Image</option>
<option value="json">JSON</option>
<option value="css">CSS Variables</option>
<option value="scss">SCSS Variables</option>
</select>
</div>
<div class="flex justify-end space-x-3">
<button id="cancelExport" class="bg-gray-200 hover:bg-gray-300 text-gray-800 px-4 py-2 rounded-md">
Cancel
</button>
<button id="confirmExport" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md">
Export
</button>
</div>
</div>
</div>
<!-- Save Modal -->
<div id="saveModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
<div class="bg-white rounded-lg p-6 w-full max-w-md">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-semibold">Save Palette</h3>
<button id="closeSaveModal" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700 mb-2">Palette Name</label>
<input type="text" id="paletteName" class="border rounded-md px-3 py-2 w-full" placeholder="My Awesome Palette">
</div>
<div class="flex justify-end space-x-3">
<button id="cancelSave" class="bg-gray-200 hover:bg-gray-300 text-gray-800 px-4 py-2 rounded-md">
Cancel
</button>
<button id="confirmSave" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md">
Save
</button>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// DOM Elements
const baseColorInput = document.getElementById('baseColor');
const hexInput = document.getElementById('hexInput');
const colorModeSelect = document.getElementById('colorMode');
const brightnessInput = document.getElementById('brightness');
const saturationInput = document.getElementById('saturation');
const luminosityInput = document.getElementById('luminosity');
const randomBtn = document.getElementById('randomBtn');
const resetBtn = document.getElementById('resetBtn');
const paletteContainer = document.getElementById('paletteContainer');
const contrastResults = document.getElementById('contrastResults');
const previewBtns = document.querySelectorAll('.preview-btn');
const paletteOptions = document.querySelectorAll('.palette-option');
const exportModal = document.getElementById('exportModal');
const saveModal = document.getElementById('saveModal');
const exportBtn = document.getElementById('exportBtn');
const saveBtn = document.getElementById('saveBtn');
const shareBtn = document.getElementById('shareBtn');
const closeExportModal = document.getElementById('closeExportModal');
const closeSaveModal = document.getElementById('closeSaveModal');
const cancelExport = document.getElementById('cancelExport');
const cancelSave = document.getElementById('cancelSave');
const confirmExport = document.getElementById('confirmExport');
const confirmSave = document.getElementById('confirmSave');
const exportFormat = document.getElementById('exportFormat');
const paletteName = document.getElementById('paletteName');
const colorWheel = document.getElementById('colorWheel');
// Current palette state
let currentPalette = [];
let currentBaseColor = '#3b82f6';
// Initialize
generatePalette();
// Event Listeners
baseColorInput.addEventListener('input', function() {
currentBaseColor = this.value;
hexInput.value = this.value;
generatePalette();
});
hexInput.addEventListener('input', function() {
if (/^#[0-9A-F]{6}$/i.test(this.value)) {
currentBaseColor = this.value;
baseColorInput.value = this.value;
generatePalette();
}
});
colorModeSelect.addEventListener('change', generatePalette);
brightnessInput.addEventListener('input', generatePalette);
saturationInput.addEventListener('input', generatePalette);
luminosityInput.addEventListener('input', generatePalette);
randomBtn.addEventListener('click', generateRandomPalette);
resetBtn.addEventListener('click', resetControls);
exportBtn.addEventListener('click', () => exportModal.classList.remove('hidden'));
saveBtn.addEventListener('click', () => saveModal.classList.remove('hidden'));
shareBtn.addEventListener('click', sharePalette);
closeExportModal.addEventListener('click', () => exportModal.classList.add('hidden'));
closeSaveModal.addEventListener('click', () => saveModal.classList.add('hidden'));
cancelExport.addEventListener('click', () => exportModal.classList.add('hidden'));
cancelSave.addEventListener('click', () => saveModal.classList.add('hidden'));
confirmExport.addEventListener('click', exportPalette);
confirmSave.addEventListener('click', savePalette);
previewBtns.forEach(btn => {
btn.addEventListener('click', function() {
previewBtns.forEach(b => b.classList.remove('active'));
this.classList.add('active');
updatePreview(this.dataset.theme);
});
});
paletteOptions.forEach(option => {
option.addEventListener('click', function() {
const colors = this.dataset.colors.split(',');
currentBaseColor = colors[0];
baseColorInput.value = currentBaseColor;
hexInput.value = currentBaseColor;
generatePaletteFromArray(colors);
});
});
colorWheel.addEventListener('click', function(e) {
const rect = this.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const centerX = rect.width / 2;
const centerY = rect.height / 2;
// Calculate angle and distance from center
const angle = Math.atan2(y - centerY, x - centerX) * (180 / Math.PI);
const distance = Math.sqrt(Math.pow(x - centerX, 2) + Math.pow(y - centerY, 2));
const maxDistance = centerX;
const saturation = Math.min(100, Math.round((distance / maxDistance) * 100));
// Convert angle to hue (0-360)
let hue = (angle + 180) % 360;
if (hue < 0) hue += 360;
// Convert HSL to HEX
currentBaseColor = hslToHex(hue, saturation, 50);
baseColorInput.value = currentBaseColor;
hexInput.value = currentBaseColor;
generatePalette();
});
// Helper Functions
function generatePalette() {
const baseColor = currentBaseColor;
const mode = colorModeSelect.value;
const brightness = parseInt(brightnessInput.value);
const saturation = parseInt(saturationInput.value);
const luminosity = parseInt(luminosityInput.value);
let colors = [];
// Convert base color to HSL
const hsl = hexToHsl(baseColor);
switch(mode) {
case 'analogous':
colors = generateAnalogousColors(hsl);
break;
case 'complementary':
colors = generateComplementaryColors(hsl);
break;
case 'triadic':
colors = generateTriadicColors(hsl);
break;
case 'tetradic':
colors = generateTetradicColors(hsl);
break;
case 'monochromatic':
colors = generateMonochromaticColors(hsl);
break;
}
// Apply adjustments
colors = colors.map(color => {
let [h, s, l] = hexToHsl(color);
// Adjust brightness (lightness)
l = Math.min(100, Math.max(0, l + brightness));
// Adjust saturation
s = Math.min(100, Math.max(0, s + saturation));
// Adjust luminosity (separate from brightness)
if (luminosity > 0) {
l = Math.min(100, l + (100 - l) * (luminosity / 100));
} else if (luminosity < 0) {
l = Math.max(0, l + l * (luminosity / 100));
}
return hslToHex(h, s, l);
});
currentPalette = colors;
renderPalette(colors);
updatePreview('light');
checkContrast();
}
function generatePaletteFromArray(colors) {
currentPalette = colors;
renderPalette(colors);
updatePreview('light');
checkContrast();
}
function generateRandomPalette() {
// Generate random hue (0-360)
const hue = Math.floor(Math.random() * 360);
currentBaseColor = hslToHex(hue, 70, 50);
baseColorInput.value = currentBaseColor;
hexInput.value = currentBaseColor;
// Randomly select a mode
const modes = ['analogous', 'complementary', 'triadic', 'tetradic', 'monochromatic'];
colorModeSelect.value = modes[Math.floor(Math.random() * modes.length)];
// Random adjustments (-30 to 30)
brightnessInput.value = Math.floor(Math.random() * 61) - 30;
saturationInput.value = Math.floor(Math.random() * 61) - 30;
luminosityInput.value = Math.floor(Math.random() * 61) - 30;
generatePalette();
}
function resetControls() {
currentBaseColor = '#3b82f6';
baseColorInput.value = currentBaseColor;
hexInput.value = currentBaseColor;
colorModeSelect.value = 'analogous';
brightnessInput.value = 0;
saturationInput.value = 0;
luminosityInput.value = 0;
generatePalette();
}
function renderPalette(colors) {
paletteContainer.innerHTML = '';
colors.forEach((color, index) => {
const colorElement = document.createElement('div');
colorElement.className = 'color-swatch flex flex-col items-center p-3 rounded-lg border border-gray-200';
colorElement.innerHTML = `
<div class="w-full h-20 rounded mb-2" style="background-color: ${color}"></div>
<div class="text-xs font-mono mb-1">${color.toUpperCase()}</div>
<div class="flex space-x-1">
<button class="copy-btn text-xs bg-gray-100 hover:bg-gray-200 px-2 py-1 rounded" data-color="${color}">
<i class="fas fa-copy"></i>
</button>
<button class="lock-btn text-xs bg-gray-100 hover:bg-gray-200 px-2 py-1 rounded" data-locked="false">
<i class="fas fa-lock-open"></i>
</button>
</div>
`;
paletteContainer.appendChild(colorElement);
});
// Add event listeners to new buttons
document.querySelectorAll('.copy-btn').forEach(btn => {
btn.addEventListener('click', function() {
const color = this.dataset.color;
navigator.clipboard.writeText(color);
const originalText = this.innerHTML;
this.innerHTML = '<i class="fas fa-check"></i>';
setTimeout(() => {
this.innerHTML = originalText;
}, 1000);
});
});
document.querySelectorAll('.lock-btn').forEach(btn => {
btn.addEventListener('click', function() {
const isLocked = this.dataset.locked === 'true';
this.dataset.locked = !isLocked;
this.innerHTML = isLocked ? '<i class="fas fa-lock-open"></i>' : '<i class="fas fa-lock"></i>';
});
});
}
function updatePreview(theme) {
const preview = document.getElementById('websitePreview');
const primary = currentPalette[0];
const secondary = currentPalette.length > 1 ? currentPalette[1] : adjustColor(primary, 20, 20);
const accent = currentPalette.length > 2 ? currentPalette[2] : adjustColor(primary, 30, -20);
if (theme === 'light') {
preview.style.setProperty('--primary', primary);
preview.style.setProperty('--secondary', secondary);
preview.style.setProperty('--background', '#ffffff');
preview.style.setProperty('--text', '#1f2937');
preview.style.setProperty('--accent', accent);
} else {
preview.style.setProperty('--primary', primary);
preview.style.setProperty('--secondary', secondary);
preview.style.setProperty('--background', '#1f2937');
preview.style.setProperty('--text', '#f3f4f6');
preview.style.setProperty('--accent', accent);
}
}
function checkContrast() {
contrastResults.innerHTML = '';
if (currentPalette.length < 2) return;
// Check contrast between all pairs
for (let i = 0; i < currentPalette.length; i++) {
for (let j = i + 1; j < currentPalette.length; j++) {
const color1 = currentPalette[i];
const color2 = currentPalette[j];
const ratio = getContrastRatio(color1, color2);
const result = document.createElement('div');
result.className = 'bg-gray-100 rounded-lg p-3 flex items-center justify-between';
const colorsDiv = document.createElement('div');
colorsDiv.className = 'flex items-center';
colorsDiv.innerHTML = `
<div class="w-6 h-6 rounded-full mr-2" style="background-color: ${color1}"></div>
<div class="w-6 h-6 rounded-full mr-2" style="background-color: ${color2}"></div>
<span class="text-sm">${color1.toUpperCase()} & ${color2.toUpperCase()}</span>
`;
const ratioDiv = document.createElement('div');
let ratioClass = 'contrast-poor';
if (ratio >= 7) {
ratioClass = 'contrast-good';
} else if (ratio >= 4.5) {
ratioClass = 'contrast-fair';
}
ratioDiv.className = `contrast-ratio ${ratioClass}`;
ratioDiv.textContent = ratio.toFixed(2) + ':1';
result.appendChild(colorsDiv);
result.appendChild(ratioDiv);
contrastResults.appendChild(result);
}
}
}
function exportPalette() {
const format = exportFormat.value;
switch(format) {
case 'png':
// In a real app, we'd use a library like html2canvas to generate an image
alert('PNG export would be implemented here');
break;
case 'json':
const json = JSON.stringify({
name: paletteName.value || 'My Color Palette',
colors: currentPalette,
created: new Date().toISOString()
}, null, 2);
const blob = new Blob([json], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'palette.json';
a.click();
break;
case 'css':
let css = ':root {\n';
currentPalette.forEach((color, index) => {
css += ` --color-${index + 1}: ${color};\n`;
});
css += '}';
const cssBlob = new Blob([css], { type: 'text/css' });
const cssUrl = URL.createObjectURL(cssBlob);
const cssA = document.createElement('a');
cssA.href = cssUrl;
cssA.download = 'palette.css';
cssA.click();
break;
case 'scss':
let scss = '';
currentPalette.forEach((color, index) => {
scss += `$color-${index + 1}: ${color};\n`;
});
const scssBlob = new Blob([scss], { type: 'text/scss' });
const scssUrl = URL.createObjectURL(scssBlob);
const scssA = document.createElement('a');
scssA.href = scssUrl;
scssA.download = 'palette.scss';
scssA.click();
break;
}
exportModal.classList.add('hidden');
}
function savePalette() {
const name = paletteName.value || 'My Color Palette';
// In a real app, we'd save to localStorage or a backend
alert(`Palette "${name}" would be saved here`);
saveModal.classList.add('hidden');
}
function sharePalette() {
if (navigator.share) {
navigator.share({
title: 'Check out my color palette!',
text: 'I created this beautiful color palette using the Color Palette Generator',
url: window.location.href
}).catch(err => {
console.log('Error sharing:', err);
fallbackShare();
});
} else {
fallbackShare();
}
}
function fallbackShare() {
const url = `mailto:?subject=My Color Palette&body=Check out this color palette I created: ${currentPalette.join(', ')}`;
window.open(url, '_blank');
}
// Color generation functions
function generateAnalogousColors(baseHsl) {
const [h, s, l] = baseHsl;
return [
hslToHex((h + 330) % 360, s, l),
hslToHex((h + 345) % 360, s, l),
hslToHex(h, s, l),
hslToHex((h + 15) % 360, s, l),
hslToHex((h + 30) % 360, s, l)
];
}
function generateComplementaryColors(baseHsl) {
const [h, s, l] = baseHsl;
return [
hslToHex(h, s, l),
hslToHex((h + 180) % 360, s, l),
hslToHex((h + 30) % 360, s, l),
hslToHex((h + 210) % 360, s, l),
hslToHex((h + 60) % 360, s, l)
];
}
function generateTriadicColors(baseHsl) {
const [h, s, l] = baseHsl;
return [
hslToHex(h, s, l),
hslToHex((h + 120) % 360, s, l),
hslToHex((h + 240) % 360, s, l),
hslToHex((h + 60) % 360, s, l),
hslToHex((h + 180) % 360, s, l)
];
}
function generateTetradicColors(baseHsl) {
const [h, s, l] = baseHsl;
return [
hslToHex(h, s, l),
hslToHex((h + 90) % 360, s, l),
hslToHex((h + 180) % 360, s, l),
hslToHex((h + 270) % 360, s, l),
hslToHex((h + 45) % 360, s, l)
];
}
function generateMonochromaticColors(baseHsl) {
const [h, s, l] = baseHsl;
return [
hslToHex(h, s, Math.max(0, l - 20)),
hslToHex(h, s, Math.max(0, l - 10)),
hslToHex(h, s, l),
hslToHex(h, s, Math.min(100, l + 10)),
hslToHex(h, s, Math.min(100, l + 20))
];
}
// Color conversion utilities
function hexToHsl(hex) {
// Convert hex to RGB first
let r = 0, g = 0, b = 0;
if (hex.length == 4) {
r = parseInt(hex[1] + hex[1], 16);
g = parseInt(hex[2] + hex[2], 16);
b = parseInt(hex[3] + hex[3], 16);
} else if (hex.length == 7) {
r = parseInt(hex[1] + hex[2], 16);
g = parseInt(hex[3] + hex[4], 16);
b = parseInt(hex[5] + hex[6], 16);
}
// Then to HSL
r /= 255;
g /= 255;
b /= 255;
const max = Math.max(r, g, b);
const min = Math.min(r, g, b);
let h, s, l = (max + min) / 2;
if (max === min) {
h = s = 0; // achromatic
} else {
const d = max - min;
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
switch(max) {
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
case g: h = (b - r) / d + 2; break;
case b: h = (r - g) / d + 4; break;
}
h /= 6;
}
return [Math.round(h * 360), Math.round(s * 100), Math.round(l * 100)];
}
function hslToHex(h, s, l) {
h /= 360;
s /= 100;
l /= 100;
let r, g, b;
if (s === 0) {
r = g = b = l; // achromatic
} else {
const hue2rgb = (p, q, t) => {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1/6) return p + (q - p) * 6 * t;
if (t < 1/2) return q;
if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
return p;
};
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
const p = 2 * l - q;
r = hue2rgb(p, q, h + 1/3);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1/3);
}
const toHex = x => {
const hex = Math.round(x * 255).toString(16);
return hex.length === 1 ? '0' + hex : hex;
};
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
}
function adjustColor(hex, saturationChange, lightnessChange) {
let [h, s, l] = hexToHsl(hex);
s = Math.min(100, Math.max(0, s + saturationChange));
l = Math.min(100, Math.max(0, l + lightnessChange));
return hslToHex(h, s, l);
}
function getContrastRatio(color1, color2) {
const luminance1 = getLuminance(color1);
const luminance2 = getLuminance(color2);
const lighter = Math.max(luminance1, luminance2);
const darker = Math.min(luminance1, luminance2);
return (lighter + 0.05) / (darker + 0.05);
}
function getLuminance(color) {
// Convert hex to RGB
let r = 0, g = 0, b = 0;
if (color.length == 4) {
r = parseInt(color[1] + color[1], 16);
g = parseInt(color[2] + color[2], 16);
b = parseInt(color[3] + color[3], 16);
} else if (color.length == 7) {
r = parseInt(color[1] + color[2], 16);
g = parseInt(color[3] + color[4], 16);
b = parseInt(color[5] + color[6], 16);
}
// Convert sRGB to linear RGB
r = r / 255;
g = g / 255;
b = b / 255;
r = r <= 0.03928 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4);
g = g <= 0.03928 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4);
b = b <= 0.03928 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4);
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
}
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Designer00m/colors" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>