Prompt specification
Build or customize the Three.js 3D scene "Daily weather tile calendar" 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: Daily weather tile calendar
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/daily-weather-tile-calendar-x1269
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing daily weather variability. Create a grid of thirty raised day tiles with temperature bars and simple rain markers; keep invented values labeled synthetic and make daily variability visible. Low-poly.
Working Three.js Starter (daily-weather-tile-calendar-x1269):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>30 Days of Synthetic Weather</title>
<style>
:root {
color-scheme: dark;
--ink: #edf8fb;
--muted: #9db4bc;
--panel: rgba(9, 23, 31, 0.82);
--line: rgba(186, 229, 240, 0.16);
--accent: #70d7bc;
--rain: #59c9ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #08141b;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#app {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
z-index: 10;
pointer-events: none;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 18px;
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.intro {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 22px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
content: "";
background: var(--accent);
border-radius: 50%;
box-shadow: 0 0 16px rgba(112, 215, 188, 0.8);
}
h1 {
margin: 10px 0 8px;
font-size: clamp(25px, 3vw, 38px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.intro p {
margin: 0;
max-width: 34ch;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.synthetic-pill {
display: inline-flex;
align-items: center;
margin-top: 15px;
padding: 7px 10px;
color: #ffe5a4;
background: rgba(242, 203, 104, 0.1);
border: 1px solid rgba(242, 203, 104, 0.28);
border-radius: 999px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.metrics {
display: flex;
gap: 24px;
margin-top: 18px;
padding-top: 16px;
border-top: 1px solid var(--line);
}
.metric strong,
.metric span {
display: block;
}
.metric strong {
font-size: 17px;
letter-spacing: -0.02em;
}
.metric span {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend {
top: 22px;
right: 22px;
width: 245px;
padding: 18px;
}
.legend h2 {
margin: 0 0 14px;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.temperature-scale {
height: 9px;
background: linear-gradient(
90deg,
#59b9d6 0%,
#70d7bc 37.5%,
#f2cb68 75%,
#f16d5f 100%
);
border-radius: 99px;
box-shadow: 0 0 18px rgba(112, 215, 188, 0.12);
}
.scale-labels {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 16px;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.rain-icon {
position: relative;
width: 18px;
height: 22px;
flex: 0 0 18px;
}
.rain-icon::before,
.rain-icon::after {
position: absolute;
width: 8px;
height: 12px;
content: "";
background: var(--rain);
border-radius: 70% 20% 65% 35%;
transform: rotate(45deg);
box-shadow: 0 0 10px rgba(89, 201, 255, 0.45);
}
.rain-icon::before {
left: 1px;
top: 2px;
}
.rain-icon::after {
right: 0;
bottom: 1px;
opacity: 0.55;
}
.reset {
width: 100%;
margin-top: 16px;
padding: 9px 12px;
color: var(--ink);
background: rgba(255, 255, 255, 0.045);
border: 1px solid var(--line);
border-radius: 9px;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
pointer-events: auto;
transition: background 160ms ease, border-color 160ms ease;
}
.reset:hover {
background: rgba(255, 255, 255, 0.09);
border-color: rgba(186, 229, 240, 0.3);
}
.control-hint {
position: fixed;
z-index: 10;
bottom: 20px;
left: 50%;
padding: 9px 13px;
color: var(--muted);
background: rgba(7, 18, 25, 0.72);
border: 1px solid var(--line);
border-radius: 999px;
font-size: 10px;
letter-spacing: 0.06em;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(12px);
white-space: nowrap;
}
.control-hint b {
color: var(--ink);
font-weight: 700;
}
@media (max-width: 760px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px;
}
.intro p {
display: none;
}
h1 {
margin-top: 8px;
font-size: 25px;
}
.synthetic-pill {
position: absolute;
top: 15px;
right: 15px;
margin: 0;
padding: 6px 8px;
font-size: 8px;
}
.metrics {
gap: 18px;
margin-top: 12px;
padding-top: 11px;
}
.metric strong {
font-size: 14px;
}
.metric span {
font-size: 8px;
}
.legend {
top: auto;
right: 12px;
bottom: 54px;
width: 205px;
padding: 13px;
}
.legend h2 {
margin-bottom: 10px;
font-size: 10px;
}
.legend-row {
margin-top: 11px;
font-size: 9px;
}
.reset {
margin-top: 11px;
padding: 7px 10px;
font-size: 9px;
}
.control-hint {
bottom: 12px;
font-size: 9px;
}
}
</style>
</head>
<body>
<main
id="app"
role="img"
aria-label="A low-poly three-dimensional grid of thirty synthetic weather days. Bar height and color show temperature; blue drops mark rain."
></main>
<header class="hud intro">
<div class="eyebrow">30-day weather field</div>
<h1>Weather, day by day.</h1>
<p>
Thirty raised tiles turn an invented month into a tactile landscape.
Taller, warmer bars and floating blue drops reveal each day’s variation.
</p>
<div class="synthetic-pill">Synthetic values · not a forecast</div>
<div class="metrics">
<div class="metric">
<strong id="rangeMetric">10°–34°C</strong>
<span>Synthetic range</span>
</div>
<div class="metric">
<strong id="rainMetric">11 / 30</strong>
<span>Rain days</span>
</div>
</div>
</header>
<aside class="hud legend">
<h2>How to read the grid</h2>
<div class="temperature-scale"></div>
<div class="scale-labels">
<span>10°C</span>
<span>22°C</span>
<span>34°C</span>
</div>
<div class="legend-row">
<span class="rain-icon" aria-hidden="true"></span>
<span>Blue faceted drops mark synthetic rain days.</span>
</div>
<div class="legend-row">
<span aria-hidden="true">↕</span>
<span>Each bar’s height also encodes its daily temperature.</span>
</div>
<button class="reset" id="resetView" type="button">Reset camera</button>
</aside>
<div class="control-hint">
<b>Drag</b> to orbit · <b>Scroll / pinch</b> 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";
// ------------------------------------------------------------
// Invented data. These are intentionally not real observations.
// ------------------------------------------------------------
const temperatures = [
12, 14, 11, 18, 23, 21, 26, 29, 27, 31,
33, 30, 24, 22, 19, 17, 13, 10, 12, 16,
21, 25, 28, 32, 34, 29, 23, 18, 15, 13
];
const rainAmounts = [
0, 0, 2, 0, 0, 4, 0, 0, 1, 0,
0, 2, 5, 0, 0, 3, 0, 7, 0, 0,
2, 0, 0, 0, 1, 4, 0, 0, 5, 0
];
const minimumTemperature = Math.min(...temperatures);
const maximumTemperature = Math.max(...temperatures);
const rainyDays = rainAmounts.filter((amount) => amount > 0).length;
document.querySelector("#rangeMetric").textContent =
`${minimumTemperature}°–${maximumTemperature}C`;
document.querySelector("#rainMetric").textContent =
`${rainyDays} / ${temperatures.length}`;
// ------------------------------------------------------------
// Renderer, scene, camera, and lighting
// ------------------------------------------------------------
const mount = document.querySelector("#app");
const renderer = new THREE.WebGLRenderer({
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.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly grid of thirty synthetic daily weather observations"
);
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08141b);
scene.fog = new THREE.FogExp2(0x08141b, 0.026);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(
0xc5efff,
0x152126,
1.65
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedcf, 3.1);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0007;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x70bfff, 1.15);
rim.position.set(9, 7, -10);
scene.add(rim);
// ------------------------------------------------------------
// Materials and shared geometry
// ------------------------------------------------------------
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x0a171e,
roughness: 1,
metalness: 0
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.52;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(
40,
20,
0x355461,
0x203944
);
grid.position.y = -0.505;
grid.material.transparent = true;
grid.material.opacity = 0.2;
scene.add(grid);
const board = new THREE.Mesh(
new THREE.BoxGeometry(14.4, 0.38, 10.4),
new THREE.MeshStandardMaterial({
color: 0x10242d,
roughness: 0.88,
metalness: 0.04
})
);
board.position.y = -0.31;
board.castShadow = true;
board.receiveShadow = true;
scene.add(board);
const boardSurface = new THREE.Mesh(
new THREE.BoxGeometry(13.95, 0.05, 9.95),
new THREE.MeshStandardMaterial({
color: 0x142a33,
roughness: 0.95
})
);
boardSurface.position.y = -0.105;
boardSurface.receiveShadow = true;
scene.add(boardSurface);
const boardEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(board.geometry),
new THREE.LineBasicMaterial({
color: 0x83a7b4,
transparent: true,
opacity: 0.2
})
);
boardEdges.position.copy(board.position);
scene.add(boardEdges);
const tileGeometry = new THREE.BoxGeometry(1.78, 0.26, 1.42);
const tileTopGeometry = new THREE.BoxGeometry(1.62, 0.035, 1.26);
const barGeometry = new THREE.BoxGeometry(0.34, 1, 0.34);
barGeometry.translate(0, 0.5, 0);
const dropGeometry = new THREE.ConeGeometry(0.095, 0.23, 5, 1);
dropGeometry.rotateZ(Math.PI);
const puddleGeometry = new THREE.CircleGeometry(0.19, 8);
const dropMaterial = new THREE.MeshStandardMaterial({
color: 0x59c9ff,
emissive: 0x0b3650,
emissiveIntensity: 0.45,
roughness: 0.35,
metalness: 0.08,
flatShading: true,
transparent: true,
opacity: 0.88
});
const puddleMaterial = new THREE.MeshBasicMaterial({
color: 0x59c9ff,
transparent: true,
opacity: 0.28,
depthWrite: false,
side: THREE.DoubleSide
});
const outlineMaterial = new THREE.LineBasicMaterial({
color: 0xc7edf5,
transparent: true,
opacity: 0.2
});
const barOutlineMaterial = new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.2
});
const colorStops = [
{ value: 10, color: new THREE.Color(0x59b9d6) },
{ value: 18, color: new THREE.Color(0x70d7bc) },
{ value: 26, color: new THREE.Color(0xf2cb68) },
{ value: 34, color: new THREE.Color(0xf16d5f) }
];
function temperatureColor(value) {
if (value <= colorStops[0].value) {
return colorStops[0].color.clone();
}
for (let i = 0; i < colorStops.length - 1; i++) {
const a = colorStops[i];
const b = colorStops[i + 1];
if (value <= b.value) {
const amount = (value - a.value) / (b.value - a.value);
return a.color.clone().lerp(b.color, amount);
}
}
return colorStops[colorStops.length - 1].color.clone();
}
// ------------------------------------------------------------
// Canvas-based labels. These remain readable while orbiting.
// ------------------------------------------------------------
function roundedRectangle(context, x, y, width, height, radius) {
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + width - radius, y);
context.quadraticCurveTo(x + width, y, x + width, y + radius);
context.lineTo(x + width, y + height - radius);
context.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
context.lineTo(x + radius, y + height);
context.quadraticCurveTo(
x,
y + height,
x,
y + height - radius
);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
}
function createTextSprite(
text,
{
worldWidth,
worldHeight,
foreground = "#f2fbfd",
background = "rgba(7, 20, 28, 0.90)",
border = "rgba(195, 229, 237, 0.22)",
fontSize = 58,
canvasWidth = 256,
canvasHeight = 112
} = {}
) {
const canvas = document.createElement("canvas");
canvas.width = canvasWidth;
canvas.height = canvasHeight;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvasWidth, canvasHeight);
roundedRectangle(
context,
5,
5,
canvasWidth - 10,
canvasHeight - 10,
24
);
context.fillStyle = background;
context.fill();
context.strokeStyle = border;
context.lineWidth = 3;
context.stroke();
context.fillStyle = foreground;
context.font = `800 ${fontSize}px system-ui, sans-serif`;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(
text,
canvasWidth / 2,
canvasHeight / 2 + 2
);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.needsUpdate = true;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldHeight, 1);
sprite.renderOrder = 50;
return sprite;
}
// ------------------------------------------------------------
// Build the 6 × 5 grid of raised day tiles
// ------------------------------------------------------------
const rainDrops = [];
const columns = 6;
const rows = 5;
const gapX = 2.08;
const gapZ = 1.75;
for (let dayIndex = 0; dayIndex < 30; dayIndex++) {
const column = dayIndex % columns;
const row = Math.floor(dayIndex / columns);
const temperature = temperatures[dayIndex];
const rainAmount = rainAmounts[dayIndex];
const normalized =
(temperature - minimumTemperature) /
(maximumTemperature - minimumTemperature);
const tileGroup = new THREE.Group();
tileGroup.position.set(
(column - (columns - 1) / 2) * gapX,
0,
(row - (rows - 1) / 2) * gapZ
);
scene.add(tileGroup);
const tileTint = new THREE.Color(0x19333d);
tileTint.lerp(new THREE.Color(0x49352f), normalized * 0.55);
const tileMaterial = new THREE.MeshStandardMaterial({
color: tileTint,
roughness: 0.82,
metalness: 0.03,
flatShading: true
});
const tile = new THREE.Mesh(tileGeometry, tileMaterial);
tile.castShadow = true;
tile.receiveShadow = true;
tileGroup.add(tile);
const tileEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(tileGeometry),
outlineMaterial
);
tile.add(tileEdges);
const topMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color(0x203a43).lerp(
new THREE.Color(0x453833),
normalized * 0.4
),
roughness: 0.92,
flatShading: true
});
const tileTop = new THREE.Mesh(tileTopGeometry, topMaterial);
tileTop.position.y = 0.145;
tileTop.receiveShadow = true;
tileGroup.add(tileTop);
// Temperature bar: base-pivot geometry makes scaling from the floor easy.
const barHeight = 0.55 + normalized * 1.82;
const barColor = temperatureColor(temperature);
const bar = new THREE.Mesh(
barGeometry,
new THREE.MeshStandardMaterial({
color: barColor,
emissive: barColor.clone().multiplyScalar(0.12),
emissiveIntensity: 0.32,
roughness: 0.5,
metalness: 0.05,
flatShading: true
})
);
bar.position.set(0.16, 0.165, -0.12);
bar.scale.y = barHeight;
bar.castShadow = true;
bar.receiveShadow = true;
tileGroup.add(bar);
const barEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(barGeometry),
barOutlineMaterial
);
bar.add(barEdges);
const dayLabel = createTextSprite(
`D${String(dayIndex + 1).padStart(2, "0")}`,
{
worldWidth: 0.54,
worldHeight: 0.24,
fontSize: 52,
canvasWidth: 256,
canvasHeight: 96,
background: "rgba(7, 19, 27, 0.94)",
border: "rgba(186, 229, 240, 0.24)"
}
);
dayLabel.position.set(-0.48, 0.29, 0.46);
tileGroup.add(dayLabel);
const temperatureLabel = createTextSprite(
`${temperature}°`,
{
worldWidth: 0.72,
worldHeight: 0.31,
fontSize: 62,
background: "rgba(7, 20, 28, 0.91)",
border: `#${barColor.getHexString()}`
}
);
temperatureLabel.position.set(
0.16,
0.165 + barHeight + 0.22,
-0.12
);
tileGroup.add(temperatureLabel);
if (rainAmount > 0) {
const dropCount =
rainAmount >= 6 ? 3 : rainAmount >= 3 ? 2 : 1;
const puddle = new THREE.Mesh(
puddleGeometry,
puddleMaterial
);
puddle.rotation.x = -Math.PI / 2;
puddle.scale.setScalar(0.7 + Math.min(rainAmount, 7) * 0.07);
puddle.position.set(-0.53, 0.169, -0.12);
tileGroup.add(puddle);
for (let dropIndex = 0; dropIndex < dropCount; dropIndex++) {
const drop = new THREE.Mesh(
dropGeometry,
dropMaterial
);
const offset = dropIndex - (dropCount - 1) / 2;
const baseY = 0.55 + (dropIndex % 2) * 0.25;
drop.position.set(
-0.53 + offset * 0.16,
baseY,
-0.13 + (dropIndex % 2) * 0.07
);
drop.castShadow = true;
drop.userData.baseY = baseY;
drop.userData.phase = dayIndex * 0.71 + dropIndex * 1.37;
tileGroup.add(drop);
rainDrops.push(drop);
}
}
}
// ------------------------------------------------------------
// Custom orbit camera controls — implemented directly, without
// importing any camera-control addons.
// ------------------------------------------------------------
const orbit = {
theta: 0.42,
phi: 0.86,
radius: 19.2,
goalTheta: 0.42,
goalPhi: 0.86,
goalRadius: 19.2,
target: new THREE.Vector3(0, 0.43, 0)
};
const pointers = new Map();
let pinchDistance = null;
function clamp(value, minimum, maximum) {
return Math.max(minimum, Math.min(maximum, value));
}
function currentPinchDistance() {
const values = [...pointers.values()];
if (values.length < 2) return null;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
function resetView(instant = true) {
const isNarrow = window.innerWidth < 760;
orbit.goalTheta = 0.42;
orbit.goalPhi = 0.86;
orbit.goalRadius = isNarrow ? 26.5 : 19.2;
if (instant) {
orbit.theta = orbit.goalTheta;
orbit.phi = orbit.goalPhi;
orbit.radius = orbit.goalRadius;
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
pinchDistance = currentPinchDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const pointer = pointers.get(event.pointerId);
if (!pointer) return;
const deltaX = event.clientX - pointer.x;
const deltaY = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointers.size === 1) {
orbit.goalTheta -= deltaX * 0.006;
orbit.goalPhi = clamp(
orbit.goalPhi + deltaY * 0.005,
0.32,
1.28
);
} else if (pointers.size === 2) {
const distance = currentPinchDistance();
if (distance && pinchDistance) {
orbit.goalRadius = clamp(
orbit.goalRadius * (pinchDistance / distance),
12.5,
42
);
}
pinchDistance = distance;
}
});
function removePointer(event) {
pointers.delete(event.pointerId);
pinchDistance = pointers.size === 2 ? currentPinchDistance() : null;
}
renderer.domElement.addEventListener("pointerup", removePointer);
renderer.domElement.addEventListener("pointercancel", removePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.goalRadius = clamp(
orbit.goalRadius * Math.exp(event.deltaY * 0.001),
12.5,
42
);
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
document.querySelector("#resetView").addEventListener("click", () => {
resetView(true);
});
function updateCamera(deltaTime) {
const damping = 1 - Math.exp(-12 * deltaTime);
orbit.theta += (orbit.goalTheta - orbit.theta) * damping;
orbit.phi += (orbit.goalPhi - orbit.phi) * damping;
orbit.radius += (orbit.goalRadius - orbit.radius) * damping;
const sinPhi = Math.sin(orbit.phi);
const cosPhi = Math.cos(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * cosPhi,
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
// ------------------------------------------------------------
// Responsive rendering
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.fov = width < 760 ? 52 : 42;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
resetView(true);
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
function animate() {
const deltaTime = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera(deltaTime);
if (!reducedMotion) {
for (const drop of rainDrops) {
drop.position.y =
drop.userData.baseY +
Math.sin(elapsed * 2.1 + drop.userData.phase) * 0.035;
}
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```