moreiraj93's picture
https://image2url.com/images/1761549230258-8d82204b-e6f9-4fd3-bf70-cb416b606c78.webp https://image2url.com/images/1761549261138-8c5d0146-33a0-439e-8600-ac4e78052139.webp https://image2url.com/images/1761549284835-2f67e3e9-6b75-4f4b-9ad0-68e92bf81118.jpg https://image2url.com/images/1761549308567-dc29722e-f3dd-4f10-8f8f-340ce5f06b6b.jpg
06ffea8 verified
document.addEventListener('DOMContentLoaded', function() {
// Color generator button functionality
const colorGenerator = document.getElementById('color-generator');
if (colorGenerator) {
colorGenerator.addEventListener('click', function() {
const colors = generateRandomColors(5);
applyColorsToElements(colors);
});
}
// Generate random colors
function generateRandomColors(count) {
const colors = [];
for (let i = 0; i < count; i++) {
const hue = Math.floor(Math.random() * 360);
colors.push(`hsl(${hue}, 70%, 60%)`);
}
return colors;
}
// Apply colors to elements
function applyColorsToElements(colors) {
const colorBlocks = document.querySelectorAll('.color-block');
colorBlocks.forEach((block, index) => {
const color = colors[index % colors.length];
block.style.backgroundColor = color;
block.style.backgroundImage = `linear-gradient(to bottom right, ${color}, ${adjustBrightness(color, -20)})`;
});
}
// Helper function to adjust color brightness
function adjustBrightness(color, percent) {
// Implementation for adjusting color brightness
// This is a simplified version - in a real app you might want to use a color manipulation library
return color;
}
});