diff --git a/public/js/bg-grid.js b/public/js/bg-grid.js index 695c2f4..b479e8f 100644 --- a/public/js/bg-grid.js +++ b/public/js/bg-grid.js @@ -650,6 +650,18 @@ if (canvas) { } scene.add(moon); + // Moon cycle: slow rise-and-set across an arch (~60s), ~10s below the + // horizon, then rising again from the opposite side of the sky + const MOON_EDGE = 78; // x of the rise/set point (near the screen edge) + const MOON_DUR = 60; // seconds from horizon to horizon + const MOON_REST = 10; // seconds hidden between passes + const moonCycle = { + t: 0, // seconds into the current pass + side: 1, // +1 = rising on the left, -1 = rising on the right + hidden: false, + restLeft: 0, + }; + // ---------- Equalizer skyline (distant bars pulsing with the bass) ---------- const EQ_BARS = 28; const eqBase = [], eqPhase = [], eqSpeed = []; @@ -951,6 +963,37 @@ if (canvas) { } starColorAttr.needsUpdate = true; + // Moon: drift along a slow arch, then rest and re-rise on the other side + if (moonCycle.hidden) { + moonCycle.restLeft -= dt; + if (moonCycle.restLeft <= 0) { + moonCycle.hidden = false; + moonCycle.t = 0; + moonCycle.side = -moonCycle.side; // rise from the opposite edge + } + } else { + moon.visible = true; + moonCycle.t += dt; + const p = Math.min(1, moonCycle.t / MOON_DUR); + const x0 = moonCycle.side > 0 ? -MOON_EDGE : MOON_EDGE; + const x1 = moonCycle.side > 0 ? MOON_EDGE : -MOON_EDGE; + moon.position.x = x0 + (x1 - x0) * p; + // Sinks just below the horizon at both ends so it clearly rises & sets + const y = -6 + 44 * Math.sin(Math.PI * p); + moon.position.y = y; + // Fade out as its lower edge dips under the horizon, so it slips + // behind it instead of overlapping the horizon line + const fade = Math.min(1, Math.max(0, (y - 4.5) / 8)); // 4.5 = moon radius + moonMat.opacity = 0.9 * fade; + moonCraterMat.opacity = 0.4 * fade; + moon.rotation.z = p * Math.PI * 2; // one lazy turn over the whole pass + if (p >= 1) { + moon.visible = false; // fully set behind the horizon + moonCycle.hidden = true; + moonCycle.restLeft = MOON_REST; + } + } + // Shooting star streaks if (!shooting.active && now >= shooting.nextAt) spawnShootingStar(); if (shooting.active) {