Prompt specification
Build or customize the Three.js 3D scene "Two Hemispheres Seasonal Garden Comparison" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Two Hemispheres Seasonal Garden Comparison
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/two-hemispheres-seasonal-garden-comparison-x3767
Scene Description Prompt:
Compare voxel gardens in opposite hemispheres, linking seasonal sunlight geometry to a globe and marking growth illustrative. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (two-hemispheres-seasonal-garden-comparison-x3767):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Gardens — Hemispheric Season Study</title>
<style>
:root{
--north:#6ee7f9; --south:#fca66b; --ink:#e8f1f8;
--panel:rgba(9,16,26,.74); --line:rgba(140,185,215,.18);
--dim:#8ea6b8;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;background:#04060c;color:var(--ink);
font:13px/1.45 ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;
overflow:hidden;-webkit-font-smoothing:antialiased}
#app{position:fixed;inset:0}
canvas{display:block;touch-action:none}
.hud{position:fixed;inset:0;pointer-events:none;z-index:5}
.panel{position:absolute;background:var(--panel);border:1px solid var(--line);
border-radius:12px;padding:11px 13px;backdrop-filter:blur(10px);
box-shadow:0 10px 34px rgba(0,0,0,.45);pointer-events:auto}
h1{font-size:15px;margin:0 0 2px;letter-spacing:.14em;text-transform:uppercase;font-weight:650}
.sub{color:var(--dim);font-size:11px;letter-spacing:.05em}
#title{top:16px;left:16px;max-width:330px}
#title .sub{margin-top:4px}
.hemi{width:246px}
#north{top:16px;right:16px;border-top:2px solid var(--north)}
#south{bottom:112px;right:16px;border-top:2px solid var(--south)}
.hname{display:flex;justify-content:space-between;align-items:baseline;
font-size:11.5px;letter-spacing:.16em;text-transform:uppercase;font-weight:650}
.hname .tag{font-size:10px;letter-spacing:.1em;color:var(--dim);font-weight:500}
.rows{margin-top:9px;display:grid;grid-template-columns:auto 1fr;gap:3px 10px;font-size:11.5px}
.rows .k{color:var(--dim)}
.rows .v{text-align:right;font-variant-numeric:tabular-nums}
.meter{margin-top:9px}
.meter .lab{display:flex;justify-content:space-between;font-size:10px;
letter-spacing:.11em;text-transform:uppercase;color:var(--dim)}
.bar{height:7px;margin-top:4px;border-radius:4px;background:rgba(255,255,255,.07);
border:1px solid var(--line);overflow:hidden}
.bar i{display:block;height:100%;width:0%;transition:width .12s linear;
background-image:repeating-linear-gradient(115deg,rgba(255,255,255,.28) 0 4px,rgba(255,255,255,0) 4px 9px)}
#north .bar i{background-color:var(--north)}
#south .bar i{background-color:var(--south)}
.illu{font-size:9.5px;letter-spacing:.13em;text-transform:uppercase;color:#6d8496;margin-top:4px}
#clock{top:16px;left:50%;transform:translateX(-50%);text-align:center;min-width:250px}
#clock .date{font-size:19px;letter-spacing:.09em;font-variant-numeric:tabular-nums}
#clock .season{font-size:11px;color:var(--north);margin-top:2px;letter-spacing:.08em}
#clock .decl{font-size:11px;color:var(--dim);margin-top:4px;font-variant-numeric:tabular-nums}
#controls{bottom:16px;left:50%;transform:translateX(-50%);display:flex;gap:6px;
align-items:center;flex-wrap:wrap;justify-content:center;max-width:min(96vw,860px)}
button{font:inherit;font-size:11px;letter-spacing:.07em;color:var(--ink);cursor:pointer;
background:rgba(255,255,255,.05);border:1px solid var(--line);border-radius:8px;padding:6px 10px}
button:hover{background:rgba(120,200,255,.14);border-color:rgba(140,210,255,.42)}
button.on{background:rgba(110,231,249,.18);border-color:rgba(110,231,249,.5)}
.sep{width:1px;height:22px;background:var(--line);margin:0 3px}
#note{bottom:16px;left:16px;max-width:300px;font-size:11px;color:var(--dim)}
#note b{color:#cfe3f0;font-weight:600}
#note .warn{color:#f0c987}
#compare{bottom:112px;left:16px;width:246px}
#compare .cmp{font-size:11px;color:var(--dim);margin-top:5px}
#compare .lead{font-size:12.5px;font-variant-numeric:tabular-nums}
#legend{bottom:16px;right:16px;font-size:10.5px;color:var(--dim);text-align:right;
max-width:230px}
@media (max-width:1000px){
#note,#legend{display:none}
#north{top:auto;bottom:150px;right:16px}
#south{display:none}
#compare{display:none}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="hud">
<div class="panel" id="title">
<h1>Voxel Gardens</h1>
<div class="sub">Hemispheric season study — solar geometry linked to growth</div>
</div>
<div class="panel" id="clock">
<div class="date" id="date">Jun 21</div>
<div class="season" id="season">Northern summer · Southern winter</div>
<div class="decl" id="decl">declination δ +23.4° · axial tilt 23.44°</div>
</div>
<div class="panel hemi" id="north">
<div class="hname"><span style="color:var(--north)">Northern garden</span><span class="tag">45°N</span></div>
<div class="rows">
<div class="k">Season</div><div class="v" id="n-season">—</div>
<div class="k">Solar noon elevation</div><div class="v" id="n-elev">—</div>
<div class="k">Day length</div><div class="v" id="n-len">—</div>
<div class="k">Light proxy</div><div class="v" id="n-prox">—</div>
</div>
<div class="meter">
<div class="lab"><span>Growth</span><span id="n-grow">0%</span></div>
<div class="bar"><i id="n-bar"></i></div>
<div class="illu">▨ illustrative — proxy only</div>
</div>
</div>
<div class="panel hemi" id="south">
<div class="hname"><span style="color:var(--south)">Southern garden</span><span class="tag">45°S</span></div>
<div class="rows">
<div class="k">Season</div><div class="v" id="s-season">—</div>
<div class="k">Solar noon elevation</div><div class="v" id="s-elev">—</div>
<div class="k">Day length</div><div class="v" id="s-len">—</div>
<div class="k">Light proxy</div><div class="v" id="s-prox">—</div>
</div>
<div class="meter">
<div class="lab"><span>Growth</span><span id="s-grow">0%</span></div>
<div class="bar"><i id="s-bar"></i></div>
<div class="illu">▨ illustrative — proxy only</div>
</div>
</div>
<div class="panel" id="compare">
<div class="hname"><span>Comparison</span><span class="tag">opposite hemispheres</span></div>
<div class="cmp">Seasonal growth lead</div>
<div class="lead" id="lead">—</div>
<div class="cmp">Light proxy gap</div>
<div class="lead" id="gap">—</div>
</div>
<div class="panel" id="controls">
<button id="play">⏸ Pause</button>
<button id="speed">1×</button>
<div class="sep"></div>
<button data-jump="0">Jun solstice</button>
<button data-jump="90">Sep equinox</button>
<button data-jump="180">Dec solstice</button>
<button data-jump="270">Mar equinox</button>
<div class="sep"></div>
<button id="orbit">Auto-orbit</button>
<button id="reset">Reset view</button>
</div>
<div class="panel" id="note">
<b>Method.</b> Earth's axis is tilted 23.44°; the Sun runs the ecliptic once a year,
so declination δ swings ±23.4°. Each garden's <b>noon elevation</b> and <b>day length</b>
are real spherical-astronomy geometry. <span class="warn">Growth response is illustrative</span> —
a stylized proxy for seasonal light, not a calibrated phenology or climate model.
</div>
<div class="panel" id="legend">
── dashed circle = day/night terminator<br>
── blue line = polar axis · ring = ecliptic<br>
── striped bars = illustrative growth proxy
</div>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ============================================================
Constants & scene
============================================================ */
const R = 3.0; // globe radius
const SUN_R = 11.5; // sun orbital radius (ecliptic)
const EPS = THREE.MathUtils.degToRad(23.44);
const DEG = 180 / Math.PI;
const clamp = THREE.MathUtils.clamp;
const app = document.getElementById('app');
const renderer = new THREE.WebGLRenderer({ antialias:true, powerPreference:'high-performance' });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x04060c);
scene.fog = new THREE.FogExp2(0x04060c, 0.012);
const camera = new THREE.PerspectiveCamera(42, innerWidth/innerHeight, 0.1, 300);
scene.add(new THREE.AmbientLight(0x2b3d55, 0.85));
const sunLight = new THREE.DirectionalLight(0xfff1d6, 2.1);
scene.add(sunLight);
const fillLight = new THREE.DirectionalLight(0x5f86b8, 0.45);
fillLight.position.set(-6, 5, 4);
scene.add(fillLight);
/* ============================================================
Small helpers: labels, radial textures
============================================================ */
function radialTex(inner, mid){
const c = document.createElement('canvas'); c.width = c.height = 128;
const g = c.getContext('2d');
const grd = g.createRadialGradient(64,64,0,64,64,64);
grd.addColorStop(0, inner); grd.addColorStop(.32, mid); grd.addColorStop(1,'rgba(0,0,0,0)');
g.fillStyle = grd; g.fillRect(0,0,128,128);
const t = new THREE.CanvasTexture(c); t.colorSpace = THREE.SRGBColorSpace; return t;
}
class Label {
constructor(text, { color='#dbe9f4', size=40, worldH=0.26, weight=500, glow=null } = {}){
this.size = size; this.weight = weight; this.color = color; this.worldH = worldH;
this.glow = glow;
this.canvas = document.createElement('canvas');
this.ctx = this.canvas.getContext('2d');
this.tex = new THREE.CanvasTexture(this.canvas);
this.tex.colorSpace = THREE.SRGBColorSpace;
this.mat = new THREE.SpriteMaterial({ map:this.tex, transparent:true,
depthTest:false, depthWrite:false });
this.sprite = new THREE.Sprite(this.mat);
this.sprite.renderOrder = 12;
this._t = null;
this.set(text);
}
set(t){
if (t === this._t) return; this._t = t;
const c = this.ctx;
const font = `${this.weight} ${this.size}px ui-sans-serif,system-ui,"Segoe UI",Roboto,sans-serif`;
c.font = font;
const w = Math.ceil(c.measureText(t).width) + 18;
const h = Math.round(this.size * 1.42);
this.canvas.width = w; this.canvas.height = h;
c.font = font; c.textAlign = 'center'; c.textBaseline = 'middle';
if (this.glow){ c.shadowColor = this.glow; c.shadowBlur = 12; }
c.fillStyle = this.color; c.fillText(t, w/2, h/2);
this.tex.needsUpdate = true;
this.sprite.scale.set(this.worldH * (w/h), this.worldH, 1);
}
}
/* ============================================================
Earth group (tilted axis) + globe
============================================================ */
const earth = new THREE.Group();
earth.rotation.y = EPS; // local +Z (north pole) -> world (sinε,0,cosε)
scene.add(earth);
const P = new THREE.Vector3(0,0,1); // earth-local north pole
const globeMat = new THREE.ShaderMaterial({
uniforms:{ uSun:{ value:new THREE.Vector3(1,0,0) } },
vertexShader:`
varying vec3 vWN; varying vec3 vWP;
void main(){
vec4 wp = modelMatrix * vec4(position,1.0);
vWP = wp.xyz; vWN = normalize(mat3(modelMatrix)*normal);
gl_Position = projectionMatrix * viewMatrix * wp;
}`,
fragmentShader:`
uniform vec3 uSun; varying vec3 vWN; varying vec3 vWP;
void main(){
vec3 n = normalize(vWN);
vec3 s = normalize(uSun);
float ndl = dot(n,s);
float day = smoothstep(-0.16,0.30,ndl);
vec3 night = vec3(0.010,0.022,0.042);
vec3 ocean = vec3(0.030,0.085,0.130);
vec3 c = mix(night, ocean, day);
float term = 1.0 - smoothstep(0.0,0.22,abs(ndl));
c += vec3(0.30,0.55,0.60)*term*0.16;
vec3 v = normalize(cameraPosition - vWP);
float rim = pow(1.0 - max(dot(n,v),0.0), 3.2);
c += vec3(0.16,0.42,0.55)*rim*0.55;
gl_FragColor = vec4(c,1.0);
}`
});
const globe = new THREE.Mesh(new THREE.SphereGeometry(R, 72, 48), globeMat);
earth.add(globe);
/* ---------------- value-noise voxel continents ---------------- */
function hash(x,y,z){ const s = Math.sin(x*127.1 + y*311.7 + z*74.7)*43758.5453123; return s - Math.floor(s); }
function sm(t){ return t*t*(3-2*t); }
function noise3(x,y,z){
const xi=Math.floor(x), yi=Math.floor(y), zi=Math.floor(z);
const xf=x-xi, yf=y-yi, zf=z-zi, u=sm(xf), v=sm(yf), w=sm(zf);
const h=(a,b,c)=>hash(a,b,c);
const c000=h(xi,yi,zi), c100=h(xi+1,yi,zi), c010=h(xi,yi+1,zi), c110=h(xi+1,yi+1,zi);
const c001=h(xi,yi,zi+1), c101=h(xi+1,yi,zi+1), c011=h(xi,yi+1,zi+1), c111=h(xi+1,yi+1,zi+1);
const x00=c000+(c100-c000)*u, x10=c010+(c110-c010)*u, x01=c001+(c101-c001)*u, x11=c011+(c111-c011)*u;
const y0=x00+(x10-x00)*v, y1=x01+(x11-x01)*v;
return y0+(y1-y0)*w;
}
function fbm(x,y,z){ let a=.5,f=1,s=0; for(let i=0;i<4;i++){ s+=a*noise3(x*f,y*f,z*f); f*=2.03; a*=.5; } return s; }
/* ============================================================
Gardens (declared before land so land can avoid them)
============================================================ */
const GARDENS = [
{ key:'north', lat: 45, lon: 30, accent:0x6ee7f9, name:'NORTHERN GARDEN · 45°N' },
{ key:'south', lat:-45, lon:-100, accent:0xfca66b, name:'SOUTHERN GARDEN · 45°S' }
];
function latLonDir(lat, lon){
const p = THREE.MathUtils.degToRad(lat), l = THREE.MathUtils.degToRad(lon);
return new THREE.Vector3(Math.cos(p)*Math.cos(l), Math.cos(p)*Math.sin(l), Math.sin(p));
}
function basisFor(dir){
const east = new THREE.Vector3().crossVectors(P, dir).normalize();
const north = new THREE.Vector3().crossVectors(dir, east).normalize();
return { east, north };
}
/* ---------------- voxel land shell ---------------- */
(function buildLand(){
const cells = [];
const step = 3.0;
for (let lat=-84; lat<=84; lat+=step){
for (let lon=-180; lon<180; lon+=step){
const d = latLonDir(lat, lon);
let skip = false;
for (const g of GARDENS){
if (d.angleTo(latLonDir(g.lat, g.lon)) < THREE.MathUtils.degToRad(14)) { skip = true; break; }
}
if (skip) continue;
const n = fbm(d.x*2.7+11.3, d.y*2.7+4.7, d.z*2.7+21.9);
const ice = Math.abs(lat) > 70;
if (!ice && n < 0.505) continue;
cells.push({ d, lat, n });
}
}
const geo = new THREE.BoxGeometry(0.17,0.17,0.17);
const mat = new THREE.MeshLambertMaterial({ color:0xffffff });
const mesh = new THREE.InstancedMesh(geo, mat, cells.length);
const m = new THREE.Matrix4(), q = new THREE.Quaternion(), sc = new THREE.Vector3(), pos = new THREE.Vector3();
const col = new THREE.Color();
cells.forEach((c,i)=>{
const { east, north } = basisFor(c.d);
const b = new THREE.Matrix4().makeBasis(east, north, c.d);
q.setFromRotationMatrix(b);
const jitter = (hash(c.lat*3.1, c.lon*0.7, i*0.13) - 0.5);
const h = 0.17 * (1 + jitter*0.55);
pos.copy(c.d).multiplyScalar(R + 0.085 + jitter*0.045);
sc.set(1, 1, 1 + jitter*0.3);
m.compose(pos, q, sc);
mesh.setMatrixAt(i, m);
const a = Math.abs(c.lat);
let r,g,b2;
if (a > 70){ r=.82; g=.87; b2=.93; }
else if (a > 48){ r=.40; g=.37; b2=.27; }
else if (a > 22){ r=.28; g=.40; b2=.20; }
else { r=.16; g=.44; b2=.19; }
const v = 0.85 + hash(i*1.7, c.lat, c.lon)*0.32;
col.setRGB(r*v, g*v, b2*v);
mesh.setColorAt(i, col);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
earth.add(mesh);
})();
/* ---------------- graticule (floating diagram lines) ---------------- */
(function graticule(){
const mat = new THREE.LineBasicMaterial({ color:0x6fd0e6, transparent:true,
opacity:.20, depthTest:false });
const mk = (pts)=>{ const g=new THREE.BufferGeometry().setFromPoints(pts);
const l=new THREE.Line(g, mat); l.renderOrder=4; earth.add(l); return l; };
const ring = (lat)=>{
const r = R*1.20, z = R*1.20*Math.sin(THREE.MathUtils.degToRad(lat));
const pts=[]; for(let i=0;i<=128;i++){ const a=i/128*Math.PI*2;
pts.push(new THREE.Vector3(Math.cos(a)*r, Math.sin(a)*r, z)); }
mk(pts);
};
ring(0); ring(23.44); ring(-23.44); ring(66.56); ring(-66.56);
// meridians
for (const lon of [0,90,180,270]){
const pts=[];
for(let i=0;i<=64;i++){
const lat = THREE.MathUtils.degToRad(-84 + 168*i/64);
const d = latLonDir(lat, lon).multiplyScalar(R*1.20);
pts.push(d);
}
mk(pts);
}
})();
/* ============================================================
Sun, ecliptic, axis, terminator, declination arc
============================================================ */
const sunMesh = new THREE.Mesh(new THREE.SphereGeometry(0.52, 32, 24),
new THREE.MeshBasicMaterial({ color:0xfff3d0 }));
scene.add(sunMesh);
const sunGlow = new THREE.Sprite(new THREE.SpriteMaterial({
map: radialTex('rgba(255,248,220,1)','rgba(255,196,110,.55)'),
blending: THREE.AdditiveBlending, depthWrite:false, transparent:true }));
sunGlow.scale.set(4.6,4.6,1);
scene.add(sunGlow);
const miniSunTex = radialTex('rgba(255,250,225,1)','rgba(255,200,120,.6)');
/* ecliptic ring */
const ecliptic = (()=>{
const pts=[]; for(let i=0;i<=180;i++){ const a=i/180*Math.PI*2;
pts.push(new THREE.Vector3(Math.cos(a)*SUN_R, Math.sin(a)*SUN_R, 0)); }
const l = new THREE.Line(new THREE.BufferGeometry().setFromPoints(pts),
new THREE.LineDashedMaterial({ color:0xffc887, transparent:true, opacity:.35,
dashSize:.35, gapSize:.28, depthTest:false }));
l.computeLineDistances(); l.renderOrder=3; scene.add(l); return l;
})();
const eclipticLabel = new Label('ECLIPTIC PLANE', { color:'#ffcf9a', size:30, worldH:0.24 });
eclipticLabel.sprite.position.set(0, SUN_R*0.99, 0); scene.add(eclipticLabel.sprite);
/* polar axis */
const axisDir = new THREE.Vector3(Math.sin(EPS), 0, Math.cos(EPS));
const axisLine = (()=>{
const g = new THREE.BufferGeometry().setFromPoints([
axisDir.clone().multiplyScalar(-R*1.34), axisDir.clone().multiplyScalar(R*1.34)]);
const l = new THREE.Line(g, new THREE.LineDashedMaterial({ color:0x9fd8ff,
transparent:true, opacity:.6, dashSize:.14, gapSize:.10, depthTest:false }));
l.computeLineDistances(); l.renderOrder=5; scene.add(l); return l;
})();
const axisTip = new THREE.Mesh(new THREE.ConeGeometry(0.11,0.3,12),
new THREE.MeshBasicMaterial({ color:0xbfe6ff }));
axisTip.position.copy(axisDir).multiplyScalar(R*1.40); axisTip.quaternion.setFromUnitVectors(
new THREE.Vector3(0,1,0), axisDir); scene.add(axisTip);
const axisLabel = new Label('POLAR AXIS', { color:'#bfe6ff', size:28, worldH:0.2 });
axisLabel.sprite.position.copy(axisDir).multiplyScalar(R*1.55).add(new THREE.Vector3(0,0,.25));
scene.add(axisLabel.sprite);
/* tilt arc between ecliptic normal (world +Z) and the axis */
const tiltArc = (()=>{
const pts=[]; const N=28, rad=1.62;
for(let i=0;i<=N;i++){
const t=i/N, a = t*EPS;
pts.push(new THREE.Vector3(Math.sin(a)*rad, 0, Math.cos(a)*rad));
}
const l = new THREE.Line(new THREE.BufferGeometry().setFromPoints(pts),
new THREE.LineBasicMaterial({ color:0xffd9a0, transparent:true, opacity:.75, depthTest:false }));
l.renderOrder=6; scene.add(l); return l;
})();
const tiltLabel = new Label('23.44° AXIAL TILT', { color:'#ffd9a0', size:28, worldH:0.2 });
tiltLabel.sprite.position.set(Math.sin(EPS*0.5)*1.95, 0, Math.cos(EPS*0.5)*1.95);
scene.add(tiltLabel.sprite);
/* terminator (great circle perpendicular to sun) */
const terminator = (()=>{
const g = new THREE.BufferGeometry();
g.setAttribute('position', new THREE.BufferAttribute(new Float32Array(129*3), 3));
const l = new THREE.Line(g, new THREE.LineDashedMaterial({ color:0x9fe8ff,
transparent:true, opacity:.55, dashSize:.09, gapSize:.07, depthTest:false }));
l.renderOrder=5; scene.add(l); return l;
})();
/* subsolar point */
const subSolar = new THREE.Mesh(new THREE.SphereGeometry(0.075, 16, 12),
new THREE.MeshBasicMaterial({ color:0xfff0c0 }));
scene.add(subSolar);
const subLabel = new Label('SUBSOLAR POINT', { color:'#ffe9bd', size:26, worldH:0.17 });
scene.add(subLabel.sprite);
/* parallel sunlight bundle */
const RAY_COUNT = 9;
const rayGeo = new THREE.BufferGeometry();
rayGeo.setAttribute('position', new THREE.BufferAttribute(new Float32Array(RAY_COUNT*2*3), 3));
const rays = new THREE.LineSegments(rayGeo, new THREE.LineBasicMaterial({
color:0xffd79a, transparent:true, opacity:.5, depthTest:false }));
rays.renderOrder = 2; scene.add(rays);
/* declination arc on the globe (equatorial plane -> sun direction) */
const declArc = (()=>{
const g = new THREE.BufferGeometry();
g.setAttribute('position', new THREE.BufferAttribute(new Float32Array(33*3), 3));
const l = new THREE.Line(g, new THREE.LineBasicMaterial({ color:0xffc46b,
transparent:true, opacity:.9, depthTest:false }));
l.renderOrder = 6; earth.add(l); return l;
})();
const declLabel = new Label('δ', { color:'#ffc46b', size:40, worldH:0.26, weight:700 });
earth.add(declLabel.sprite);
/* ============================================================
Voxel garden builder
============================================================ */
const VS = 0.075; // plant voxel size
const PAD = 9, SP = 0.19; // pad grid
function buildGarden(g){
const dir = latLonDir(g.lat, g.lon);
const { east, north } = basisFor(dir);
const group = new THREE.Group();
group.quaternion.setFromRotationMatrix(new THREE.Matrix4().makeBasis(east, north, dir));
group.position.copy(dir).multiplyScalar(R + 0.33);
earth.add(group);
const accent = new THREE.Color(g.accent);
/* ---- soil pad ---- */
const soilGeo = new THREE.BoxGeometry(SP*0.94, SP*0.94, 0.13);
const soilMat = new THREE.MeshLambertMaterial({ color:0xffffff, emissive:0x1a1208 });
const soil = new THREE.InstancedMesh(soilGeo, soilMat, PAD*PAD);
const m4 = new THREE.Matrix4();
const soilColors = [];
for (let i=0;i<PAD;i++) for (let j=0;j<PAD;j++){
const k = i*PAD+j;
const x = (i-(PAD-1)/2)*SP, y = (j-(PAD-1)/2)*SP;
const hgt = 1 + (hash(i*3.3,j*1.9,k)*0.5-0.25)*0.45;
m4.compose(new THREE.Vector3(x,y,0.065*hgt), new THREE.Quaternion(),
new THREE.Vector3(1,1,hgt));
soil.setMatrixAt(k,m4);
soilColors.push(hash(i*7.1,j*5.7,k*2.3));
}
group.add(soil);
/* ---- plants: stem + leaf voxels ---- */
const plantDefs = [];
for (let i=0;i<PAD;i++) for (let j=0;j<PAD;j++){
const k=i*PAD+j;
if (hash(i*11.3,j*13.7,k*3.1) > 0.52) continue; // sparse planting
const x=(i-(PAD-1)/2)*SP + (hash(i,j,k)-0.5)*0.05;
const y=(j-(PAD-1)/2)*SP + (hash(j,k,i)-0.5)*0.05;
const maxVox = 3 + Math.floor(hash(k*1.7,i*2.3,j*4.1)*5);
const vigour = 0.62 + hash(k*9.1,i*1.3,j*2.7)*0.38;
const leaves = [];
for(let v=1;v<maxVox;v++){
if (hash(v*3.1,k*7.7,i*2.9) > 0.45){
const dirv = Math.floor(hash(v*5.3,k*3.1,j)*4);
leaves.push({ v, dx: dirv===0?1:dirv===1?-1:0, dy: dirv===2?1:dirv===3?-1:0 });
}
}
plantDefs.push({ x, y, maxVox, vigour, leaves });
}
const total = plantDefs.reduce((s,p)=>s+p.maxVox+p.leaves.length, 0);
const plantGeo = new THREE.BoxGeometry(VS*0.92, VS*0.92, VS*0.92);
const plantMat = new THREE.MeshLambertMaterial({ color:0xffffff, emissive:0x0a1608 });
const plants = new THREE.InstancedMesh(plantGeo, plantMat, total);
const pColor = new THREE.Color();
plants.instanceColor = new THREE.InstancedBufferAttribute(new Float32Array(total*3), 3);
group.add(plants);
// pre-compute voxel slots
const slots = [];
plantDefs.forEach((p,pi)=>{
for(let v=0; v<p.maxVox; v++) slots.push({ p, pi, v, leaf:false });
p.leaves.forEach(l=>slots.push({ p, pi, v:l.v, leaf:true }));
});
/* ---- frost voxels ---- */
const frostN = 70;
const frost = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.055,0.055,0.055),
new THREE.MeshLambertMaterial({ color:0xe8f4ff, emissive:0x334455 }), frostN);
const frostPos = [];
for(let k=0;k<frostN;k++){
const x=(hash(k*3.7,1,2)-0.5)*SP*(PAD-1), y=(hash(k*1.3,5,9)-0.5)*SP*(PAD-1);
frostPos.push({x,y,z:0.14+hash(k,2,3)*0.05, r:hash(k*2.2,1,1)});
m4.compose(new THREE.Vector3(x,y,frostPos[k].z), new THREE.Quaternion(), new THREE.Vector3(0,0,0));
frost.setMatrixAt(k,m4);
}
group.add(frost);
/* ---- under-glow + light shaft ---- */
const halo = new THREE.Mesh(new THREE.CircleGeometry(1.15, 48),
new THREE.MeshBasicMaterial({ color:accent, transparent:true, opacity:.13,
blending:THREE.AdditiveBlending, depthWrite:false, side:THREE.DoubleSide }));
halo.position.z = -0.26; halo.rotation.x = Math.PI/2; group.add(halo);
const shaft = new THREE.Mesh(new THREE.CylinderGeometry(0.62,0.30,0.30,24,1,true),
new THREE.MeshBasicMaterial({ color:accent, transparent:true, opacity:.10,
blending:THREE.AdditiveBlending, depthWrite:false, side:THREE.DoubleSide }));
shaft.position.z = -0.15; group.add(shaft);
/* ---- local solar geometry diagram ---- */
const horizon = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.85,0,0), new THREE.Vector3(0.85,0,0)]),
new THREE.LineDashedMaterial({ color:0x9fd8ff, transparent:true, opacity:.45,
dashSize:.07, gapSize:.06, depthTest:false }));
horizon.computeLineDistances(); horizon.renderOrder=6; group.add(horizon);
const rayGeo = new THREE.BufferGeometry();
rayGeo.setAttribute('position', new THREE.BufferAttribute(new Float32Array(2*3), 3));
const noonRay = new THREE.Line(rayGeo, new THREE.LineBasicMaterial({
color:0xffd79a, transparent:true, opacity:.95, depthTest:false }));
noonRay.renderOrder=7; group.add(noonRay);
const noonSun = new THREE.Sprite(new THREE.SpriteMaterial({
map:miniSunTex, blending:THREE.AdditiveBlending, depthWrite:false, transparent:true }));
noonSun.scale.set(0.42,0.42,1); group.add(noonSun);
const arcGeo = new THREE.BufferGeometry();
arcGeo.setAttribute('position', new THREE.BufferAttribute(new Float32Array(25*3), 3));
const elevArc = new THREE.Line(arcGeo, new THREE.LineBasicMaterial({
color:0xffd79a, transparent:true, opacity:.9, depthTest:false }));
elevArc.renderOrder=7; group.add(elevArc);
const nameLabel = new Label(g.name, { color:'#eaf4fb', size:32, worldH:0.24, weight:600,
glow:'rgba(0,0,0,.9)' });
nameLabel.sprite.position.set(0,0,1.05); group.add(nameLabel.sprite);
const illuLabel = new Label('▨ growth = illustrative', { color:'#9fb4c4', size:26,
worldH:0.17 }); illuLabel.sprite.position.set(0,0,0.62); group.add(illuLabel.sprite);
const elevLabel = new Label('', { color:'#ffdca8', size:26, worldH:0.17 });
elevLabel.sprite.position.set(0,0,0.95); group.add(elevLabel.sprite);
return { ...g, group, soil, soilColors, plants, slots, plantDefs, frost, frostPos,
noonRay, noonSun, elevArc, elevLabel, dir, east, north,
growth:0.42, target:0.42, proxy:0, elev:0, dayLen:12, noonSunLocal:new THREE.Vector3() };
}
const gardens = GARDENS.map(buildGarden);
/* ============================================================
Stars
============================================================ */
(function stars(){
const N = 1400, pos = new Float32Array(N*3), col = new Float32Array(N*3);
const c = new THREE.Color();
for(let i=0;i<N;i++){
const u = Math.random()*2-1, th = Math.random()*Math.PI*2, s = Math.sqrt(1-u*u);
const r = 60 + Math.random()*70;
pos[i*3]=s*Math.cos(th)*r; pos[i*3+1]=s*Math.sin(th)*r; pos[i*3+2]=u*r;
c.setHSL(0.55 + Math.random()*0.12, 0.35, 0.55 + Math.random()*0.4);
col[i*3]=c.r; col[i*3+1]=c.g; col[i*3+2]=c.b;
}
const g = new THREE.BufferGeometry();
g.setAttribute('position', new THREE.BufferAttribute(pos,3));
g.setAttribute('color', new THREE.BufferAttribute(col,3));
const p = new THREE.Points(g, new THREE.PointsMaterial({ size:0.55, vertexColors:true,
transparent:true, opacity:.85, sizeAttenuation:true }));
scene.add(p);
})();
/* ============================================================
Camera controls (implemented inline — no addons)
============================================================ */
const cam = { az:0, el:0.18, dist:13.2 };
let dragging=false, lastX=0, lastY=0, autoOrbit=true, userTouch=0;
renderer.domElement.addEventListener('pointerdown', e=>{
dragging=true; lastX=e.clientX; lastY=e.clientY; userTouch=performance.now();
renderer.domElement.setPointerCapture(e.pointerId);
});
addEventListener('pointermove', e=>{
if(!dragging) return;
cam.az -= (e.clientX-lastX)*0.005;
cam.el = clamp(cam.el + (e.clientY-lastY)*0.005, -1.25, 1.25);
lastX=e.clientX; lastY=e.clientY; userTouch=performance.now();
});
addEventListener('pointerup', ()=>{ dragging=false; });
renderer.domElement.addEventListener('wheel', e=>{
e.preventDefault();
cam.dist = clamp(cam.dist * (1 + Math.sign(e.deltaY)*0.08), 6.5, 42);
}, { passive:false });
function applyCamera(){
const d = new THREE.Vector3(
Math.cos(cam.el)*Math.sin(cam.az), -Math.cos(cam.el)*Math.cos(cam.az), Math.sin(cam.el));
camera.position.copy(d).multiplyScalar(cam.dist);
camera.lookAt(0,0,0);
}
/* default view: look along the bisector of the two gardens */
(function initialView(){
const a = gardens[0].group.getWorldPosition(new THREE.Vector3());
const b = gardens[1].group.getWorldPosition(new THREE.Vector3());
const d = a.clone().add(b).normalize();
cam.az = Math.atan2(d.x, -d.y);
cam.el = Math.asin(clamp(d.z,-1,1)) + 0.06;
cam.dist = 13.2;
})();
/* ============================================================
Seasonal model
============================================================ */
let theta = 0; // 0 = June solstice (sun toward +X, δ max north)
let playing = true, speed = 1;
const YEAR_SECONDS = 46;
const sunDir = new THREE.Vector3();
const sunLocal = new THREE.Vector3();
function updateSun(){
sunDir.set(Math.cos(theta), Math.sin(theta), 0);
const sp = sunDir.clone().multiplyScalar(SUN_R);
sunMesh.position.copy(sp);
sunGlow.position.copy(sp);
sunLight.position.copy(sp);
globeMat.uniforms.uSun.value.copy(sunDir);
earth.updateMatrixWorld();
// earth-local sun direction
sunLocal.copy(sunDir).applyAxisAngle(new THREE.Vector3(0,1,0), -EPS);
}
/* declination δ = angle above the equatorial plane */
function declination(){ return Math.asin(clamp(sunLocal.dot(P), -1, 1)); }
/* hour angle → day length, noon elevation */
function solar(phiDeg, dec){
const phi = THREE.MathUtils.degToRad(phiDeg);
const c = -Math.tan(phi)*Math.tan(dec);
const H = Math.acos(clamp(c,-1,1));
const elev = Math.PI/2 - Math.abs(phi - dec);
return { hours: 24*H/Math.PI, elev: elev*DEG, elevRad: elev, H };
}
/* illustrative daily-light proxy (normalised 0..1) */
function proxyOf(hours, elevDeg){
const p = (hours/24) * Math.max(0, Math.sin(THREE.MathUtils.degToRad(elevDeg)));
return clamp((p-0.07)/(0.63-0.07), 0, 1);
}
/* ============================================================
Garden update (growth + local solar diagram)
============================================================ */
const tmpM = new THREE.Matrix4(), tmpQ = new THREE.Quaternion(),
tmpP = new THREE.Vector3(), tmpS = new THREE.Vector3();
const stemCol = new THREE.Color(), leafCol = new THREE.Color(),
dormant = new THREE.Color(0.47,0.35,0.22), stemC = new THREE.Color(0.22,0.60,0.26),
leafC = new THREE.Color(0.45,0.82,0.36);
function updateGarden(g, dec){
const phi = THREE.MathUtils.degToRad(g.lat);
const lam = THREE.MathUtils.degToRad(g.lon);
// solar-noon sun direction in earth-local coords
const sNoon = new THREE.Vector3(Math.cos(dec)*Math.cos(lam), Math.cos(dec)*Math.sin(lam), Math.sin(dec));
g.noonSunLocal.copy(sNoon);
const e = sNoon.dot(g.east), n = sNoon.dot(g.north), u = sNoon.dot(g.dir);
g.elev = Math.asin(clamp(u,-1,1))*DEG;
const s = solar(g.lat, dec);
g.dayLen = s.hours;
g.proxy = proxyOf(s.hours, s.elev);
g.target = g.proxy;
/* ---- grow / shrink ---- */
g.growth += (g.target - g.growth) * 0.035;
/* ---- soil colouring by season ---- */
const lush = clamp(g.growth*1.2, 0, 1);
for (let k=0;k<g.soil.count;k++){
const v = g.soilColors[k];
const r = THREE.MathUtils.lerp(0.30, 0.34, lush) * (0.82+v*0.36);
const gg= THREE.MathUtils.lerp(0.24, 0.30, lush) * (0.82+v*0.36);
const b = THREE.MathUtils.lerp(0.20, 0.17, lush) * (0.82+v*0.36);
g.soil.setColorAt(k, new THREE.Color(r,gg,b));
}
if (g.soil.instanceColor) g.soil.instanceColor.needsUpdate = true;
/* ---- plants ---- */
const slots = g.slots;
for (let i=0;i<slots.length;i++){
const sl = slots[i];
const gp = clamp(g.growth * sl.p.vigour, 0, 1);
const frac = sl.v / sl.p.maxVox;
const vis = frac < gp * 0.98 + 0.02;
const x = sl.p.x + (sl.leaf ? sl.leaf.dx*VS*0.92 : 0);
const y = sl.p.y + (sl.leaf ? sl.leaf.dy*VS*0.92 : 0);
const z = 0.135 + (sl.v+0.5)*VS;
if (vis){
tmpP.set(x,y,z); tmpS.set(1,1,1);
} else {
tmpP.set(x,y,z); tmpS.set(0,0,0);
}
tmpM.compose(tmpP, tmpQ, tmpS);
g.plants.setMatrixAt(i, tmpM);
const c = sl.leaf ? leafC : stemC;
stemCol.copy(dormant).lerp(c, clamp(gp*1.35,0,1));
g.plants.setColorAt(i, stemCol);
}
g.plants.instanceMatrix.needsUpdate = true;
if (g.plants.instanceColor) g.plants.instanceColor.needsUpdate = true;
/* ---- frost ---- */
const fk = clamp(1 - g.growth*2.1, 0, 1);
for (let k=0;k<g.frostPos.length;k++){
const f = g.frostPos[k];
const sc = fk * (f.r > fk ? 0 : 1);
tmpP.set(f.x, f.y, f.z); tmpS.set(sc,sc,sc);
tmpM.compose(tmpP, tmpQ, tmpS);
g.frost.setMatrixAt(k, tmpM);
}
g.frost.instanceMatrix.needsUpdate = true;
/* ---- local solar diagram ---- */
const L = 1.45;
const rp = g.noonRay.geometry.attributes.position;
rp.setXYZ(0, 0,0,0);
rp.setXYZ(1, e*L, n*L, u*L);
rp.needsUpdate = true;
g.noonSun.position.set(e*L, n*L, u*L);
// elevation arc in the local meridian plane
const ap = g.elevArc.geometry.attributes.position;
const hs = n >= 0 ? 1 : -1;
const ar = 0.86;
for (let i=0;i<=24;i++){
const a = (i/24) * (s.elevRad);
ap.setXYZ(i, 0, Math.cos(a)*hs*ar, Math.sin(a)*ar);
}
ap.needsUpdate = true;
g.elevLabel.set(`${g.elev.toFixed(0)}° noon elevation · δ ${(dec*DEG>=0?'+':'−')}${Math.abs(dec*DEG).toFixed(1)}°`);
g.elevLabel.sprite.position.set(0, Math.cos(s.elevRad)*hs*0.95 - 0.12, Math.sin(s.elevRad)*0.95 + 0.06);
}
/* ============================================================
Globals update (terminator, rays, declination arc)
============================================================ */
const _u = new THREE.Vector3(), _v = new THREE.Vector3();
function updateGlobals(){
// terminator great circle (perp to sun)
_u.set(0,0,1).cross(sunDir);
if (_u.lengthSq() < 1e-6) _u.set(1,0,0);
_u.normalize(); _v.crossVectors(sunDir,_u).normalize();
const tp = terminator.geometry.attributes.position;
const rad = R*1.21;
for (let i=0;i<=128;i++){
const a = i/128*Math.PI*2;
tp.setXYZ(i, (_u.x*Math.cos(a)+_v.x*Math.sin(a))*rad,
(_u.y*Math.cos(a)+_v.y*Math.sin(a))*rad,
(_u.z*Math.cos(a)+_v.z*Math.sin(a))*rad);
}
tp.needsUpdate = true; terminator.computeLineDistances();
// parallel sunlight bundle
_u.set(0,0,1).cross(sunDir); if (_u.lengthSq()<1e-6) _u.set(1,0,0);
_u.normalize(); _v.crossVectors(sunDir,_u).normalize();
const offs = [[0,0],[-.62,0],[.62,0],[0,-.62],[0,.62],[-.45,-.45],[.45,.45],[-.95,.2],[.95,-.2]];
const rp = rays.geometry.attributes.position;
for (let i=0;i<RAY_COUNT;i++){
const [ox,oy] = offs[i % offs.length];
const start = new THREE.Vector3().copy(sunDir).multiplyScalar(SUN_R)
.addScaledVector(_u, ox).addScaledVector(_v, oy);
const disc = R*R - (start.lengthSq() - SUN_R*SUN_R);
const t = SUN_R - Math.sqrt(Math.max(disc, 0));
const end = start.clone().addScaledVector(sunDir, -t);
rp.setXYZ(i*2, start.x, start.y, start.z);
rp.setXYZ(i*2+1, end.x, end.y, end.z);
}
rp.needsUpdate = true;
// subsolar marker
subSolar.position.copy(sunDir).multiplyScalar(R*1.26);
subLabel.sprite.position.copy(sunDir).multiplyScalar(R*1.42).add(new THREE.Vector3(0,0,0.12));
// declination arc (equatorial plane -> sun direction) in earth-local space
const q = new THREE.Vector3().copy(sunLocal).addScaledVector(P, -sunLocal.dot(P));
if (q.lengthSq() < 1e-8) q.set(1,0,0);
q.normalize();
const dp = declArc.geometry.attributes.position;
const arcRadius = 1.30;
for (let i=0;i<=32;i++){
const t = i/32;
const v = new THREE.Vector3().copy(q).multiplyScalar(Math.cos(t*Math.acos(clamp(q.dot(sunLocal),-1,1))))
.addScaledVector(sunLocal, Math.sin(t*Math.acos(clamp(q.dot(sunLocal),-1,1))));
dp.setXYZ(i, v.x*arcRadius, v.y*arcRadius, v.z*arcRadius);
}
dp.needsUpdate = true;
const mid = new THREE.Vector3().copy(q).multiplyScalar(Math.cos(Math.acos(clamp(q.dot(sunLocal),-1,1))/2))
.addScaledVector(sunLocal, Math.sin(Math.acos(clamp(q.dot(sunLocal),-1,1))/2));
declLabel.sprite.position.copy(mid).multiplyScalar(1.62);
declLabel.set(`δ ${sunLocal.dot(P)*DEG>=0?'+':'−'}${Math.abs(sunLocal.dot(P)*DEG).toFixed(1)}°`);
}
/* ============================================================
HUD
============================================================ */
const $ = id => document.getElementById(id);
const MONTH = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
function dayOfYear(theta){ return (172 + theta*DEG/360*365) % 365; }
function seasonFor(doy){
if (doy < 79) return ['Northern winter','Southern summer'];
if (doy < 172) return ['Northern spring','Southern autumn'];
if (doy < 264) return ['Northern summer','Southern winter'];
if (doy < 354.5) return ['Northern autumn','Southern spring'];
return ['Northern winter','Southern summer'];
}
function updateHUD(dec){
const doy = dayOfYear(theta);
const dt = new Date(Date.UTC(2025,0,1) + Math.floor(doy)*86400000);
$('date').textContent = `${MONTH[dt.getUTCMonth()]} ${dt.getUTCDate()}`;
const [ns,ss] = seasonFor(doy);
$('season').textContent = `${ns} · ${ss}`;
$('decl').textContent = `declination δ ${dec*DEG>=0?'+':'−'}${Math.abs(dec*DEG).toFixed(1)}° · axial tilt 23.44°`;
const n = gardens[0], s = gardens[1];
$('n-season').textContent = ns;
$('s-season').textContent = ss;
$('n-elev').textContent = `${n.elev.toFixed(1)}°`;
$('s-elev').textContent = `${s.elev.toFixed(1)}°`;
$('n-len').textContent = `${n.dayLen.toFixed(1)} h`;
$('s-len').textContent = `${s.dayLen.toFixed(1)} h`;
$('n-prox').textContent = `${(n.proxy*100).toFixed(0)} %`;
$('s-prox').textContent = `${(s.proxy*100).toFixed(0)} %`;
$('n-grow').textContent = `${(n.growth*100).toFixed(0)} %`;
$('s-grow').textContent = `${(s.growth*100).toFixed(0)} %`;
$('n-bar').style.width = `${(n.growth*100).toFixed(1)}%`;
$('s-bar').style.width = `${(s.growth*100).toFixed(1)}%`;
const dg = (n.growth - s.growth)*100;
const dp = (n.proxy - s.proxy)*100;
$('lead').textContent = dg >= 0 ? `North +${dg.toFixed(0)} pts` : `South +${(-dg).toFixed(0)} pts`;
$('gap').textContent = dp >= 0 ? `North +${dp.toFixed(0)} % light` : `South +${(-dp).toFixed(0)} % light`;
}
/* ---------------- controls ---------------- */
$('play').onclick = e => { playing = !playing; e.target.textContent = playing ? '⏸ Pause' : '▶ Play';
e.target.classList.toggle('on', !playing); };
$('speed').onclick = e => { speed = speed===1 ? 2 : speed===2 ? 0.5 : 1;
e.target.textContent = `${speed}×`; };
document.querySelectorAll('[data-jump]').forEach(b=>{
b.onclick = ()=>{ theta = THREE.MathUtils.degToRad(parseFloat(b.dataset.jump)); };
});
$('orbit').onclick = e => { autoOrbit = !autoOrbit; e.target.classList.toggle('on', autoOrbit); };
$('orbit').classList.add('on');
$('reset').onclick = ()=>{
const a = gardens[0].group.getWorldPosition(new THREE.Vector3());
const b = gardens[1].group.getWorldPosition(new THREE.Vector3());
const d = a.clone().add(b).normalize();
cam.az = Math.atan2(d.x,-d.y);
cam.el = Math.asin(clamp(d.z,-1,1)) + 0.06;
cam.dist = 13.2;
};
addEventListener('resize', ()=>{
camera.aspect = innerWidth/innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
/* ============================================================
Loop
============================================================ */
const clock = new THREE.Clock();
function animate(){
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (playing) theta = (theta + dt * (Math.PI*2/YEAR_SECONDS) * speed) % (Math.PI*2);
if (autoOrbit && !dragging && (performance.now()-userTouch) > 3500) cam.az += dt*0.035;
applyCamera();
updateSun();
const dec = declination();
updateGlobals();
gardens.forEach(g=>updateGarden(g, dec));
updateHUD(dec);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```