Add slow moon rise-and-set cycle to background grid
- Moon now drifts along a ~60s arch across the sky, rests ~10s below the horizon, then re-rises from the opposite edge - Fades out near the horizon so it slips behind it rather than overlapping the line, and rotates once per pass
This commit is contained in:
parent
8d1dfb03d4
commit
a8396c4024
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue