Prompt specification
Build or customize the Three.js 3D scene "Tilted Globe and Parallel Light Rays" 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: Tilted Globe and Parallel Light Rays
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/tilted-globe-and-parallel-light-rays-x3765
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing axial tilt and sunlight incidence across latitudes. Model a tilted globe with equator, axis, and parallel incoming light guides. Preserve axis orientation and show how light strikes different latitudes at different angles. Low-poly.
Working Three.js Starter (tilted-globe-and-parallel-light-rays-x3765):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Axial Tilt & Solar Incidence</title>
<style>
:root {
color-scheme: dark;
--bg: #050914;
--panel: rgba(8, 16, 31, 0.78);
--panel-border: rgba(151, 196, 255, 0.18);
--text: #edf5ff;
--muted: #91a7c1;
--cyan: #54d7ff;
--gold: #ffd166;
--violet: #ae8cff;
--red: #ff7b7b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 62% 40%, #14213b 0%, #080e1c 38%, #03060d 78%);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
z-index: 0;
display: block;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.panel {
pointer-events: auto;
border: 1px solid var(--panel-border);
border-radius: 15px;
background: var(--panel);
box-shadow:
0 18px 55px rgba(0, 0, 0, 0.32),
inset 0 1px rgba(255, 255, 255, 0.04);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
.intro {
position: absolute;
top: 20px;
left: 20px;
width: min(440px, calc(100vw - 40px));
padding: 19px 21px 17px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 32px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro p {
margin: 10px 0 14px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.badges {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 999px;
background: rgba(255, 255, 255, 0.035);
color: #bfd1e6;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.badge::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
content: "";
box-shadow: 0 0 10px currentColor;
}
.badge.axis {
color: #f4f8ff;
}
.badge.sun {
color: var(--gold);
}
.data-panel {
position: absolute;
top: 20px;
right: 20px;
width: 310px;
padding: 17px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 6px;
}
.panel-heading h2 {
margin: 0;
font-size: 14px;
letter-spacing: -0.01em;
}
.panel-heading span {
color: var(--gold);
font-size: 11px;
font-weight: 800;
}
.data-panel > p {
margin: 0 0 14px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.lat-row {
display: grid;
grid-template-columns: 55px 1fr 48px;
align-items: center;
gap: 9px;
min-height: 28px;
color: #dbe9fa;
font-size: 11px;
}
.lat-row > span {
font-weight: 700;
}
.lat-row > b {
color: var(--text);
font-size: 11px;
text-align: right;
}
.energy {
height: 5px;
overflow: hidden;
border-radius: 10px;
background: rgba(255, 255, 255, 0.08);
}
.energy i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--gold);
box-shadow: 0 0 9px currentColor;
transition: width 120ms ease, background 120ms ease;
}
.lat-row.night {
color: #7e8ba0;
}
.lat-row.night > b {
color: var(--red);
}
.panel-note {
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid rgba(255, 255, 255, 0.07);
color: #71869f;
font-size: 10px;
line-height: 1.45;
}
.controls {
position: absolute;
bottom: 20px;
left: 50%;
width: min(610px, calc(100vw - 40px));
padding: 15px 17px;
transform: translateX(-50%);
}
.control-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 10px;
}
.control-top label {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.control-top output {
color: var(--gold);
font-size: 12px;
font-weight: 800;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
border-radius: 10px;
outline: none;
appearance: none;
-webkit-appearance: none;
background:
linear-gradient(90deg, #ffd166 0%, #ffd166 100%) no-repeat,
rgba(255, 255, 255, 0.09);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 3px solid #162238;
border-radius: 50%;
appearance: none;
-webkit-appearance: none;
background: var(--gold);
box-shadow: 0 0 14px rgba(255, 209, 102, 0.6);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #162238;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 14px rgba(255, 209, 102, 0.6);
}
.control-bottom {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 12px;
}
.presets {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
button {
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 8px;
background: rgba(255, 255, 255, 0.04);
color: #afc1d7;
font: inherit;
font-size: 10px;
font-weight: 700;
cursor: pointer;
transition: 140ms ease;
}
button:hover,
button.active {
border-color: rgba(255, 209, 102, 0.42);
background: rgba(255, 209, 102, 0.1);
color: #ffe5a5;
}
.subsolar {
text-align: right;
white-space: nowrap;
}
.subsolar span {
display: block;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.subsolar strong {
display: block;
margin-top: 2px;
color: var(--gold);
font-size: 15px;
}
.legend {
position: absolute;
bottom: 24px;
left: 22px;
display: grid;
gap: 7px;
color: #9bb0c7;
font-size: 10px;
}
.legend div {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 18px;
height: 2px;
border-radius: 2px;
box-shadow: 0 0 8px currentColor;
}
.hint {
position: absolute;
right: 22px;
bottom: 24px;
color: #71869f;
font-size: 10px;
text-align: right;
line-height: 1.5;
}
#labelLayer {
position: fixed;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
display: none;
transform: translate(-50%, -50%);
color: #dcecff;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
text-shadow: 0 1px 5px #000, 0 0 12px #000;
white-space: nowrap;
}
.incidence-label {
position: absolute;
display: none;
transform: translate(10px, -50%);
padding: 5px 7px;
border: 1px solid rgba(255, 209, 102, 0.25);
border-radius: 6px;
background: rgba(6, 12, 23, 0.85);
color: #ffe4a3;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.02em;
text-shadow: none;
white-space: nowrap;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.35);
}
.incidence-label.night {
border-color: rgba(255, 123, 123, 0.3);
color: #ffaaaa;
}
.subsolar-label {
color: #fff1b6;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #050914;
color: #8ca4bf;
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading span {
display: inline-block;
width: 26px;
height: 26px;
margin-right: 12px;
border: 2px solid rgba(255, 209, 102, 0.18);
border-top-color: var(--gold);
border-radius: 50%;
animation: spin 800ms linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 900px) {
.data-panel {
width: 270px;
}
.legend,
.hint {
display: none;
}
}
@media (max-width: 680px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.intro p {
display: none;
}
.badges {
margin-top: 11px;
}
.data-panel {
display: none;
}
.controls {
bottom: 12px;
width: calc(100vw - 24px);
padding: 13px;
}
.control-bottom {
align-items: flex-end;
}
.presets button {
padding: 6px 7px;
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="loading"><span></span>Loading low-poly globe…</div>
<div id="labelLayer"></div>
<div class="hud">
<header class="intro panel">
<div class="eyebrow">Earth–Sun Geometry</div>
<h1>Axial Tilt & Solar Incidence</h1>
<p>
The globe’s north axis remains locked at 23.44°. Move the Sun around
Earth to compare direct, oblique, grazing, and night-side illumination.
</p>
<div class="badges">
<span class="badge axis">Axis locked</span>
<span class="badge sun">Parallel sunlight</span>
<span class="badge">23.44° tilt</span>
</div>
</header>
<aside class="data-panel panel">
<div class="panel-heading">
<h2>Incidence by latitude</h2>
<span id="orbitState">June solstice</span>
</div>
<p>
Angles are measured at the sun-facing meridian using the angle
between the ray line and the local outward surface normal.
</p>
<div class="lat-row" data-lat="60">
<span>60° N</span>
<div class="energy"><i></i></div>
<b>—</b>
</div>
<div class="lat-row" data-lat="30">
<span>30° N</span>
<div class="energy"><i></i></div>
<b>—</b>
</div>
<div class="lat-row" data-lat="0">
<span>Equator</span>
<div class="energy"><i></i></div>
<b>—</b>
</div>
<div class="lat-row" data-lat="-30">
<span>30° S</span>
<div class="energy"><i></i></div>
<b>—</b>
</div>
<div class="lat-row" data-lat="-60">
<span>60° S</span>
<div class="energy"><i></i></div>
<b>—</b>
</div>
<div class="panel-note">
Bar length represents the relative direct-beam intensity,
proportional to cos(incidence angle). Cyan segments show local
surface normals; gold segments show incoming sunlight.
</div>
</aside>
<section class="controls panel">
<div class="control-top">
<label for="sunAngle">Sun position around Earth’s orbit</label>
<output id="angleOut" for="sunAngle">0.0°</output>
</div>
<input
id="sunAngle"
type="range"
min="0"
max="360"
step="0.1"
value="0"
aria-label="Sun position around Earth's orbit"
/>
<div class="control-bottom">
<div class="presets">
<button data-angle="0" class="active">Jun solstice</button>
<button data-angle="90">Equinox</button>
<button data-angle="180">Dec solstice</button>
<button data-angle="270">Equinox</button>
<button id="resetCamera" title="Reset the camera">Reset view</button>
</div>
<div class="subsolar">
<span>Subsolar latitude</span>
<strong id="subsolarValue">+23.4°</strong>
</div>
</div>
</section>
<div class="legend">
<div>
<span class="swatch" style="color:#54d7ff;background:#54d7ff"></span>
Equator and parallels
</div>
<div>
<span class="swatch" style="color:#ffffff;background:#ffffff"></span>
Fixed rotation axis
</div>
<div>
<span class="swatch" style="color:#ffd166;background:#ffd166"></span>
Parallel sunlight
</div>
</div>
<div class="hint">
Drag to orbit · Scroll to zoom<br />
Double-click to reset the view
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const DEG = Math.PI / 180;
const RADIUS = 3.15;
const AXIAL_TILT = 23.44 * DEG;
const AXIS = new THREE.Vector3(
Math.sin(AXIAL_TILT),
Math.cos(AXIAL_TILT),
0
).normalize();
const ORBITAL_NORMAL = new THREE.Vector3(0, 1, 0);
const Y_AXIS = new THREE.Vector3(0, 1, 0);
const Z_AXIS = new THREE.Vector3(0, 0, 1);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x050914);
scene.fog = new THREE.FogExp2(0x050914, 0.012);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional globe. Drag to orbit and scroll to zoom."
);
document.body.prepend(renderer.domElement);
// Lighting
scene.add(new THREE.HemisphereLight(0x9bc9ff, 0x081120, 1.05));
scene.add(new THREE.AmbientLight(0x31506f, 0.45));
const sunLight = new THREE.DirectionalLight(0xffedc4, 3.1);
sunLight.target.position.set(0, 0, 0);
scene.add(sunLight);
scene.add(sunLight.target);
// A sparse, deterministic star field.
{
const count = 330;
const positions = new Float32Array(count * 3);
for (let i = 0; i < count; i++) {
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
const radius = 28 + Math.random() * 30;
positions[i * 3] =
radius * Math.sin(phi) * Math.cos(theta);
positions[i * 3 + 1] =
radius * Math.cos(phi);
positions[i * 3 + 2] =
radius * Math.sin(phi) * Math.sin(theta);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
scene.add(
new THREE.Points(
geometry,
new THREE.PointsMaterial({
color: 0xadc8e8,
size: 0.055,
transparent: true,
opacity: 0.58,
depthWrite: false
})
)
);
}
// Low-poly globe with a deliberately simplified procedural map.
function wrapLongitude(value) {
return Math.atan2(Math.sin(value), Math.cos(value));
}
function ellipseContains(lon, lat, cx, cy, rx, ry) {
const dx = wrapLongitude(lon - cx) / rx;
const dy = (lat - cy) / ry;
return dx * dx + dy * dy < 1;
}
function isLand(lon, lat) {
if (lat < -76) return true;
return (
ellipseContains(lon, lat, -105, 45, 48, 24) ||
ellipseContains(lon, lat, -82, 18, 25, 24) ||
ellipseContains(lon, lat, -61, -20, 22, 33) ||
ellipseContains(lon, lat, 18, 7, 27, 37) ||
ellipseContains(lon, lat, 62, 46, 73, 27) ||
ellipseContains(lon, lat, 106, 17, 24, 18) ||
ellipseContains(lon, lat, 135, -26, 25, 14) ||
ellipseContains(lon, lat, -42, 72, 14, 11)
);
}
function createGlobe() {
const source = new THREE.IcosahedronGeometry(RADIUS, 3);
const geometry = source.index ? source.toNonIndexed() : source;
if (source !== geometry) source.dispose();
const position = geometry.getAttribute("position");
const colors = [];
const point = new THREE.Vector3();
const color = new THREE.Color();
for (let face = 0; face < position.count; face += 3) {
point.set(
(position.getX(face) +
position.getX(face + 1) +
position.getX(face + 2)) / 3,
(position.getY(face) +
position.getY(face + 1) +
position.getY(face + 2)) / 3,
(position.getZ(face) +
position.getZ(face + 1) +
position.getZ(face + 2)) / 3
).normalize();
const lat = Math.asin(point.y);
const lon = Math.atan2(point.z, point.x);
const land = isLand(lon, lat);
const variation =
0.92 +
0.12 *
Math.abs(
Math.sin(face * 12.9898 + 78.233) * 43758.5453 -
Math.floor(
Math.sin(face * 12.9898 + 78.233) * 43758.5453
)
);
if (Math.abs(lat) > 73) {
color.set(0xc8e3ea);
} else if (land) {
if (lat > 48 || lat < -43) {
color.set(0x788b69);
} else if (lat > 30 || lat < -28) {
color.set(0x9a925f);
} else {
color.set(0x3e805f);
}
} else {
color.set(0x174f75);
if (lat < -50) color.set(0x204f70);
}
color.multiplyScalar(variation);
for (let vertex = 0; vertex < 3; vertex++) {
colors.push(color.r, color.g, color.b);
}
}
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.88,
metalness: 0.02
});
const globe = new THREE.Mesh(geometry, material);
scene.add(globe);
const wire = new THREE.LineSegments(
new THREE.WireframeGeometry(geometry),
new THREE.LineBasicMaterial({
color: 0xb9dcff,
transparent: true,
opacity: 0.075,
depthWrite: false
})
);
wire.scale.setScalar(1.001);
scene.add(wire);
const atmosphere = new THREE.LineSegments(
new THREE.WireframeGeometry(
new THREE.IcosahedronGeometry(RADIUS * 1.035, 2)
),
new THREE.LineBasicMaterial({
color: 0x55cfff,
transparent: true,
opacity: 0.12,
depthWrite: false
})
);
scene.add(atmosphere);
return globe;
}
const globe = createGlobe();
// Basis perpendicular to the rotation axis.
const ringU = new THREE.Vector3().crossVectors(
Z_AXIS,
AXIS
).normalize();
const ringV = new THREE.Vector3().crossVectors(
AXIS,
ringU
).normalize();
function latitudePoints(latitude, radiusScale = 1.018) {
const phi = latitude * DEG;
const center = AXIS.clone().multiplyScalar(
RADIUS * Math.sin(phi)
);
const radius = RADIUS * Math.cos(phi) * radiusScale;
const points = [];
for (let i = 0; i < 128; i++) {
const theta = (i / 128) * Math.PI * 2;
points.push(
center
.clone()
.addScaledVector(ringU, Math.cos(theta) * radius)
.addScaledVector(ringV, Math.sin(theta) * radius)
);
}
return points;
}
function addLatitudeRing(
latitude,
color,
opacity,
dashed = false,
radiusScale = 1.018
) {
const points = latitudePoints(latitude, radiusScale);
const material = dashed
? new THREE.LineDashedMaterial({
color,
transparent: true,
opacity,
dashSize: 0.14,
gapSize: 0.09,
depthWrite: false
})
: new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
});
const line = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
material
);
if (dashed) line.computeLineDistances();
scene.add(line);
return line;
}
// Equator: a slightly thicker tube.
{
const curve = new THREE.CatmullRomCurve3(
latitudePoints(0, 1.016),
true,
"centripetal"
);
scene.add(
new THREE.Mesh(
new THREE.TubeGeometry(curve, 160, 0.026, 6, true),
new THREE.MeshBasicMaterial({
color: 0x54d7ff,
transparent: true,
opacity: 0.95
})
)
);
}
addLatitudeRing(30, 0x67b8dc, 0.28, true);
addLatitudeRing(60, 0x67b8dc, 0.25, true);
addLatitudeRing(-30, 0x67b8dc, 0.28, true);
addLatitudeRing(-60, 0x67b8dc, 0.25, true);
// Tropics and polar circles.
addLatitudeRing(23.44, 0xffc85b, 0.52, true, 1.02);
addLatitudeRing(-23.44, 0xffc85b, 0.52, true, 1.02);
addLatitudeRing(66.56, 0xae8cff, 0.48, true, 1.02);
addLatitudeRing(-66.56, 0xae8cff, 0.48, true, 1.02);
// The axis is fixed in world space.
{
const shaftLength = (RADIUS + 1.05) * 2;
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.022, 0.022, shaftLength, 8),
new THREE.MeshBasicMaterial({ color: 0xf5f9ff })
);
shaft.quaternion.setFromUnitVectors(Y_AXIS, AXIS);
scene.add(shaft);
const northArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.095, 0.3, 8),
new THREE.MeshBasicMaterial({ color: 0xffffff })
);
northArrow.position.copy(AXIS).multiplyScalar(RADIUS + 1.18);
northArrow.quaternion.setFromUnitVectors(Y_AXIS, AXIS);
scene.add(northArrow);
const southCap = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 10, 6),
new THREE.MeshBasicMaterial({ color: 0xbfd1e6 })
);
southCap.position
.copy(AXIS)
.multiplyScalar(-(RADIUS + 0.95));
scene.add(southCap);
}
// Arc showing the 23.44° departure from the orbital normal.
const tiltArcPoints = [];
for (let i = 0; i <= 40; i++) {
const angle = (i / 40) * AXIAL_TILT;
tiltArcPoints.push(
ORBITAL_NORMAL
.clone()
.multiplyScalar(Math.cos(angle))
.addScaledVector(AXIS, Math.sin(angle))
.multiplyScalar(RADIUS + 0.48)
);
}
const tiltArc = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(tiltArcPoints),
new THREE.LineDashedMaterial({
color: 0xc5d7eb,
dashSize: 0.08,
gapSize: 0.045,
transparent: true,
opacity: 0.75
})
);
tiltArc.computeLineDistances();
scene.add(tiltArc);
// Label helpers.
const labelLayer = document.getElementById("labelLayer");
function createWorldLabel(className = "world-label") {
const element = document.createElement("div");
element.className = className;
labelLayer.appendChild(element);
return element;
}
const northLabel = createWorldLabel();
northLabel.textContent = "North axis";
northLabel.style.color = "#ffffff";
const equatorLabel = createWorldLabel();
equatorLabel.textContent = "Equator";
equatorLabel.style.color = "#54d7ff";
const tiltLabel = createWorldLabel();
tiltLabel.textContent = "23.44° axial tilt";
tiltLabel.style.color = "#d4e3f2";
const sunLabel = createWorldLabel();
sunLabel.textContent = "Sun";
sunLabel.style.color = "#ffe59a";
const subsolarLabel = createWorldLabel("world-label subsolar-label");
subsolarLabel.textContent = "Subsolar point";
// Sun source.
const sunOrb = new THREE.Mesh(
new THREE.SphereGeometry(0.25, 16, 8),
new THREE.MeshBasicMaterial({ color: 0xffd166 })
);
scene.add(sunOrb);
const sunHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.4, 0.014, 6, 32),
new THREE.MeshBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.55,
depthWrite: false
})
);
scene.add(sunHalo);
// Parallel incoming rays.
const rayUOffsets = [-3, -1.5, 0, 1.5, 3];
const rayYOffsets = [-2.6, -1.3, 0, 1.3, 2.6];
const rayMetadata = [];
for (const yOffset of rayYOffsets) {
for (const uOffset of rayUOffsets) {
rayMetadata.push({ uOffset, yOffset });
}
}
const rayPositions = new Float32Array(rayMetadata.length * 6);
const rayGeometry = new THREE.BufferGeometry();
rayGeometry.setAttribute(
"position",
new THREE.BufferAttribute(rayPositions, 3)
);
const rayLines = new THREE.LineSegments(
rayGeometry,
new THREE.LineDashedMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.34,
dashSize: 0.24,
gapSize: 0.12,
depthWrite: false
})
);
scene.add(rayLines);
const rayDotPositions = new Float32Array(rayMetadata.length * 3);
const rayDotGeometry = new THREE.BufferGeometry();
rayDotGeometry.setAttribute(
"position",
new THREE.BufferAttribute(rayDotPositions, 3)
);
const rayDots = new THREE.Points(
rayDotGeometry,
new THREE.PointsMaterial({
color: 0xffe7a1,
size: 0.075,
transparent: true,
opacity: 0.95,
depthWrite: false
})
);
scene.add(rayDots);
const rayArrowMaterial = new THREE.MeshBasicMaterial({
color: 0xffd166,
depthTest: false,
depthWrite: false
});
const rayArrows = rayUOffsets.map(() => {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.075, 0.24, 7),
rayArrowMaterial
);
arrow.renderOrder = 12;
scene.add(arrow);
return arrow;
});
// Local incidence annotations.
const selectedLatitudes = [60, 30, 0, -30, -60];
const normalMaterial = new THREE.LineBasicMaterial({
color: 0x54d7ff,
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false
});
const rayMaterial = new THREE.LineBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
});
const normalArrowMaterial = new THREE.MeshBasicMaterial({
color: 0x54d7ff,
depthTest: false,
depthWrite: false
});
const incomingArrowMaterial = new THREE.MeshBasicMaterial({
color: 0xffd166,
depthTest: false,
depthWrite: false
});
function replaceLinePoints(line, points) {
line.geometry.dispose();
line.geometry = new THREE.BufferGeometry().setFromPoints(points);
line.renderOrder = 14;
}
const incidenceItems = selectedLatitudes.map((latitude) => {
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 10, 6),
new THREE.MeshBasicMaterial({
color: 0xffd166,
depthTest: false,
depthWrite: false
})
);
marker.renderOrder = 18;
scene.add(marker);
const normalLine = new THREE.Line(
new THREE.BufferGeometry(),
normalMaterial
);
normalLine.renderOrder = 14;
scene.add(normalLine);
const incomingLine = new THREE.Line(
new THREE.BufferGeometry(),
rayMaterial
);
incomingLine.renderOrder = 14;
scene.add(incomingLine);
const arc = new THREE.Line(
new THREE.BufferGeometry(),
new THREE.LineBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
})
);
arc.renderOrder = 16;
scene.add(arc);
const normalArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.055, 0.17, 7),
normalArrowMaterial
);
normalArrow.renderOrder = 17;
scene.add(normalArrow);
const incomingArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.055, 0.17, 7),
incomingArrowMaterial
);
incomingArrow.renderOrder = 17;
scene.add(incomingArrow);
const label = createWorldLabel("incidence-label");
return {
latitude,
marker,
normalLine,
incomingLine,
arc,
normalArrow,
incomingArrow,
label,
normal: new THREE.Vector3(),
position: new THREE.Vector3(),
angle: 0
};
});
const subsolarRing = new THREE.Mesh(
new THREE.RingGeometry(0.1, 0.15, 28),
new THREE.MeshBasicMaterial({
color: 0xffe8a6,
side: THREE.DoubleSide,
depthTest: false,
depthWrite: false
})
);
subsolarRing.renderOrder = 19;
scene.add(subsolarRing);
const subsolarPoint = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 10, 6),
new THREE.MeshBasicMaterial({
color: 0xfff1b8,
depthTest: false,
depthWrite: false
})
);
subsolarPoint.renderOrder = 20;
scene.add(subsolarPoint);
let sunDirection = new THREE.Vector3(1, 0, 0);
let currentSunAngle = 0;
function formatLatitude(value) {
const rounded = Math.abs(value) < 0.05 ? 0 : value;
const sign = rounded >= 0 ? "+" : "−";
return `${sign}${Math.abs(rounded).toFixed(1)}°`;
}
function updateIncidence() {
const axisDotSun = THREE.MathUtils.clamp(
AXIS.dot(sunDirection),
-1,
1
);
const subsolarLatitude = Math.asin(axisDotSun) / DEG;
// Direction toward the Sun projected into the equatorial plane.
const sunwardEquatorial = sunDirection
.clone()
.addScaledVector(AXIS, -AXIS.dot(sunDirection))
.normalize();
for (const item of incidenceItems) {
const latitude = item.latitude * DEG;
const normal = AXIS
.clone()
.multiplyScalar(Math.sin(latitude))
.addScaledVector(
sunwardEquatorial,
Math.cos(latitude)
)
.normalize();
const position = normal.clone().multiplyScalar(RADIUS);
const cosine = THREE.MathUtils.clamp(
normal.dot(sunDirection),
-1,
1
);
const angle = Math.acos(cosine);
const night = angle > Math.PI / 2;
item.normal.copy(normal);
item.position.copy(position);
item.angle = angle;
item.marker.position.copy(position);
item.marker.material.color.set(
night ? 0xff7b7b : 0xffd166
);
replaceLinePoints(item.normalLine, [
position,
position.clone().addScaledVector(normal, 1.1)
]);
replaceLinePoints(item.incomingLine, [
position,
position.clone().addScaledVector(sunDirection, 1.6)
]);
// Angle arc between the outward normal and the sunward ray line.
const tangent = sunDirection
.clone()
.addScaledVector(normal, -cosine);
if (tangent.lengthSq() < 1e-6) {
tangent.crossVectors(normal, Y_AXIS);
}
tangent.normalize();
const arcPoints = [];
for (let i = 0; i <= 48; i++) {
const theta = (i / 48) * angle;
arcPoints.push(
position
.clone()
.addScaledVector(normal, Math.cos(theta) * 0.42)
.addScaledVector(tangent, Math.sin(theta) * 0.42)
);
}
replaceLinePoints(item.arc, arcPoints);
item.arc.material.color.set(
night ? 0xff7b7b : 0xffd166
);
item.normalArrow.position
.copy(position)
.addScaledVector(normal, 1.05);
item.normalArrow.quaternion.setFromUnitVectors(
Y_AXIS,
normal
);
item.incomingArrow.position
.copy(position)
.addScaledVector(sunDirection, 1.42);
item.incomingArrow.quaternion.setFromUnitVectors(
Y_AXIS,
sunDirection.clone().negate()
);
const latitudeName =
item.latitude === 0
? "Equator"
: `${Math.abs(item.latitude)}° ${
item.latitude > 0 ? "N" : "S"
}`;
item.label.textContent =
`${latitudeName} · ${(angle / DEG).toFixed(1)}°` +
(night ? " · night" : "");
item.label.classList.toggle("night", night);
}
// Subsolar point: the point whose normal points directly at the Sun.
const subsolarPosition = sunDirection
.clone()
.multiplyScalar(RADIUS + 0.018);
subsolarPoint.position.copy(subsolarPosition);
subsolarRing.position.copy(subsolarPosition);
subsolarRing.quaternion.setFromUnitVectors(
Z_AXIS,
sunDirection
);
document.getElementById("subsolarValue").textContent =
formatLatitude(subsolarLatitude);
let state = "Oblique orbit position";
if (Math.abs(subsolarLatitude - 23.44) < 0.25) {
state = "June solstice";
} else if (Math.abs(subsolarLatitude + 23.44) < 0.25) {
state = "December solstice";
} else if (Math.abs(subsolarLatitude) < 0.25) {
state = "Equinox";
}
document.getElementById("orbitState").textContent = state;
// Update the numerical table.
for (const row of document.querySelectorAll(".lat-row")) {
const latitude = Number(row.dataset.lat);
const item = incidenceItems.find(
(entry) => entry.latitude === latitude
);
const degrees = item.angle / DEG;
const intensity = Math.max(0, Math.cos(item.angle));
const bar = row.querySelector(".energy i");
const value = row.querySelector("b");
value.textContent = `${degrees.toFixed(1)}°`;
bar.style.width = `${(intensity * 100).toFixed(1)}%`;
bar.style.background =
degrees < 30
? "#fff0a6"
: degrees < 70
? "#ffd166"
: "#ff9d5c";
row.classList.toggle("night", item.angle > Math.PI / 2);
}
}
function updateSun(angleDegrees) {
currentSunAngle = angleDegrees;
const angle = angleDegrees * DEG;
// The orbital plane is XZ; its normal is world Y.
sunDirection.set(Math.cos(angle), 0, Math.sin(angle)).normalize();
const tangent = new THREE.Vector3(
-Math.sin(angle),
0,
Math.cos(angle)
).normalize();
const sourceDistance = 8.5;
const rayLength = 20;
rayMetadata.forEach((meta, index) => {
const start = sunDirection
.clone()
.multiplyScalar(sourceDistance)
.addScaledVector(tangent, meta.uOffset)
.addScaledVector(Y_AXIS, meta.yOffset);
const end = start
.clone()
.addScaledVector(sunDirection, -rayLength);
meta.start = start;
meta.end = end;
const offset = index * 6;
rayPositions[offset] = start.x;
rayPositions[offset + 1] = start.y;
rayPositions[offset + 2] = start.z;
rayPositions[offset + 3] = end.x;
rayPositions[offset + 4] = end.y;
rayPositions[offset + 5] = end.z;
});
rayGeometry.attributes.position.needsUpdate = true;
rayLines.computeLineDistances();
rayUOffsets.forEach((uOffset, index) => {
const start = sunDirection
.clone()
.multiplyScalar(sourceDistance)
.addScaledVector(tangent, uOffset);
rayArrows[index].position
.copy(start)
.addScaledVector(sunDirection, -0.35);
rayArrows[index].quaternion.setFromUnitVectors(
Y_AXIS,
sunDirection.clone().negate()
);
});
const sunPosition = sunDirection.clone().multiplyScalar(9.5);
sunOrb.position.copy(sunPosition);
sunHalo.position.copy(sunPosition);
sunHalo.quaternion.setFromUnitVectors(Z_AXIS, sunDirection);
sunLight.position.copy(sunDirection).multiplyScalar(16);
document.getElementById("angleOut").textContent =
`${angleDegrees.toFixed(1)}°`;
document.querySelectorAll("[data-angle]").forEach((button) => {
button.classList.toggle(
"active",
Math.abs(Number(button.dataset.angle) - angleDegrees) < 0.15
);
});
updateIncidence();
}
const sunSlider = document.getElementById("sunAngle");
sunSlider.addEventListener("input", (event) => {
updateSun(Number(event.target.value));
});
document.querySelectorAll("[data-angle]").forEach((button) => {
button.addEventListener("click", () => {
const angle = Number(button.dataset.angle);
sunSlider.value = String(angle);
updateSun(angle);
});
});
// Direct camera controls: no external controls module is used.
const desiredCamera = {
theta: 0.78,
phi: 1.05,
radius: 15.5
};
const currentCamera = {
theta: desiredCamera.theta,
phi: desiredCamera.phi,
radius: desiredCamera.radius
};
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
const canvas = renderer.domElement;
function resetCamera() {
desiredCamera.theta = 0.78;
desiredCamera.phi = 1.05;
desiredCamera.radius = 15.5;
}
canvas.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) return;
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
desiredCamera.theta -= dx * 0.006;
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - dy * 0.006,
0.22,
Math.PI - 0.22
);
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius + event.deltaY * 0.012,
8,
27
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
document.getElementById("resetCamera").addEventListener(
"click",
resetCamera
);
canvas.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") {
desiredCamera.theta += step;
} else if (event.key === "ArrowRight") {
desiredCamera.theta -= step;
} else if (event.key === "ArrowUp") {
desiredCamera.phi = Math.max(
0.22,
desiredCamera.phi - step
);
} else if (event.key === "ArrowDown") {
desiredCamera.phi = Math.min(
Math.PI - 0.22,
desiredCamera.phi + step
);
} else if (event.key === "+" || event.key === "=") {
desiredCamera.radius = Math.max(
8,
desiredCamera.radius - 0.7
);
} else if (event.key === "-") {
desiredCamera.radius = Math.min(
27,
desiredCamera.radius + 0.7
);
} else {
return;
}
event.preventDefault();
});
function projectLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.12 &&
Math.abs(projected.y) < 1.12;
element.style.display = visible ? "block" : "none";
if (visible) {
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
}
function updateLabels() {
projectLabel(
northLabel,
AXIS.clone().multiplyScalar(RADIUS + 1.55)
);
projectLabel(
equatorLabel,
ringU.clone().multiplyScalar(RADIUS + 0.15)
);
projectLabel(
tiltLabel,
ORBITAL_NORMAL.clone()
.add(AXIS)
.normalize()
.multiplyScalar(RADIUS + 0.85)
);
projectLabel(
sunLabel,
sunDirection.clone().multiplyScalar(9.5)
);
projectLabel(
subsolarLabel,
subsolarPoint.position
.clone()
.addScaledVector(sunDirection, 0.3)
);
for (const item of incidenceItems) {
projectLabel(
item.label,
item.position
.clone()
.addScaledVector(item.normal, 0.12)
.addScaledVector(sunDirection, 0.22)
);
}
}
const clock = new THREE.Clock();
const reducedMotion = matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const damping = 1 - Math.exp(-9 * delta);
currentCamera.theta = THREE.MathUtils.lerp(
currentCamera.theta,
desiredCamera.theta,
damping
);
currentCamera.phi = THREE.MathUtils.lerp(
currentCamera.phi,
desiredCamera.phi,
damping
);
currentCamera.radius = THREE.MathUtils.lerp(
currentCamera.radius,
desiredCamera.radius,
damping
);
const sinPhi = Math.sin(currentCamera.phi);
camera.position.set(
currentCamera.radius *
sinPhi *
Math.cos(currentCamera.theta),
currentCamera.radius * Math.cos(currentCamera.phi),
currentCamera.radius *
sinPhi *
Math.sin(currentCamera.theta)
);
camera.lookAt(0, 0, 0);
camera.updateMatrixWorld();
// Moving points reveal the common direction of the light rays.
rayMetadata.forEach((meta, index) => {
const travel = reducedMotion
? (index + 0.5) / rayMetadata.length
: (elapsed * 0.105 + index * 0.071) % 1;
const position = meta.start.clone().lerp(meta.end, travel);
rayDotPositions[index * 3] = position.x;
rayDotPositions[index * 3 + 1] = position.y;
rayDotPositions[index * 3 + 2] = position.z;
});
rayDotGeometry.attributes.position.needsUpdate = true;
const pulse = reducedMotion
? 1
: 1 + Math.sin(elapsed * 2.2) * 0.045;
sunOrb.scale.setScalar(pulse);
updateLabels();
renderer.render(scene, camera);
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
updateSun(0);
animate();
const loading = document.getElementById("loading");
loading.style.opacity = "0";
setTimeout(() => loading.remove(), 380);
</script>
</body>
</html>
```