From a0de5649ef7368b64568318df6b639101b16befc Mon Sep 17 00:00:00 2001 From: Brian Fertig Date: Sun, 25 Oct 2026 20:35:15 -0600 Subject: [PATCH] Add sky, equalizer skyline, street lamps, and shooting stars to bg-grid - Stars: 160 twinkling points with per-star phase/speed and occasional sharp glints - Moon: wireframe disc with crater rings at a fixed position in the backdrop - Equalizer skyline: 28 line-segment bars that shimmer idly and grow with bass energy - Street lamps: poles, arms, light beams, and ground pools on both lanes, reused by the existing scroll/recycle pass so they track the grid - Lamps' glow, beam, and pool opacity breathe with the beat - Shooting star: occasional streak that spawns at random intervals, fades in/out over its lifetime --- public/js/bg-grid.js | 169 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) diff --git a/public/js/bg-grid.js b/public/js/bg-grid.js index 9bf1f68..b57c30f 100644 --- a/public/js/bg-grid.js +++ b/public/js/bg-grid.js @@ -608,6 +608,134 @@ if (canvas) { } + // ---------- Sky: stars and moon (static, in front of the sunset backdrop) ---------- + const starCount = 160; + const starPos = new Float32Array(starCount * 3); + const starCol = new Float32Array(starCount * 3); + const starBase = [], starSpeed = [], starPhase = [], starGlint = []; + for (let i = 0; i < starCount; i++) { + starPos[i * 3] = rnd(-85, 85); + starPos[i * 3 + 1] = rnd(14, 62); + starPos[i * 3 + 2] = rnd(-58, -55); + starCol[i * 3] = 1; starCol[i * 3 + 1] = 1; starCol[i * 3 + 2] = 1; + starBase.push(0.4 + Math.random() * 0.6); // rest brightness + starSpeed.push(0.6 + Math.random() * 2.2); // twinkle tempo + starPhase.push(Math.random() * Math.PI * 2); // twinkle offset + starGlint.push(Math.random() < 0.35 ? 0.6 + Math.random() * 0.6 : 0); // occasional sharp sparkle + } + const starGeo = new THREE.BufferGeometry(); + starGeo.setAttribute('position', new THREE.BufferAttribute(starPos, 3)); + starGeo.setAttribute('color', new THREE.BufferAttribute(starCol, 3)); + const starsMat = new THREE.PointsMaterial({ color: 0xffffff, vertexColors: true, size: 0.85, transparent: true, opacity: 0.9, fog: false }); + scene.add(new THREE.Points(starGeo, starsMat)); + + // Moon: a wireframe disc with a few craters + function circlePtsZ(r, n) { + const pts = []; + for (let i = 0; i < n; i++) { + const a = (i / n) * Math.PI * 2; + pts.push(new THREE.Vector3(Math.cos(a) * r, Math.sin(a) * r, 0)); + } + return pts; + } + const moon = new THREE.Group(); + moon.position.set(38, 42, -58); + const moonMat = new THREE.LineBasicMaterial({ color: 0xffe8c0, transparent: true, opacity: 0.9, fog: false }); + moon.add(new THREE.LineLoop(new THREE.BufferGeometry().setFromPoints(circlePtsZ(4.5, 20)), moonMat)); + const moonCraterMat = new THREE.LineBasicMaterial({ color: 0xffe8c0, transparent: true, opacity: 0.4, fog: false }); + for (const [cx, cy, cr] of [[1.2, 0.8, 1.1], [-1.5, -1.2, 0.8], [0.4, -2.0, 0.6], [-0.6, 1.6, 0.5]]) { + const crater = new THREE.LineLoop(new THREE.BufferGeometry().setFromPoints(circlePtsZ(cr, 10)), moonCraterMat); + crater.position.set(cx, cy, 0); + moon.add(crater); + } + scene.add(moon); + + // ---------- Equalizer skyline (distant bars pulsing with the bass) ---------- + const EQ_BARS = 28; + const eqBase = [], eqPhase = [], eqSpeed = []; + const eqVerts = new Float32Array(EQ_BARS * 2 * 3); + const eqCol = new Float32Array(EQ_BARS * 2 * 3); + const eqPalette = [new THREE.Color(0x00e5ff), new THREE.Color(0x8f5bff), new THREE.Color(0xff2bd6)]; + for (let i = 0; i < EQ_BARS; i++) { + eqBase.push(1.2 + Math.random() * 3.2); + eqPhase.push(Math.random() * Math.PI * 2); + eqSpeed.push(0.5 + Math.random() * 1.2); + const x = -52.5 + i * (105 / (EQ_BARS - 1)); + const c = eqPalette[i % 3]; + eqVerts.set([x, 0, 0, x, 1, 0], i * 6); // bottom, top (animated) + eqCol.set([c.r * 0.25, c.g * 0.25, c.b * 0.25, c.r, c.g, c.b], i * 6); // dark base -> bright tip + } + const eqGeo = new THREE.BufferGeometry(); + eqGeo.setAttribute('position', new THREE.BufferAttribute(eqVerts, 3)); + eqGeo.setAttribute('color', new THREE.BufferAttribute(eqCol, 3)); + const eqMat = new THREE.LineBasicMaterial({ vertexColors: true, transparent: true, opacity: 0.55 }); + const eq = new THREE.LineSegments(eqGeo, eqMat); + eq.position.z = -45; // far down the grid, like a distant city skyline + scene.add(eq); + + // ---------- Street lamps (scroll with the grid, recycle behind the camera) ---------- + const LAMP_H = 5.4; // up with the palm trunks + const lampMat = new THREE.LineBasicMaterial({ color: 0xcfd8e3, transparent: true, opacity: 0.8 }); // silver + const lampGeo = new THREE.BufferGeometry(); + lampGeo.setAttribute('position', new THREE.Float32BufferAttribute([ + 0, 0, 0, 0, LAMP_H, 0, // pole + 0, LAMP_H, 0, 0.6, LAMP_H, 0, // arm + ], 3)); + const lampHeadGeo = new THREE.EdgesGeometry(new THREE.BoxGeometry(0.4, 0.24, 0.26)); + // Light beam: an open cone of struts from the lamp head down to the grid + const beamGeo = new THREE.EdgesGeometry(new THREE.CylinderGeometry(0.18, 2.0, LAMP_H - 0.2, 8, 1, true)); + const beamMat = new THREE.LineBasicMaterial({ color: 0xe6eef7, transparent: true, opacity: 0.15, depthWrite: false }); + // Pool of light on the surface + const poolGeo = new THREE.BufferGeometry().setFromPoints(circlePtsY(2.0, 14, 0)); + const poolMat = new THREE.LineBasicMaterial({ color: 0xeef4fb, transparent: true, opacity: 0.4, depthWrite: false }); + for (const lane of [+6.2, -6.2]) { + for (let i = 0; i < 9; i++) { + const lamp = new THREE.Group(); + lamp.position.set(lane, 0, -6 - i * 12); + lamp.add(new THREE.LineSegments(lampGeo, lampMat)); + const head = new THREE.LineSegments(lampHeadGeo, lampMat); + head.position.set(0.78, LAMP_H - 0.1, 0); + lamp.add(head); + const beam = new THREE.LineSegments(beamGeo, beamMat); + beam.position.set(0.78, (LAMP_H - 0.2) / 2, 0); + lamp.add(beam); + const pool = new THREE.LineLoop(poolGeo, poolMat); + pool.position.set(0.78, 0.03, 0); + lamp.add(pool); + lamp.userData.baseX = lane; + // Slight size variance so they don't read as a rigid fence + lamp.scale.setScalar(0.9 + Math.random() * 0.3); + scene.add(lamp); + palmTrees.push(lamp); // reuse the same scroll & recycle pass + } + } + + // ---------- Occasional shooting star ---------- + const shootMat = new THREE.LineBasicMaterial({ color: 0xd9ecff, transparent: true, opacity: 0, fog: false }); + const shootGroup = new THREE.Group(); + shootGroup.add(new THREE.Line(new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(0, 0, 0), new THREE.Vector3(1, 0, 0)]), shootMat)); + shootGroup.visible = false; + scene.add(shootGroup); + const shooting = { + active: false, + group: shootGroup, + nextAt: performance.now() + rnd(12000, 25000), + life: 0, + dur: 1.3, + vel: new THREE.Vector3(), + }; + const _shootDir = new THREE.Vector3(); + function spawnShootingStar() { + const side = Math.random() < 0.5 ? -1 : 1; + shooting.vel.set(side * rnd(0.7, 1), -rnd(0.3, 0.5), 0).normalize().multiplyScalar(rnd(55, 85)); + shooting.group.position.set(-side * rnd(15, 45), rnd(36, 55), -52); + _shootDir.copy(shooting.vel).normalize(); + shooting.group.quaternion.setFromUnitVectors(new THREE.Vector3(1, 0, 0), _shootDir); + shooting.life = 0; + shooting.group.visible = true; + shooting.active = true; + } + // ---------- Beat / bass reactivity surface ---------- const state = { beat: 0, // smoothed bass energy 0..1 @@ -685,6 +813,47 @@ if (canvas) { } } + // Street lamps: glow, beam and ground pool all breathe with the beat + lampMat.opacity = 0.55 + state.beat * 0.35; + beamMat.opacity = 0.1 + state.beat * 0.14; + poolMat.opacity = 0.3 + state.beat * 0.45; + + // Equalizer skyline: idle shimmer + bass-driven growth + const eqPos = eqGeo.attributes.position; + for (let i = 0; i < EQ_BARS; i++) { + const h = eqBase[i] * (0.55 + 0.45 * Math.sin(now * 0.001 * eqSpeed[i] + eqPhase[i])) * (1 + state.beat * 1.6); + eqPos.setY(i * 2 + 1, h); + } + eqPos.needsUpdate = true; + + // Star twinkle: every star breathes on its own rhythm, some glint sharply + const starColorAttr = starGeo.attributes.color; + for (let i = 0; i < starCount; i++) { + const t1 = now * 0.001 * starSpeed[i] + starPhase[i]; + let b = starBase[i] * (0.3 + 0.55 * Math.pow(0.5 + 0.5 * Math.sin(t1), 2)); + if (starGlint[i]) { + const s = Math.sin(now * 0.0021 * starSpeed[i] + starPhase[i] * 3); + b += starGlint[i] * Math.pow(Math.max(0, s), 6); + } + starColorAttr.setXYZ(i, b * 0.78, b * 0.88, Math.min(1.2, b)); // pale ice-blue tint + } + starColorAttr.needsUpdate = true; + + // Shooting star streaks + if (!shooting.active && now >= shooting.nextAt) spawnShootingStar(); + if (shooting.active) { + shooting.life += dt; + const p = Math.min(1, shooting.life / shooting.dur); + shooting.group.position.addScaledVector(shooting.vel, dt); + shootMat.opacity = Math.sin(Math.PI * p) * 0.9; + shooting.group.scale.set(4 + 4 * Math.sin(Math.PI * p), 1, 1); + if (p >= 1) { + shooting.active = false; + shooting.group.visible = false; + shooting.nextAt = now + rnd(18000, 40000); + } + } + // Pulse color on beat (violet -> magenta) const mix = Math.min(1, state.beat); gridMat.color.setRGB(0.56 + mix * 0.44, 0.35 - mix * 0.2, 0.94);