Refactor earthday.js: move flowerColors definition to a constant and use it in flower generation

This commit is contained in:
CodeDevMLH
2026-02-24 19:19:25 +01:00
parent f4f472e6ec
commit f9b4b3c25d

View File

@@ -3,6 +3,8 @@ const config = window.SeasonalsPluginConfig?.EarthDay || {};
const enabled = config.EnableEarthDay !== undefined ? config.EnableEarthDay : true; const enabled = config.EnableEarthDay !== undefined ? config.EnableEarthDay : true;
const vineCount = config.VineCount || 4; const vineCount = config.VineCount || 4;
const flowerColors = ['#FF69B4', '#FFD700', '#87CEFA', '#FF4500', '#BA55D3', '#FFA500', '#FF1493'];
let msgPrinted = false; let msgPrinted = false;
// Toggle Function // Toggle Function
@@ -66,12 +68,11 @@ function createElements() {
} }
// Generate Flowers // Generate Flowers
const colors = ['#FF69B4', '#FFD700', '#87CEFA', '#FF4500', '#BA55D3', '#FFA500', '#FF1493'];
const flowerCount = Math.max(10, vineCount * 15); const flowerCount = Math.max(10, vineCount * 15);
for (let i = 0; i < flowerCount; i++) { for (let i = 0; i < flowerCount; i++) {
const x = 10 + Math.random() * (w - 20); const x = 10 + Math.random() * (w - 20);
const y = hSVG * 0.1 + Math.random() * (hSVG * 0.5); const y = hSVG * 0.1 + Math.random() * (hSVG * 0.5);
const col = colors[Math.floor(Math.random() * colors.length)]; const col = flowerColors[Math.floor(Math.random() * flowerColors.length)];
paths += `<path d="M ${x} ${hSVG} Q ${x - 5 + Math.random() * 10} ${y+15} ${x} ${y}" stroke="#006400" stroke-width="1.5" fill="none"/>`; paths += `<path d="M ${x} ${hSVG} Q ${x - 5 + Math.random() * 10} ${y+15} ${x} ${y}" stroke="#006400" stroke-width="1.5" fill="none"/>`;