Prompt specification
Build or customize the Three.js 3D scene "Zero Tilt Versus Earth-Like Tilt Experiment" 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: Zero Tilt Versus Earth-Like Tilt Experiment
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/zero-tilt-versus-earth-like-tilt-experiment-x3768
Scene Description Prompt:
Compare voxel idealized planets with zero and Earth-like axial tilt at equal orbital distances, showing seasonal daylight. One HTML file with Three.js from cdnjs.
Working Three.js Starter (zero-tilt-versus-earth-like-tilt-experiment-x3768):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Axial Tilt and Seasonal Daylight</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(8, 15, 29, 0.78);
--panel-border: rgba(151, 190, 231, 0.18);
--text: #eef6ff;
--muted: #9fb2c9;
--cyan: #69e4ff;
--orange: #ffb45b;
--yellow: #ffd86a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #030711;
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #030711;
color: #b8d8f2;
letter-spacing: 0.12em;
text-transform: uppercase;
font-size: 12px;
transition: opacity 0.45s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.intro {
position: fixed;
z-index: 10;
top: 22px;
left: 24px;
width: min(440px, calc(100vw - 48px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: #9bdfff;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #70f1b4;
box-shadow: 0 0 12px #70f1b4;
}
h1 {
margin: 8px 0 7px;
font-size: clamp(24px, 3.3vw, 42px);
line-height: 1.02;
letter-spacing: -0.04em;
text-wrap: balance;
}
.intro p {
max-width: 410px;
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 13px;
}
.chip {
padding: 6px 9px;
border: 1px solid var(--panel-border);
border-radius: 999px;
background: rgba(11, 22, 40, 0.66);
color: #bdd3e9;
font-size: 10px;
letter-spacing: 0.03em;
}
.controls {
position: fixed;
z-index: 20;
top: 22px;
right: 24px;
width: 242px;
padding: 12px;
border: 1px solid var(--panel-border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(15px);
}
.controls-title {
margin-bottom: 10px;
color: #91a8c1;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.button-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
button {
min-height: 32px;
border: 1px solid rgba(160, 199, 237, 0.16);
border-radius: 8px;
background: rgba(83, 126, 171, 0.12);
color: #d9eaff;
font: inherit;
font-size: 10px;
cursor: pointer;
transition:
background 0.18s ease,
border-color 0.18s ease,
transform 0.18s ease;
}
button:hover {
background: rgba(103, 158, 212, 0.24);
border-color: rgba(160, 213, 255, 0.4);
}
button:active {
transform: translateY(1px);
}
#pause {
width: 100%;
margin-bottom: 7px;
color: #071019;
border-color: transparent;
background: linear-gradient(135deg, #78ddff, #79f0c4);
font-weight: 800;
}
.speed-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 11px;
color: #a9bed3;
font-size: 10px;
}
.speed-row input {
width: 100%;
accent-color: #75dfff;
}
.toggle {
display: flex;
align-items: center;
gap: 7px;
margin-top: 10px;
color: #a9bed3;
font-size: 10px;
cursor: pointer;
}
.toggle input {
accent-color: #75dfff;
}
.planet-label {
position: fixed;
z-index: 15;
left: 0;
top: 0;
width: 210px;
padding: 12px;
border: 1px solid var(--panel-border);
border-top: 2px solid var(--cyan);
border-radius: 12px;
background: rgba(7, 14, 28, 0.88);
box-shadow: 0 14px 35px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
pointer-events: none;
transform: translate(-50%, -100%);
transition: opacity 0.15s ease;
}
.planet-label.earth {
border-top-color: var(--orange);
}
.planet-label .tag {
color: var(--cyan);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.planet-label.earth .tag {
color: var(--orange);
}
.planet-label h2 {
margin: 4px 0 9px;
font-size: 15px;
letter-spacing: -0.02em;
}
.planet-label .stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.stat {
padding: 7px;
border-radius: 7px;
background: rgba(119, 162, 208, 0.09);
}
.stat span {
display: block;
color: #8fa8c2;
font-size: 8px;
letter-spacing: 0.04em;
}
.stat strong {
display: block;
margin-top: 2px;
color: #f4f9ff;
font-size: 13px;
}
.meter {
position: relative;
height: 5px;
margin-top: 9px;
overflow: hidden;
border-radius: 999px;
background: #18253a;
}
.meter i {
display: block;
width: 50%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #ffb653, #ffe782);
transition: width 0.15s linear;
}
.meter b {
position: absolute;
top: -2px;
bottom: -2px;
left: 50%;
width: 1px;
background: rgba(255, 255, 255, 0.5);
}
.season {
margin-top: 8px;
color: #bbcddd;
font-size: 9px;
line-height: 1.35;
}
.declination {
margin-top: 4px;
color: #7189a2;
font-size: 8px;
}
.sun-label {
position: fixed;
z-index: 12;
left: 0;
top: 0;
padding: 5px 8px;
border: 1px solid rgba(255, 218, 109, 0.22);
border-radius: 999px;
background: rgba(10, 13, 19, 0.72);
color: #ffe28b;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
pointer-events: none;
transform: translate(-50%, -50%);
transition: opacity 0.15s ease;
}
.legend {
position: fixed;
z-index: 10;
left: 24px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
max-width: min(590px, calc(100vw - 48px));
color: #8fa5bd;
font-size: 9px;
pointer-events: none;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 14px;
height: 3px;
border-radius: 99px;
background: var(--yellow);
}
.swatch.axis {
background: var(--cyan);
}
.swatch.ring {
height: 0;
border-top: 1px dashed #ffce68;
border-radius: 0;
background: transparent;
}
.note {
position: fixed;
z-index: 10;
right: 24px;
bottom: 22px;
max-width: 330px;
color: #6f849b;
font-size: 9px;
line-height: 1.5;
text-align: right;
pointer-events: none;
}
@media (max-width: 760px) {
.intro {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
}
.intro p,
.chips {
display: none;
}
h1 {
max-width: 290px;
font-size: 25px;
}
.controls {
top: auto;
right: 12px;
bottom: 12px;
width: 218px;
padding: 9px;
}
.controls-title,
.toggle,
.note {
display: none;
}
.planet-label {
width: 156px;
padding: 9px;
}
.planet-label h2 {
margin-bottom: 7px;
font-size: 12px;
}
.planet-label .stats {
gap: 4px;
}
.stat {
padding: 5px;
}
.stat strong {
font-size: 11px;
}
.legend {
left: 14px;
bottom: 145px;
max-width: 220px;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<div id="loading">Building voxel worlds…</div>
<header class="intro">
<div class="eyebrow"><span class="live-dot"></span>Live orbital comparison</div>
<h1>Axial tilt changes daylight.</h1>
<p>
Two identical voxel worlds share one circular orbit and remain exactly
the same distance from the Sun. Only their axial tilt differs.
</p>
<div class="chips">
<span class="chip">Shared orbital radius · 6.8</span>
<span class="chip">Identical terrain</span>
<span class="chip">23.44° Earth-like tilt</span>
</div>
</header>
<aside class="controls">
<div class="controls-title">Simulation controls</div>
<button id="pause" type="button">Pause</button>
<div class="button-row">
<button type="button" data-view="oblique">Oblique</button>
<button type="button" data-view="top">Top</button>
<button type="button" data-view="tilt">Tilt</button>
</div>
<label class="speed-row">
Speed
<input
id="speed"
type="range"
min="0.2"
max="2.5"
step="0.1"
value="1"
/>
</label>
<label class="toggle">
<input id="axes" type="checkbox" checked />
Show axes and latitude rings
</label>
</aside>
<div id="label-zero" class="planet-label">
<div class="tag">0.0° axial tilt</div>
<h2>Equinox world</h2>
<div class="stats">
<div class="stat">
<span>45°N daylight</span>
<strong id="zeroN">12.0 h</strong>
</div>
<div class="stat">
<span>45°S daylight</span>
<strong id="zeroS">12.0 h</strong>
</div>
</div>
<div class="meter"><i id="zeroMeter"></i><b></b></div>
<div id="zeroSeason" class="season">No seasons · 12-hour day at 45°</div>
<div class="declination">Solar declination: 0.0°</div>
</div>
<div id="label-earth" class="planet-label earth">
<div class="tag">23.44° axial tilt</div>
<h2>Earth-like world</h2>
<div class="stats">
<div class="stat">
<span>45°N daylight</span>
<strong id="earthN">15.4 h</strong>
</div>
<div class="stat">
<span>45°S daylight</span>
<strong id="earthS">8.6 h</strong>
</div>
</div>
<div class="meter"><i id="earthMeter"></i><b></b></div>
<div id="earthSeason" class="season">Northern summer · Southern winter</div>
<div id="earthDecl" class="declination">Solar declination: +23.4°</div>
</div>
<div id="sun-label" class="sun-label">SUN · SHARED ORBIT</div>
<div class="legend">
<span><i class="swatch"></i> Sunlight</span>
<span><i class="swatch axis"></i> Rotation axis</span>
<span><i class="swatch ring"></i> 45°N latitude</span>
<span>Yellow bead = local noon on the 45°N ring</span>
</div>
<div class="note">
Day length uses the standard geometric, no-atmosphere formula at 45° N/S.
The planets stay 180° apart on the same orbit, so their distances from
the Sun are identical.
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x030711);
scene.fog = new THREE.FogExp2(0x030711, 0.009);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.05,
100
);
const cameraTarget = new THREE.Vector3(0, 0.25, 0);
const desiredCamera = {
theta: 0.55,
phi: 1.05,
radius: 14.8
};
const currentCamera = {
theta: desiredCamera.theta,
phi: desiredCamera.phi,
radius: desiredCamera.radius
};
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.AmbientLight(0x243651, 0.2));
const sunlight = new THREE.PointLight(0xffefcf, 4.5, 0, 0);
sunlight.position.set(0, 0, 0);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(512, 512);
sunlight.shadow.camera.near = 0.5;
sunlight.shadow.camera.far = 11;
sunlight.shadow.bias = -0.0015;
sunlight.shadow.normalBias = 0.025;
scene.add(sunlight);
// -------------------------------------------------------------------------
// Stars
// -------------------------------------------------------------------------
const starPositions = [];
const starColors = [];
for (let i = 0; i < 850; i++) {
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
const radius = 30 + Math.random() * 24;
starPositions.push(
radius * Math.sin(phi) * Math.cos(theta),
radius * Math.cos(phi),
radius * Math.sin(phi) * Math.sin(theta)
);
const brightness = 0.45 + Math.random() * 0.55;
starColors.push(
brightness * 0.72,
brightness * 0.84,
brightness
);
}
const starGeometry = new THREE.BufferGeometry();
starGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(starPositions, 3)
);
starGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(starColors, 3)
);
const stars = new THREE.Points(
starGeometry,
new THREE.PointsMaterial({
size: 0.055,
vertexColors: true,
transparent: true,
opacity: 0.85,
depthWrite: false
})
);
scene.add(stars);
// -------------------------------------------------------------------------
// Sun
// -------------------------------------------------------------------------
const sun = new THREE.Mesh(
new THREE.SphereGeometry(0.58, 36, 24),
new THREE.MeshBasicMaterial({ color: 0xffc54d })
);
scene.add(sun);
const sunGlowInner = new THREE.Mesh(
new THREE.SphereGeometry(0.78, 32, 20),
new THREE.MeshBasicMaterial({
color: 0xffb52f,
transparent: true,
opacity: 0.15,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
scene.add(sunGlowInner);
const sunGlowOuter = new THREE.Mesh(
new THREE.SphereGeometry(1.12, 32, 20),
new THREE.MeshBasicMaterial({
color: 0xffa521,
transparent: true,
opacity: 0.045,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
scene.add(sunGlowOuter);
// -------------------------------------------------------------------------
// Orbit and orbital-plane grid
// -------------------------------------------------------------------------
const ORBIT_RADIUS = 6.8;
const orbitPoints = [];
for (let i = 0; i < 256; i++) {
const angle = (i / 256) * Math.PI * 2;
orbitPoints.push(
new THREE.Vector3(
Math.cos(angle) * ORBIT_RADIUS,
0,
Math.sin(angle) * ORBIT_RADIUS
)
);
}
const orbit = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(orbitPoints),
new THREE.LineBasicMaterial({
color: 0x7ea3cb,
transparent: true,
opacity: 0.28,
depthWrite: false
})
);
scene.add(orbit);
const grid = new THREE.GridHelper(
18,
36,
0x36516f,
0x14243b
);
grid.position.y = -0.16;
grid.material.transparent = true;
grid.material.opacity = 0.24;
grid.material.depthWrite = false;
scene.add(grid);
// -------------------------------------------------------------------------
// Deterministic value noise used to build an identical voxel world
// -------------------------------------------------------------------------
function hash3(x, y, z) {
let h =
Math.imul(x, 374761393) ^
Math.imul(y, 668265263) ^
Math.imul(z, 2147483647);
h = Math.imul(h ^ (h >>> 13), 1274126177);
return ((h ^ (h >>> 16)) >>> 0) / 4294967295;
}
function smoothstep(t) {
return t * t * (3 - 2 * t);
}
function valueNoise(x, y, z) {
const x0 = Math.floor(x);
const y0 = Math.floor(y);
const z0 = Math.floor(z);
const tx = smoothstep(x - x0);
const ty = smoothstep(y - y0);
const tz = smoothstep(z - z0);
const c000 = hash3(x0, y0, z0);
const c100 = hash3(x0 + 1, y0, z0);
const c010 = hash3(x0, y0 + 1, z0);
const c110 = hash3(x0 + 1, y0 + 1, z0);
const c001 = hash3(x0, y0, z0 + 1);
const c101 = hash3(x0 + 1, y0, z0 + 1);
const c011 = hash3(x0, y0 + 1, z0 + 1);
const c111 = hash3(x0 + 1, y0 + 1, z0 + 1);
const x00 = THREE.MathUtils.lerp(c000, c100, tx);
const x10 = THREE.MathUtils.lerp(c010, c110, tx);
const x01 = THREE.MathUtils.lerp(c001, c101, tx);
const x11 = THREE.MathUtils.lerp(c011, c111, tx);
const y0Mix = THREE.MathUtils.lerp(x00, x10, ty);
const y1Mix = THREE.MathUtils.lerp(x01, x11, ty);
return THREE.MathUtils.lerp(y0Mix, y1Mix, tz);
}
function fbm(x, y, z) {
let amplitude = 0.5;
let frequency = 1;
let sum = 0;
let normalization = 0;
for (let octave = 0; octave < 4; octave++) {
sum +=
amplitude *
valueNoise(x * frequency, y * frequency, z * frequency);
normalization += amplitude;
amplitude *= 0.5;
frequency *= 2.03;
}
return sum / normalization;
}
// -------------------------------------------------------------------------
// Voxel planet geometry
// -------------------------------------------------------------------------
const VOXEL_RADIUS = 1.08;
const VOXEL_STEP = 0.18;
const VOXEL_SIZE = 0.165;
const descriptors = [];
for (let ix = -6; ix <= 6; ix++) {
for (let iy = -6; iy <= 6; iy++) {
for (let iz = -6; iz <= 6; iz++) {
const x = ix * VOXEL_STEP;
const y = iy * VOXEL_STEP;
const z = iz * VOXEL_STEP;
const distance = Math.sqrt(x * x + y * y + z * z);
if (distance > VOXEL_RADIUS) continue;
const nx = x / VOXEL_RADIUS;
const ny = y / VOXEL_RADIUS;
const nz = z / VOXEL_RADIUS;
const rough =
valueNoise(nx * 7.1 + 3, ny * 7.1 - 8, nz * 7.1 + 11) -
0.5;
const radialScale = 0.985 + rough * 0.035;
const position = new THREE.Vector3(
nx * VOXEL_RADIUS * radialScale,
ny * VOXEL_RADIUS * radialScale,
nz * VOXEL_RADIUS * radialScale
);
const terrain =
fbm(nx * 2.45 + 11.2, ny * 2.45 - 7.1, nz * 2.45 + 3.4) +
0.12 * Math.sin(nx * 5.1 + nz * 3.8 + ny * 2.2);
const elevation = fbm(
nx * 5.5 - 4,
ny * 5.5 + 9,
nz * 5.5 + 13
);
const color = new THREE.Color();
if (Math.abs(ny) > 0.78 + (elevation - 0.5) * 0.12) {
// Polar ice
color.setHSL(0.56, 0.22, 0.88 + elevation * 0.06);
} else if (terrain > 0.535) {
// Land: green lowlands, brown uplands, occasional high mountains
if (elevation > 0.69) {
color.setHSL(0.105, 0.29, 0.39 + elevation * 0.12);
} else {
color.setHSL(0.34, 0.34, 0.31 + elevation * 0.12);
}
} else {
// Ocean
color.setHSL(0.56, 0.57, 0.25 + elevation * 0.08);
}
color.offsetHSL(
0,
(hash3(ix, iy, iz) - 0.5) * 0.035,
(hash3(ix + 91, iy - 17, iz + 43) - 0.5) * 0.055
);
descriptors.push({ position, color });
}
}
}
const voxelGeometry = new THREE.BoxGeometry(
VOXEL_SIZE,
VOXEL_SIZE,
VOXEL_SIZE
);
const voxelMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.84,
metalness: 0
});
function makeVoxelMesh() {
const mesh = new THREE.InstancedMesh(
voxelGeometry,
voxelMaterial,
descriptors.length
);
const dummy = new THREE.Object3D();
descriptors.forEach((descriptor, index) => {
dummy.position.copy(descriptor.position);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, descriptor.color);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.instanceColor.needsUpdate = true;
mesh.instanceMatrix.setUsage(THREE.StaticDrawUsage);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.frustumCulled = false;
return mesh;
}
// -------------------------------------------------------------------------
// Planet construction
// -------------------------------------------------------------------------
const atmosphereMaterial = new THREE.ShaderMaterial({
uniforms: {
atmosphereColor: { value: new THREE.Color(0x63c8ff) }
},
vertexShader: `
varying vec3 vWorldNormal;
varying vec3 vWorldPosition;
void main() {
vec4 worldPosition = modelMatrix * vec4(position, 1.0);
vWorldPosition = worldPosition.xyz;
vWorldNormal = normalize(mat3(modelMatrix) * normal);
gl_Position = projectionMatrix * viewMatrix * worldPosition;
}
`,
fragmentShader: `
uniform vec3 atmosphereColor;
varying vec3 vWorldNormal;
varying vec3 vWorldPosition;
void main() {
vec3 viewDirection = normalize(cameraPosition - vWorldPosition);
float rim = pow(
1.0 - max(dot(normalize(vWorldNormal), viewDirection), 0.0),
2.7
);
gl_FragColor = vec4(
atmosphereColor,
rim * 0.24
);
}
`,
transparent: true,
blending: THREE.AdditiveBlending,
depthWrite: false,
side: THREE.FrontSide
});
const LATITUDE = THREE.MathUtils.degToRad(45);
const UP = new THREE.Vector3(0, 1, 0);
function makeLatitudeRing(latitude, color, dashed = false) {
const radius = VOXEL_RADIUS * Math.cos(latitude);
const y = VOXEL_RADIUS * Math.sin(latitude);
const points = [];
for (let i = 0; i < 128; i++) {
const angle = (i / 128) * Math.PI * 2;
points.push(
new THREE.Vector3(
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
)
);
}
const material = dashed
? new THREE.LineDashedMaterial({
color,
transparent: true,
opacity: 0.7,
dashSize: 0.08,
gapSize: 0.055,
depthWrite: false
})
: new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.3,
depthWrite: false
});
const line = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
material
);
if (dashed) line.computeLineDistances();
return line;
}
function makePlanet(tiltDegrees, accentColor) {
const root = new THREE.Group();
// The pivot represents the fixed direction of the rotational axis.
const pivot = new THREE.Group();
pivot.rotation.z = THREE.MathUtils.degToRad(tiltDegrees);
root.add(pivot);
// Only the surface texture spins around the tilted axis.
const spin = new THREE.Group();
pivot.add(spin);
spin.add(makeVoxelMesh());
const atmosphere = new THREE.Mesh(
new THREE.SphereGeometry(1.16, 40, 28),
atmosphereMaterial
);
pivot.add(atmosphere);
const auxiliary = new THREE.Group();
pivot.add(auxiliary);
const axis = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, -1.55, 0),
new THREE.Vector3(0, 1.55, 0)
]),
new THREE.LineBasicMaterial({
color: accentColor,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
})
);
axis.renderOrder = 8;
auxiliary.add(axis);
const north = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 12, 8),
new THREE.MeshBasicMaterial({
color: accentColor,
depthTest: false
})
);
north.position.y = 1.6;
north.renderOrder = 9;
auxiliary.add(north);
auxiliary.add(makeLatitudeRing(0, accentColor, false));
auxiliary.add(makeLatitudeRing(LATITUDE, 0xffd86a, true));
const noonMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 14, 10),
new THREE.MeshBasicMaterial({
color: 0xffe78d,
depthTest: false,
depthWrite: false
})
);
noonMarker.renderOrder = 10;
spin.add(noonMarker);
const axisWorld = new THREE.Vector3(0, 1, 0).applyQuaternion(
pivot.quaternion
);
return {
root,
pivot,
spin,
auxiliary,
noonMarker,
axisWorld
};
}
const zeroTiltPlanet = makePlanet(0, 0x69e4ff);
const earthLikePlanet = makePlanet(23.44, 0xffb45b);
scene.add(zeroTiltPlanet.root);
scene.add(earthLikePlanet.root);
// -------------------------------------------------------------------------
// Sunlight direction arrows
// -------------------------------------------------------------------------
function makeSunArrow() {
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(0, 0, 0),
ORBIT_RADIUS - 1.25,
0xffd86a,
0.23,
0.13
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.24;
arrow.line.material.depthWrite = false;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.34;
arrow.cone.material.depthWrite = false;
scene.add(arrow);
return arrow;
}
const zeroArrow = makeSunArrow();
const earthArrow = makeSunArrow();
// -------------------------------------------------------------------------
// UI references
// -------------------------------------------------------------------------
const ui = {
zeroLabel: document.querySelector("#label-zero"),
earthLabel: document.querySelector("#label-earth"),
sunLabel: document.querySelector("#sun-label"),
zeroN: document.querySelector("#zeroN"),
zeroS: document.querySelector("#zeroS"),
zeroMeter: document.querySelector("#zeroMeter"),
zeroSeason: document.querySelector("#zeroSeason"),
earthN: document.querySelector("#earthN"),
earthS: document.querySelector("#earthS"),
earthMeter: document.querySelector("#earthMeter"),
earthSeason: document.querySelector("#earthSeason"),
earthDecl: document.querySelector("#earthDecl"),
pause: document.querySelector("#pause"),
speed: document.querySelector("#speed"),
axes: document.querySelector("#axes")
};
// -------------------------------------------------------------------------
// Simulation state
// -------------------------------------------------------------------------
let running = true;
let orbitAngle = 0;
let spinPhase = 0;
let uiTimer = 0;
const zeroPosition = new THREE.Vector3();
const earthPosition = new THREE.Vector3();
function daylightHours(latitudeRadians, declinationRadians) {
const cosineHourAngle =
-Math.tan(latitudeRadians) * Math.tan(declinationRadians);
const clamped = THREE.MathUtils.clamp(
cosineHourAngle,
-1,
1
);
const hourAngle = Math.acos(clamped);
return (24 * hourAngle) / Math.PI;
}
function signedDegrees(value) {
return `${value >= 0 ? "+" : ""}${value.toFixed(1)}°`;
}
function updateReadouts() {
const zeroDeclination = 0;
const earthSunDirection = earthPosition.clone().negate().normalize();
const earthDeclination = Math.asin(
THREE.MathUtils.clamp(
earthLikePlanet.axisWorld.dot(earthSunDirection),
-1,
1
)
);
const zeroNorth = daylightHours(LATITUDE, zeroDeclination);
const zeroSouth = daylightHours(LATITUDE, -zeroDeclination);
const earthNorth = daylightHours(LATITUDE, earthDeclination);
const earthSouth = daylightHours(LATITUDE, -earthDeclination);
ui.zeroN.textContent = `${zeroNorth.toFixed(1)} h`;
ui.zeroS.textContent = `${zeroSouth.toFixed(1)} h`;
ui.zeroMeter.style.width = `${(zeroNorth / 24) * 100}%`;
ui.zeroSeason.textContent = "No seasons · 12-hour day at 45°";
ui.earthN.textContent = `${earthNorth.toFixed(1)} h`;
ui.earthS.textContent = `${earthSouth.toFixed(1)} h`;
ui.earthMeter.style.width = `${(earthNorth / 24) * 100}%`;
ui.earthDecl.textContent =
`Solar declination: ${signedDegrees(
THREE.MathUtils.radToDeg(earthDeclination)
)}`;
const earthDeclinationDegrees = THREE.MathUtils.radToDeg(
earthDeclination
);
if (earthDeclinationDegrees > 12) {
ui.earthSeason.textContent = "Northern summer · Southern winter";
} else if (earthDeclinationDegrees < -12) {
ui.earthSeason.textContent = "Northern winter · Southern summer";
} else {
ui.earthSeason.textContent = "Equinox-like seasonal transition";
}
}
function updateNoonMarker(planet, worldPosition, currentSpinPhase) {
const sunDirection = worldPosition.clone().negate().normalize();
const inPivotCoordinates = sunDirection.clone().applyQuaternion(
planet.pivot.quaternion.clone().invert()
);
const inSpinCoordinates = inPivotCoordinates.clone().applyAxisAngle(
UP,
-currentSpinPhase
);
const horizontal = new THREE.Vector2(
inSpinCoordinates.x,
inSpinCoordinates.z
);
if (horizontal.lengthSq() < 0.000001) {
horizontal.set(1, 0);
} else {
horizontal.normalize();
}
const ringRadius = VOXEL_RADIUS * Math.cos(LATITUDE);
planet.noonMarker.position.set(
horizontal.x * ringRadius,
VOXEL_RADIUS * Math.sin(LATITUDE),
horizontal.y * ringRadius
);
}
// -------------------------------------------------------------------------
// Direct camera controls: no addons or OrbitControls import
// -------------------------------------------------------------------------
const pointers = new Map();
let lastPinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
canvas.setPointerCapture(event.pointerId);
if (pointers.size === 2) {
const points = [...pointers.values()];
lastPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
desiredCamera.theta -= dx * 0.006;
desiredCamera.phi -= dy * 0.005;
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi,
0.08,
Math.PI - 0.08
);
} else if (pointers.size >= 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (lastPinchDistance > 0 && distance > 0) {
desiredCamera.radius *=
lastPinchDistance / distance;
}
lastPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
lastPinchDistance = 0;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.radius *= Math.exp(event.deltaY * 0.001);
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius,
7.5,
27
);
},
{ passive: false }
);
function setCameraView(view) {
if (view === "top") {
desiredCamera.theta = -Math.PI / 2;
desiredCamera.phi = 0.08;
desiredCamera.radius = 15.5;
} else if (view === "tilt") {
desiredCamera.theta = Math.PI / 2;
desiredCamera.phi = 1.38;
desiredCamera.radius = 14.5;
} else {
desiredCamera.theta = 0.55;
desiredCamera.phi = 1.05;
desiredCamera.radius = 14.8;
}
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => {
setCameraView(button.dataset.view);
});
});
ui.pause.addEventListener("click", () => {
running = !running;
ui.pause.textContent = running ? "Pause" : "Resume";
});
ui.axes.addEventListener("change", () => {
zeroTiltPlanet.auxiliary.visible = ui.axes.checked;
earthLikePlanet.auxiliary.visible = ui.axes.checked;
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
ui.pause.click();
}
if (event.key.toLowerCase() === "r") {
setCameraView("oblique");
}
});
// -------------------------------------------------------------------------
// DOM label projection
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function projectLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
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`;
}
const labelOffset = new THREE.Vector3(0, 1.65, 0);
const sunLabelPosition = new THREE.Vector3(0, 1.15, 0);
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const speed = Number(ui.speed.value);
if (running) {
orbitAngle =
(orbitAngle + delta * 0.07 * speed) % (Math.PI * 2);
spinPhase =
(spinPhase + delta * 0.65 * speed) % (Math.PI * 2);
}
// The planets stay exactly opposite each other on the same orbit.
zeroPosition.set(
Math.cos(orbitAngle) * ORBIT_RADIUS,
0,
Math.sin(orbitAngle) * ORBIT_RADIUS
);
earthPosition.copy(zeroPosition).multiplyScalar(-1);
zeroTiltPlanet.root.position.copy(zeroPosition);
earthLikePlanet.root.position.copy(earthPosition);
zeroTiltPlanet.spin.rotation.y = spinPhase;
earthLikePlanet.spin.rotation.y = spinPhase;
const zeroSunDirection = zeroPosition.clone().negate().normalize();
const earthSunDirection = earthPosition.clone().negate().normalize();
zeroArrow.setDirection(zeroSunDirection);
earthArrow.setDirection(earthSunDirection);
updateNoonMarker(
zeroTiltPlanet,
zeroPosition,
spinPhase
);
updateNoonMarker(
earthLikePlanet,
earthPosition,
spinPhase
);
// Smooth, direct camera movement.
const cameraSmoothing = 1 - Math.exp(-delta * 10);
currentCamera.theta +=
(desiredCamera.theta - currentCamera.theta) * cameraSmoothing;
currentCamera.phi +=
(desiredCamera.phi - currentCamera.phi) * cameraSmoothing;
currentCamera.radius +=
(desiredCamera.radius - currentCamera.radius) * cameraSmoothing;
const sinPhi = Math.sin(currentCamera.phi);
camera.position.set(
cameraTarget.x +
currentCamera.radius *
sinPhi *
Math.cos(currentCamera.theta),
cameraTarget.y +
currentCamera.radius * Math.cos(currentCamera.phi),
cameraTarget.z +
currentCamera.radius *
sinPhi *
Math.sin(currentCamera.theta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
uiTimer += delta;
if (uiTimer > 0.08) {
updateReadouts();
uiTimer = 0;
}
projectLabel(
ui.zeroLabel,
zeroPosition.clone().add(labelOffset)
);
projectLabel(
ui.earthLabel,
earthPosition.clone().add(labelOffset)
);
projectLabel(ui.sunLabel, sunLabelPosition);
renderer.render(scene, camera);
}
updateReadouts();
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```