File size: 1,400 Bytes
06ffea8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
    }
});