Prompt specification
Build or customize the Three.js 3D scene "Opposite-hemisphere season 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: Opposite-hemisphere season comparison
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/opposite-hemisphere-season-comparison-x0780
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing seasonal deciduous foliage. Create two labeled schematic courtyards in opposite hemispheres; a calendar control offsets their temperate seasonal cycles while captions explain that local climate and species still matter. Voxel style.
Working Three.js Starter (opposite-hemisphere-season-comparison-x0780):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Seasons — Opposite Hemispheres</title>
<style>
:root {
--ink: #173b33;
--muted: #60736b;
--paper: rgba(250, 249, 240, 0.9);
--line: rgba(23, 59, 51, 0.16);
--spring: #78a95b;
--summer: #2f7546;
--autumn: #d47a32;
--winter: #87918d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce7df;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#scene.dragging {
cursor: grabbing;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #dce7df;
color: var(--ink);
font-size: 13px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
pointer-events: none;
}
#loading.hidden {
opacity: 0;
}
.hero {
position: fixed;
z-index: 4;
top: 28px;
left: 30px;
max-width: 470px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 12px;
color: #47685d;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 20px;
height: 7px;
border-radius: 1px;
background: var(--ink);
box-shadow:
7px 0 0 rgba(23, 59, 51, 0.4),
14px 0 0 rgba(23, 59, 51, 0.18);
}
h1 {
margin: 0;
font-size: clamp(34px, 4.2vw, 61px);
line-height: 0.98;
letter-spacing: -0.055em;
font-weight: 760;
}
h1 em {
color: #b65f31;
font-family: Georgia, "Times New Roman", serif;
font-weight: 500;
}
.hero p {
max-width: 390px;
margin: 15px 0 0;
color: #526d63;
font-size: 14px;
line-height: 1.55;
}
.legend {
position: fixed;
z-index: 4;
top: 31px;
right: 30px;
display: flex;
gap: 16px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(250, 249, 240, 0.62);
backdrop-filter: blur(12px);
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--swatch);
}
.world-label {
position: fixed;
z-index: 5;
display: flex;
align-items: center;
gap: 10px;
min-width: 210px;
padding: 10px 13px;
transform: translate(-50%, -100%);
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 10px;
background: rgba(249, 248, 237, 0.82);
box-shadow: 0 9px 25px rgba(37, 65, 55, 0.12);
backdrop-filter: blur(10px);
pointer-events: none;
}
.world-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 19px;
background: rgba(23, 59, 51, 0.36);
}
.season-dot {
flex: 0 0 auto;
width: 12px;
height: 12px;
border-radius: 3px;
background: var(--season-color, var(--spring));
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.world-label strong {
display: block;
font-size: 10px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.world-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 11px;
}
.compact-label {
display: none;
}
.controls {
position: fixed;
z-index: 10;
left: 50%;
bottom: 20px;
width: min(880px, calc(100% - 32px));
padding: 17px 19px 15px;
transform: translateX(-50%);
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 15px;
background: var(--paper);
box-shadow:
0 18px 55px rgba(28, 61, 49, 0.16),
0 2px 8px rgba(28, 61, 49, 0.06);
backdrop-filter: blur(18px);
}
.control-main {
display: grid;
grid-template-columns: 48px 118px 1fr;
align-items: center;
gap: 15px;
}
#play {
width: 44px;
height: 44px;
border: 0;
border-radius: 9px;
background: var(--ink);
color: #fffef4;
cursor: pointer;
font-size: 16px;
transition:
transform 150ms ease,
background 150ms ease;
}
#play:hover {
transform: translateY(-1px);
background: #245448;
}
#play:active {
transform: translateY(1px);
}
.month-readout {
min-width: 0;
}
.month-readout small,
.range-label {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#monthName {
display: block;
margin-top: 2px;
font-size: 20px;
line-height: 1;
letter-spacing: -0.025em;
}
.range-wrap {
min-width: 0;
}
.range-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
}
#monthIndex {
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
--fill: 25%;
width: 100%;
height: 5px;
margin: 0;
border-radius: 5px;
outline: none;
appearance: none;
background: linear-gradient(
to right,
var(--ink) 0,
var(--ink) var(--fill),
rgba(23, 59, 51, 0.15) var(--fill),
rgba(23, 59, 51, 0.15) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #fffef4;
border-radius: 50%;
appearance: none;
background: var(--ink);
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #fffef4;
border-radius: 50%;
background: var(--ink);
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
}
.offset-row {
display: grid;
grid-template-columns: 205px 1fr 83px;
align-items: center;
gap: 14px;
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
.offset-title {
font-size: 11px;
font-weight: 700;
}
.offset-title small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 500;
}
#offsetValue {
padding: 5px 7px;
border-radius: 6px;
background: rgba(23, 59, 51, 0.07);
text-align: center;
font-size: 10px;
font-weight: 750;
font-variant-numeric: tabular-nums;
}
.status-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 13px;
}
.status-card {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
min-width: 0;
padding: 9px 11px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.34);
}
.status-card > span:first-child {
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.status-result {
display: flex;
align-items: center;
gap: 7px;
white-space: nowrap;
font-size: 11px;
font-weight: 750;
}
.status-result i {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--season-color);
}
.note {
margin: 12px 2px 0;
color: #62746d;
font-size: 10px;
line-height: 1.45;
}
.note strong {
color: var(--ink);
letter-spacing: 0.08em;
text-transform: uppercase;
}
.camera-hint {
position: fixed;
z-index: 4;
right: 25px;
bottom: 27px;
color: rgba(23, 59, 51, 0.63);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 1050px) {
.camera-hint {
display: none;
}
.legend {
top: auto;
right: 22px;
bottom: 26px;
}
}
@media (max-width: 700px) {
.hero {
top: 18px;
left: 18px;
}
.hero h1 {
font-size: 35px;
}
.hero p {
max-width: 290px;
font-size: 12px;
}
.legend {
display: none;
}
.world-label {
min-width: 0;
padding: 7px 9px;
}
.wide-label {
display: none;
}
.compact-label {
display: inline;
}
.world-label small {
font-size: 9px;
}
.controls {
bottom: 10px;
width: calc(100% - 20px);
padding: 13px;
}
.control-main {
grid-template-columns: 42px 88px 1fr;
gap: 10px;
}
#play {
width: 39px;
height: 39px;
}
#monthName {
font-size: 17px;
}
.offset-row {
grid-template-columns: 125px 1fr 68px;
gap: 9px;
}
.offset-title {
font-size: 9px;
}
.offset-title small {
display: none;
}
.status-card {
padding: 8px;
}
.status-card > span:first-child {
font-size: 8px;
}
.status-result {
font-size: 9px;
}
}
@media (max-width: 430px) {
.hero p {
display: none;
}
.eyebrow {
margin-bottom: 8px;
}
.control-main {
grid-template-columns: 38px 76px 1fr;
}
.status-card {
align-items: flex-start;
flex-direction: column;
gap: 4px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive voxel scene showing deciduous courtyards in northern and southern hemispheres"
></canvas>
<div id="loading">Building voxel courtyards…</div>
<header class="hero">
<div class="eyebrow">Voxel phenology / 01</div>
<h1>Two courtyards,<br /><em>six months apart.</em></h1>
<p>
A schematic temperate calendar: move through the year to watch spring,
summer, autumn, and bare winter shift between opposite hemispheres.
</p>
</header>
<aside class="legend" aria-hidden="true">
<span><i style="--swatch:#78a95b"></i>Spring</span>
<span><i style="--swatch:#2f7546"></i>Summer</span>
<span><i style="--swatch:#d47a32"></i>Autumn</span>
<span><i style="--swatch:#87918d"></i>Bare</span>
</aside>
<div id="northLabel" class="world-label">
<span class="season-dot" id="northDot"></span>
<div>
<strong>
<span class="wide-label">Northern Hemisphere</span>
<span class="compact-label">North</span>
</strong>
<small id="northWorldSeason">April · Spring</small>
</div>
</div>
<div id="southLabel" class="world-label">
<span class="season-dot" id="southDot"></span>
<div>
<strong>
<span class="wide-label">Southern Hemisphere</span>
<span class="compact-label">South</span>
</strong>
<small id="southWorldSeason">October · Autumn</small>
</div>
</div>
<section class="controls" aria-label="Seasonal calendar controls">
<div class="control-main">
<button id="play" type="button" aria-label="Pause calendar">
<span id="playGlyph" aria-hidden="true">❚❚</span>
</button>
<div class="month-readout">
<small>Northern calendar</small>
<strong id="monthName">April</strong>
</div>
<div class="range-wrap">
<div class="range-heading">
<label class="range-label" for="calendar">Calendar month</label>
<span id="monthIndex">04 / 12</span>
</div>
<input
id="calendar"
type="range"
min="0"
max="11.99"
step="0.01"
value="3.2"
aria-label="Calendar month"
/>
</div>
</div>
<div class="offset-row">
<div class="offset-title">
Southern phase offset
<small>Compare the hemispheric shift</small>
</div>
<input
id="offset"
type="range"
min="0"
max="6"
step="1"
value="6"
aria-label="Southern hemisphere seasonal phase offset in months"
/>
<output id="offsetValue" for="offset">+6 months</output>
</div>
<div class="status-grid">
<div class="status-card">
<span>Northern hemisphere</span>
<span class="status-result" id="northStatus">
<i id="northStatusDot"></i>
<span>April · Spring</span>
</span>
</div>
<div class="status-card">
<span>Southern hemisphere</span>
<span class="status-result" id="southStatus">
<i id="southStatusDot"></i>
<span>October · Autumn</span>
</span>
</div>
</div>
<p class="note">
<strong>Schematic, not a forecast.</strong>
Opposite temperate regions are commonly offset by about six months, but
local climate, latitude, elevation, rainfall, and deciduous species still
change the timing of budburst, color, and leaf fall.
</p>
</section>
<div class="camera-hint">Drag to orbit · Scroll to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance",
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce7df);
scene.fog = new THREE.Fog(0xdce7df, 34, 72);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
120
);
const cameraTarget = new THREE.Vector3(0, 1.55, 0);
const cameraState = {
theta: 0,
phi: 1.03,
radius: window.innerWidth / window.innerHeight < 0.75 ? 43 : 26,
};
const hemisphereLight = new THREE.HemisphereLight(
0xf2f7ed,
0x71806e,
2.25
);
scene.add(hemisphereLight);
const sun = new THREE.DirectionalLight(0xfff4d8, 3.1);
sun.position.set(-11, 19, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -20;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xcce2e4, 0.85);
fill.position.set(13, 8, -10);
scene.add(fill);
const materials = {
plinth: new THREE.MeshStandardMaterial({
color: 0xb8b5a7,
roughness: 0.95,
}),
soil: new THREE.MeshStandardMaterial({
color: 0x87977c,
roughness: 1,
}),
path: new THREE.MeshStandardMaterial({
color: 0xd4cbb3,
roughness: 0.95,
}),
wall: new THREE.MeshStandardMaterial({
color: 0xd7d1bf,
roughness: 0.95,
}),
bark: new THREE.MeshStandardMaterial({
color: 0x624a36,
roughness: 1,
}),
barkLight: new THREE.MeshStandardMaterial({
color: 0x826047,
roughness: 1,
}),
wood: new THREE.MeshStandardMaterial({
color: 0x9b714c,
roughness: 0.9,
}),
metal: new THREE.MeshStandardMaterial({
color: 0x43554f,
roughness: 0.7,
}),
northAccent: new THREE.MeshStandardMaterial({
color: 0x477e7a,
roughness: 0.85,
}),
southAccent: new THREE.MeshStandardMaterial({
color: 0xb46642,
roughness: 0.85,
}),
shrub: new THREE.MeshStandardMaterial({
color: 0x617b59,
roughness: 1,
}),
};
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function mulberry32(seed) {
return function random() {
let t = (seed += 0x6d2b79f5);
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function mod(value, divisor) {
return ((value % divisor) + divisor) % divisor;
}
// Seasonal keyframes: leaf amount, leaf color, and falling-leaf activity.
const seasonalStyles = [
{ factor: 0.0, color: 0x6c5948, drop: 0.0 },
{ factor: 0.0, color: 0x77836d, drop: 0.0 },
{ factor: 0.25, color: 0x91b96b, drop: 0.0 },
{ factor: 0.75, color: 0x6aa55b, drop: 0.0 },
{ factor: 1.0, color: 0x4f914f, drop: 0.0 },
{ factor: 1.0, color: 0x347b45, drop: 0.0 },
{ factor: 1.0, color: 0x2e7142, drop: 0.0 },
{ factor: 1.0, color: 0x4f8240, drop: 0.05 },
{ factor: 1.0, color: 0xb29b3e, drop: 0.75 },
{ factor: 0.75, color: 0xd3752f, drop: 1.0 },
{ factor: 0.25, color: 0xa64a32, drop: 0.8 },
{ factor: 0.0, color: 0x735443, drop: 0.1 },
];
const months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
const seasonNames = [
"Winter",
"Winter",
"Spring",
"Spring",
"Spring",
"Summer",
"Summer",
"Summer",
"Autumn",
"Autumn",
"Autumn",
"Winter",
];
const seasonColors = {
Winter: "#87918d",
Spring: "#78a95b",
Summer: "#2f7546",
Autumn: "#d47a32",
};
function seasonalState(monthValue) {
const wrapped = mod(monthValue, 12);
const index = Math.floor(wrapped);
const fraction = wrapped - index;
const smooth = fraction * fraction * (3 - 2 * fraction);
const a = seasonalStyles[index];
const b = seasonalStyles[(index + 1) % 12];
return {
factor: THREE.MathUtils.lerp(a.factor, b.factor, smooth),
drop: THREE.MathUtils.lerp(a.drop, b.drop, smooth),
color: new THREE.Color(a.color).lerp(
new THREE.Color(b.color),
smooth
),
};
}
function addBench(group, x, z, rotation, accentMaterial) {
const bench = new THREE.Group();
bench.position.set(x, 0.62, z);
bench.rotation.y = rotation;
group.add(bench);
addBox(bench, [1.65, 0.16, 0.5], [0, 0.42, 0], materials.wood);
addBox(bench, [0.15, 0.48, 0.42], [-0.58, 0.15, 0], materials.metal);
addBox(bench, [0.15, 0.48, 0.42], [0.58, 0.15, 0], materials.metal);
addBox(bench, [0.16, 0.17, 0.5], [-0.83, 0.58, 0], accentMaterial);
addBox(bench, [0.16, 0.17, 0.5], [0.83, 0.58, 0], accentMaterial);
}
function addPlanter(group, x, z, accentMaterial) {
addBox(
group,
[0.72, 0.38, 0.72],
[x, 0.81, z],
materials.wall
);
addBox(
group,
[0.48, 0.28, 0.48],
[x, 1.1, z],
materials.shrub
);
addBox(
group,
[0.18, 0.18, 0.18],
[x + 0.19, 1.3, z - 0.17],
accentMaterial
);
}
function addTree(group, x, z, scale, seed, leafRecords) {
const random = mulberry32(seed);
const tree = new THREE.Group();
tree.position.set(x, 0.62, z);
tree.scale.setScalar(scale);
group.add(tree);
// Blocky trunk and stepped branches remain visible in winter.
addBox(tree, [0.44, 2.6, 0.44], [0, 1.3, 0], materials.bark);
addBox(tree, [1.45, 0.22, 0.25], [0.48, 2.03, 0], materials.bark);
addBox(tree, [0.24, 0.95, 0.24], [0.96, 2.4, 0], materials.bark);
addBox(tree, [1.05, 0.2, 0.24], [-0.38, 2.24, 0.16], materials.barkLight);
addBox(tree, [0.23, 0.82, 0.23], [-0.73, 2.56, 0.16], materials.barkLight);
addBox(tree, [0.95, 0.18, 0.22], [0.12, 2.48, -0.35], materials.bark);
addBox(tree, [0.2, 0.68, 0.2], [0.45, 2.76, -0.35], materials.barkLight);
for (let ix = -3; ix <= 3; ix++) {
for (let iy = -3; iy <= 3; iy++) {
for (let iz = -3; iz <= 3; iz++) {
const ellipsoid =
(ix * ix) / (3.5 * 3.5) +
(iy * iy) / (3.15 * 3.15) +
(iz * iz) / (3.45 * 3.45);
if (ellipsoid > 1.08 || random() < 0.12) continue;
leafRecords.push({
x: x + (ix * 0.48 + (random() - 0.5) * 0.13) * scale,
y:
0.62 +
(3.27 + iy * 0.43 + (random() - 0.5) * 0.12) * scale,
z: z + (iz * 0.48 + (random() - 0.5) * 0.13) * scale,
threshold: random(),
tint: 0.78 + random() * 0.34,
size: 0.84 + random() * 0.31,
rotation: random() * Math.PI,
phase: random() * Math.PI * 2,
});
}
}
}
}
function createCourtyard(centerX, accentMaterial, seedOffset) {
const group = new THREE.Group();
group.position.x = centerX;
scene.add(group);
// Floating schematic plinth.
addBox(
group,
[8.55, 0.72, 7.55],
[0, 0.02, 0],
materials.plinth
);
addBox(
group,
[8.12, 0.16, 7.12],
[0, 0.46, 0],
materials.soil
);
// Cross-shaped paths.
addBox(
group,
[6.75, 0.075, 0.86],
[0, 0.585, 0],
materials.path,
false
);
addBox(
group,
[0.86, 0.075, 5.9],
[0, 0.585, 0],
materials.path,
false
);
// Low voxel courtyard walls.
addBox(
group,
[7.45, 0.52, 0.22],
[0, 0.88, -3.43],
materials.wall
);
addBox(
group,
[7.45, 0.52, 0.22],
[0, 0.88, 3.43],
materials.wall
);
addBox(
group,
[0.22, 0.52, 6.64],
[-3.7, 0.88, 0],
materials.wall
);
addBox(
group,
[0.22, 0.52, 6.64],
[3.7, 0.88, 0],
materials.wall
);
// Small accent plaques distinguish the two schematic sites.
addBox(
group,
[1.08, 0.38, 0.12],
[0, 0.03, 3.82],
accentMaterial
);
addBench(group, -1.15, -2.86, 0, accentMaterial);
addBench(group, 1.15, 2.86, Math.PI, accentMaterial);
addPlanter(group, -3.15, 0, accentMaterial);
addPlanter(group, 3.15, 0, accentMaterial);
const leafRecords = [];
addTree(group, -2.45, -2.3, 0.88, 41 + seedOffset, leafRecords);
addTree(group, 2.42, -2.27, 1.02, 77 + seedOffset, leafRecords);
addTree(group, -2.4, 2.3, 1.04, 103 + seedOffset, leafRecords);
addTree(group, 2.48, 2.3, 0.86, 151 + seedOffset, leafRecords);
const leafGeometry = new THREE.BoxGeometry(0.47, 0.47, 0.47);
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.92,
});
const leaves = new THREE.InstancedMesh(
leafGeometry,
leafMaterial,
leafRecords.length
);
leaves.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
leaves.castShadow = true;
leaves.receiveShadow = true;
leaves.frustumCulled = false;
group.add(leaves);
// A second instanced layer supplies small falling autumn voxels.
const fallingCount = 34;
const falling = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.14, 0.14, 0.14),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.9,
}),
fallingCount
);
falling.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
falling.frustumCulled = false;
group.add(falling);
const random = mulberry32(311 + seedOffset);
const fallingLeaves = Array.from({ length: fallingCount }, () => ({
x: (random() - 0.5) * 6.2,
y: 0.9 + random() * 5.2,
z: (random() - 0.5) * 5.9,
speed: 0.35 + random() * 0.45,
phase: random() * Math.PI * 2,
tint: 0.78 + random() * 0.36,
}));
return {
group,
leaves,
leafRecords,
falling,
fallingLeaves,
lastColorKey: "",
};
}
const courtyards = [
createCourtyard(-6.2, materials.northAccent, 0),
createCourtyard(6.2, materials.southAccent, 1000),
];
// Schematic ground and grid.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
new THREE.MeshStandardMaterial({
color: 0xd2ddd2,
roughness: 1,
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.36;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(70, 35, 0x9eb1a3, 0xbac9bb);
grid.position.y = -0.35;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
const dummy = new THREE.Object3D();
const colorScratch = new THREE.Color();
function updateFoliage(courtyard, localMonth, time, delta) {
const state = seasonalState(localMonth);
const colorKey = localMonth.toFixed(4);
if (courtyard.lastColorKey !== colorKey) {
courtyard.leafRecords.forEach((leaf, index) => {
colorScratch.copy(state.color).multiplyScalar(leaf.tint);
courtyard.leaves.setColorAt(index, colorScratch);
});
if (courtyard.leaves.instanceColor) {
courtyard.leaves.instanceColor.needsUpdate = true;
}
courtyard.fallingLeaves.forEach((leaf, index) => {
colorScratch.setHex(0xc96f31).multiplyScalar(leaf.tint);
courtyard.falling.setColorAt(index, colorScratch);
});
if (courtyard.falling.instanceColor) {
courtyard.falling.instanceColor.needsUpdate = true;
}
courtyard.lastColorKey = colorKey;
}
courtyard.leafRecords.forEach((leaf, index) => {
const emergence = leaf.threshold * 0.52;
const growth = THREE.MathUtils.clamp(
(state.factor - emergence) / 0.48,
0,
1
);
const scale = Math.max(0.001, growth * leaf.size);
const sway = Math.sin(time * 1.25 + leaf.phase) * 0.035;
dummy.position.set(
leaf.x + sway,
leaf.y + Math.sin(time * 1.7 + leaf.phase) * 0.014,
leaf.z + sway * 0.5
);
dummy.rotation.set(
0,
leaf.rotation + Math.sin(time * 0.8 + leaf.phase) * 0.07,
0
);
dummy.scale.setScalar(scale);
dummy.updateMatrix();
courtyard.leaves.setMatrixAt(index, dummy.matrix);
});
courtyard.leaves.instanceMatrix.needsUpdate = true;
courtyard.fallingLeaves.forEach((leaf, index) => {
if (state.drop > 0.04) {
leaf.y -= delta * leaf.speed * (0.55 + state.drop * 0.65);
leaf.x += Math.sin(time * 0.9 + leaf.phase) * delta * 0.08;
leaf.z += Math.cos(time * 0.75 + leaf.phase) * delta * 0.055;
if (leaf.y < 0.78 || Math.abs(leaf.x) > 3.4) {
leaf.x = (Math.random() - 0.5) * 5.8;
leaf.y = 5.2 + Math.random() * 1.4;
leaf.z = (Math.random() - 0.5) * 5.4;
}
dummy.position.set(leaf.x, leaf.y, leaf.z);
dummy.rotation.set(
time * 1.1 + leaf.phase,
time * 1.6 + leaf.phase,
time * 0.8
);
dummy.scale.setScalar(0.65 + state.drop * 0.55);
} else {
dummy.position.set(leaf.x, leaf.y, leaf.z);
dummy.scale.setScalar(0.001);
}
dummy.updateMatrix();
courtyard.falling.setMatrixAt(index, dummy.matrix);
});
courtyard.falling.instanceMatrix.needsUpdate = true;
}
// Calendar state.
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
let month = 3.2;
let phaseOffset = 6;
let playing = !reducedMotion;
const calendarInput = document.querySelector("#calendar");
const offsetInput = document.querySelector("#offset");
const monthName = document.querySelector("#monthName");
const monthIndex = document.querySelector("#monthIndex");
const offsetValue = document.querySelector("#offsetValue");
const playButton = document.querySelector("#play");
const playGlyph = document.querySelector("#playGlyph");
const northWorldSeason = document.querySelector("#northWorldSeason");
const southWorldSeason = document.querySelector("#southWorldSeason");
const northDot = document.querySelector("#northDot");
const southDot = document.querySelector("#southDot");
const northStatusDot = document.querySelector("#northStatusDot");
const southStatusDot = document.querySelector("#southStatusDot");
function setRangeFill(input) {
const percent =
((Number(input.value) - Number(input.min)) /
(Number(input.max) - Number(input.min))) *
100;
input.style.setProperty("--fill", `${percent}%`);
}
function updatePlayButton() {
playGlyph.textContent = playing ? "❚❚" : "▶";
playButton.setAttribute(
"aria-label",
playing ? "Pause calendar" : "Play calendar"
);
}
function updateReadouts() {
const northMonth = Math.floor(mod(month, 12));
const southMonth = Math.floor(mod(month + phaseOffset, 12));
const northSeason = seasonNames[northMonth];
const southSeason = seasonNames[southMonth];
monthName.textContent = months[northMonth];
monthIndex.textContent = `${String(northMonth + 1).padStart(2, "0")} / 12`;
offsetValue.textContent = `+${phaseOffset} month${phaseOffset === 1 ? "" : "s"}`;
northWorldSeason.textContent = `${months[northMonth]} · ${northSeason}`;
southWorldSeason.textContent = `${months[southMonth]} · ${southSeason}`;
const northText = document.querySelector("#northStatus span:last-child");
const southText = document.querySelector("#southStatus span:last-child");
northText.textContent = `${months[northMonth]} · ${northSeason}`;
southText.textContent = `${months[southMonth]} · ${southSeason}`;
northDot.style.setProperty("--season-color", seasonColors[northSeason]);
southDot.style.setProperty("--season-color", seasonColors[southSeason]);
northStatusDot.style.setProperty("--season-color", seasonColors[northSeason]);
southStatusDot.style.setProperty("--season-color", seasonColors[southSeason]);
setRangeFill(calendarInput);
setRangeFill(offsetInput);
}
calendarInput.addEventListener("input", () => {
month = Number(calendarInput.value);
playing = false;
updatePlayButton();
updateReadouts();
});
offsetInput.addEventListener("input", () => {
phaseOffset = Number(offsetInput.value);
updateReadouts();
});
playButton.addEventListener("click", () => {
playing = !playing;
updatePlayButton();
});
// Camera controls implemented directly without addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
cameraState.theta -= deltaX * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + deltaY * 0.005,
0.55,
1.42
);
previousX = event.clientX;
previousY = event.clientY;
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
17,
52
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraState.theta = 0;
cameraState.phi = 1.03;
cameraState.radius =
window.innerWidth / window.innerHeight < 0.75 ? 43 : 26;
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
playing = !playing;
updatePlayButton();
}
if (event.code === "ArrowRight") {
month = mod(month + 0.25, 12);
playing = false;
updatePlayButton();
}
if (event.code === "ArrowLeft") {
month = mod(month - 0.25, 12);
playing = false;
updatePlayButton();
}
});
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraTarget.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraTarget.y + cameraState.radius * Math.cos(cameraState.phi),
cameraTarget.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
const northAnchor = new THREE.Vector3(-6.2, 5.75, -2.2);
const southAnchor = new THREE.Vector3(6.2, 5.75, -2.2);
const projected = new THREE.Vector3();
function positionWorldLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity =
projected.z > -1 && projected.z < 1 ? "1" : "0";
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.fov = camera.aspect < 0.75 ? 52 : 40;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
updatePlayButton();
updateReadouts();
let previousTime = performance.now();
renderer.setAnimationLoop((time) => {
const delta = Math.min(0.05, (time - previousTime) / 1000);
previousTime = time;
if (playing) {
month = mod(month + delta * 0.11, 12);
calendarInput.value = String(month);
}
updateReadouts();
updateCamera();
updateFoliage(courtyards[0], month, time, delta);
updateFoliage(
courtyards[1],
month + phaseOffset,
time + 1.7,
delta
);
positionWorldLabel(
document.querySelector("#northLabel"),
northAnchor
);
positionWorldLabel(
document.querySelector("#southLabel"),
southAnchor
);
renderer.render(scene, camera);
loading.classList.add("hidden");
});
</script>
</body>
</html>
```