Download script.js from HyacinthChapter/colorful-canvas-creator: direct link, hf CLI and curl.
- Browser
- Download file 1.89 kB
-
https://huggingface.co/spaces/HyacinthChapter/colorful-canvas-creator/resolve/main/script.js
- Command line
-
hf download hf://spaces/HyacinthChapter/colorful-canvas-creator/script.js
-
curl -L -o script.js https://huggingface.co/spaces/HyacinthChapter/colorful-canvas-creator/resolve/main/script.js
1.89 kB
| document.addEventListener('DOMContentLoaded', function() { | |
| // Generate random color palette | |
| const generateBtn = document.querySelector('button'); | |
| if (generateBtn) { | |
| generateBtn.addEventListener('click', function() { | |
| const colorBlocks = document.querySelectorAll('.bg-primary-100, .bg-primary-300, .bg-primary-500, .bg-primary-700, .bg-primary-900, .bg-secondary-100, .bg-secondary-300, .bg-secondary-500, .bg-secondary-700, .bg-secondary-900'); | |
| colorBlocks.forEach(block => { | |
| const isPrimary = block.classList.contains('bg-primary-100') || | |
| block.classList.contains('bg-primary-300') || | |
| block.classList.contains('bg-primary-500') || | |
| block.classList.contains('bg-primary-700') || | |
| block.classList.contains('bg-primary-900'); | |
| const hues = isPrimary ? | |
| [190, 195, 200, 205, 210] : // Primary color hues (blues) | |
| [260, 265, 270, 275, 280]; // Secondary color hues (purples) | |
| const randomHue = hues[Math.floor(Math.random() * hues.length)]; | |
| const randomSaturation = 80 + Math.floor(Math.random() * 20); | |
| const randomLightness = isPrimary ? | |
| [90, 70, 50, 30, 10][Array.from(block.classList).findIndex(cls => cls.includes('primary')) % 5] : | |
| [90, 70, 50, 30, 10][Array.from(block.classList).findIndex(cls => cls.includes('secondary')) % 5]; | |
| const newColor = `hsl(${randomHue}, ${randomSaturation}%, ${randomLightness}%)`; | |
| block.style.backgroundColor = newColor; | |
| }); | |
| }); | |
| } | |
| // Feather icons replacement | |
| feather.replace(); | |
| }); |