Prompt specification
Build or customize the Three.js 3D scene "Synthetic colony observation dish" 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: Synthetic colony observation dish
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/synthetic-colony-observation-dish-x0829
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: synthetic colony observation dish. Create a sealed dish illustration with separated colored colony disks and a counting grid; state that the pattern is synthetic and avoid procedural culture instructions. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (synthetic-colony-observation-dish-x0829):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Synthetic Colony Observation Dish</title>
<style>
:root {
color-scheme: dark;
--ink: #e8fffb;
--muted: #91aaa9;
--mint: #55e3ca;
--panel: rgba(5, 18, 24, 0.78);
--line: rgba(130, 236, 219, 0.22);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #061018;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ink);
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active { cursor: grabbing; }
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 45%, transparent 40%, rgba(1, 8, 12, 0.34) 100%),
linear-gradient(180deg, rgba(2, 9, 13, 0.22), transparent 25%, transparent 72%, rgba(2, 8, 12, 0.44));
z-index: 2;
}
.brief {
position: fixed;
z-index: 3;
top: 26px;
left: 28px;
width: min(420px, calc(100vw - 56px));
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(5, 20, 25, 0.66);
color: #b9e8df;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 12px rgba(85, 227, 202, 0.9);
}
h1 {
margin: 15px 0 10px;
max-width: 390px;
font-size: clamp(29px, 4vw, 48px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 760;
text-wrap: balance;
text-shadow: 0 3px 28px rgba(0, 0, 0, 0.45);
}
.lede {
max-width: 380px;
margin: 0;
color: #afc3c1;
font-size: 13px;
line-height: 1.65;
}
.synthetic-note {
display: inline-block;
margin-top: 13px;
padding: 8px 10px;
border-left: 2px solid var(--mint);
background: linear-gradient(90deg, rgba(55, 207, 181, 0.12), transparent);
color: #d7fff6;
font-size: 11px;
line-height: 1.5;
}
.metrics {
position: fixed;
z-index: 3;
left: 28px;
bottom: 26px;
display: flex;
gap: 10px;
pointer-events: none;
}
.metric {
min-width: 112px;
padding: 13px 15px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 14px 45px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(12px);
}
.metric strong {
display: block;
color: #eafff9;
font-size: 24px;
line-height: 1;
letter-spacing: -0.04em;
}
.metric span {
display: block;
margin-top: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend {
position: fixed;
z-index: 3;
right: 28px;
bottom: 26px;
width: 188px;
padding: 14px 15px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 14px 45px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-title {
margin-bottom: 10px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 7px;
color: #c7d8d6;
font-size: 11px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
transform: rotate(45deg);
}
.help {
position: fixed;
z-index: 3;
top: 28px;
right: 28px;
padding: 9px 12px;
border: 1px solid rgba(145, 170, 169, 0.16);
border-radius: 9px;
background: rgba(5, 17, 23, 0.54);
color: #829b99;
font-size: 10px;
letter-spacing: 0.035em;
pointer-events: none;
backdrop-filter: blur(9px);
}
#loading {
position: fixed;
inset: 0;
z-index: 8;
display: grid;
place-items: center;
background: #061018;
color: #8bb8b1;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 0.45s ease, visibility 0.45s ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
@media (max-width: 700px) {
.brief {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
h1 {
max-width: 310px;
font-size: 31px;
}
.lede {
max-width: 310px;
font-size: 11px;
}
.synthetic-note {
max-width: 310px;
}
.help { display: none; }
.metrics {
left: 18px;
bottom: 18px;
gap: 7px;
}
.metric {
min-width: 88px;
padding: 10px 12px;
}
.metric strong { font-size: 20px; }
.legend {
right: 18px;
bottom: 18px;
width: 145px;
padding: 11px 12px;
}
.legend-row { font-size: 9px; }
}
@media (max-width: 460px) {
.legend { display: none; }
.brief { width: calc(100vw - 36px); }
.lede { max-width: 280px; }
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive low-poly synthetic colony observation dish"></div>
<div class="vignette"></div>
<header class="brief">
<div class="eyebrow">
<span class="status-dot"></span>
Sealed observation / synthetic
</div>
<h1>Synthetic Colony Observation Dish</h1>
<p class="lede">
A sealed low-poly illustration with separated colored colony disks,
a clipped 3 × 3 counting grid, and a static observation layout.
</p>
<div class="synthetic-note">
<strong>Pattern is synthetic.</strong> Non-biological visualization only;
no culture procedure is represented.
</div>
</header>
<div class="metrics" aria-label="Scene counts">
<div class="metric">
<strong>18</strong>
<span>Counted disks</span>
</div>
<div class="metric">
<strong>3 × 3</strong>
<span>Counting grid</span>
</div>
</div>
<aside class="legend" aria-label="Color legend">
<div class="legend-title">Display color bands</div>
<div class="legend-row"><i class="swatch" style="background:#ff6f73"></i>Coral</div>
<div class="legend-row"><i class="swatch" style="background:#f6bf58"></i>Amber</div>
<div class="legend-row"><i class="swatch" style="background:#47d8c4"></i>Teal</div>
<div class="legend-row"><i class="swatch" style="background:#a58cff"></i>Violet</div>
</aside>
<div class="help">Drag to orbit · Wheel to zoom · Right-drag to pan</div>
<div id="loading">Preparing synthetic observation scene</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.getElementById("scene");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x061018);
scene.fog = new THREE.FogExp2(0x061018, 0.022);
const camera = new THREE.PerspectiveCamera(
39,
innerWidth / innerHeight,
0.1,
100
);
camera.position.set(8.4, 9.6, 10.2);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
container.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xbcefe6, 0x081016, 1.65);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff4dc, 4.1);
key.position.set(6, 12, 8);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -10;
key.shadow.camera.right = 10;
key.shadow.camera.top = 10;
key.shadow.camera.bottom = -10;
key.shadow.camera.near = 1;
key.shadow.camera.far = 32;
key.shadow.bias = -0.0003;
scene.add(key);
const mintLight = new THREE.PointLight(0x42e4ca, 22, 18, 2);
mintLight.position.set(-7, 5, 5);
scene.add(mintLight);
const violetLight = new THREE.PointLight(0x7868ff, 17, 16, 2);
violetLight.position.set(6, 4, -6);
scene.add(violetLight);
const ground = new THREE.Mesh(
new THREE.CircleGeometry(24, 64),
new THREE.MeshStandardMaterial({
color: 0x07151b,
roughness: 0.96,
metalness: 0.03
})
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const pedestal = new THREE.Group();
scene.add(pedestal);
const pedestalBase = new THREE.Mesh(
new THREE.CylinderGeometry(5.2, 5.45, 0.62, 32),
new THREE.MeshStandardMaterial({
color: 0x112a33,
roughness: 0.62,
metalness: 0.24,
flatShading: true
})
);
pedestalBase.position.y = 0.31;
pedestalBase.castShadow = true;
pedestalBase.receiveShadow = true;
pedestal.add(pedestalBase);
const pedestalTop = new THREE.Mesh(
new THREE.CylinderGeometry(4.95, 5.08, 0.16, 32),
new THREE.MeshStandardMaterial({
color: 0x0b2028,
roughness: 0.46,
metalness: 0.32,
flatShading: true
})
);
pedestalTop.position.y = 0.70;
pedestalTop.castShadow = true;
pedestalTop.receiveShadow = true;
pedestal.add(pedestalTop);
const pedestalEdge = new THREE.Mesh(
new THREE.TorusGeometry(5.02, 0.035, 5, 48),
new THREE.MeshStandardMaterial({
color: 0x3bcab8,
emissive: 0x164e45,
emissiveIntensity: 1.1,
roughness: 0.3
})
);
pedestalEdge.rotation.x = Math.PI / 2;
pedestalEdge.position.y = 0.785;
pedestal.add(pedestalEdge);
const dish = new THREE.Group();
scene.add(dish);
const dishBase = new THREE.Mesh(
new THREE.CylinderGeometry(4.73, 4.73, 0.18, 32),
new THREE.MeshPhysicalMaterial({
color: 0x17434c,
roughness: 0.25,
metalness: 0.08,
transparent: true,
opacity: 0.88,
flatShading: true
})
);
dishBase.position.y = 0.90;
dishBase.castShadow = true;
dishBase.receiveShadow = true;
dish.add(dishBase);
const agar = new THREE.Mesh(
new THREE.CylinderGeometry(4.28, 4.28, 0.10, 40),
new THREE.MeshPhysicalMaterial({
color: 0xc4d8cd,
roughness: 0.72,
metalness: 0,
transparent: true,
opacity: 0.94,
flatShading: true
})
);
agar.position.y = 1.045;
agar.receiveShadow = true;
dish.add(agar);
const lowerRim = new THREE.Mesh(
new THREE.TorusGeometry(4.58, 0.105, 6, 40),
new THREE.MeshPhysicalMaterial({
color: 0x76dcd2,
roughness: 0.18,
metalness: 0.08,
transparent: true,
opacity: 0.72
})
);
lowerRim.rotation.x = Math.PI / 2;
lowerRim.position.y = 1.01;
dish.add(lowerRim);
const gasket = new THREE.Mesh(
new THREE.TorusGeometry(4.57, 0.075, 5, 40),
new THREE.MeshStandardMaterial({
color: 0x153d42,
roughness: 0.55,
metalness: 0.12,
flatShading: true
})
);
gasket.rotation.x = Math.PI / 2;
gasket.position.y = 1.105;
dish.add(gasket);
// Fixed decorative colony layout. This is explicitly synthetic and does not
// describe, prescribe, or model any biological culture procedure.
const colonyLayout = [
{ x: 3.139, z: 0.841, r: 0.235, h: 0.070, color: 0xff6f73 },
{ x: 2.298, z: 2.298, r: 0.205, h: 0.060, color: 0xf6bf58 },
{ x: 0.841, z: 3.139, r: 0.225, h: 0.075, color: 0x47d8c4 },
{ x: -0.841, z: 3.139, r: 0.190, h: 0.055, color: 0xa58cff },
{ x: -2.298, z: 2.298, r: 0.240, h: 0.070, color: 0xff6f73 },
{ x: -3.139, z: 0.841, r: 0.215, h: 0.065, color: 0xf6bf58 },
{ x: -3.139, z: -0.841, r: 0.200, h: 0.060, color: 0x47d8c4 },
{ x: -2.298, z: -2.298, r: 0.230, h: 0.075, color: 0xa58cff },
{ x: -0.841, z: -3.139, r: 0.205, h: 0.060, color: 0xff6f73 },
{ x: 0.841, z: -3.139, r: 0.220, h: 0.070, color: 0xf6bf58 },
{ x: 2.298, z: -2.298, r: 0.195, h: 0.055, color: 0x47d8c4 },
{ x: 3.139, z: -0.841, r: 0.235, h: 0.070, color: 0xa58cff },
{ x: 1.430, z: 0.383, r: 0.175, h: 0.055, color: 0x47d8c4 },
{ x: 0.383, z: 1.430, r: 0.195, h: 0.065, color: 0xa58cff },
{ x: -1.047, z: 1.047, r: 0.185, h: 0.060, color: 0xff6f73 },
{ x: -1.430, z: -0.383, r: 0.205, h: 0.070, color: 0xf6bf58 },
{ x: -0.383, z: -1.430, r: 0.180, h: 0.055, color: 0x47d8c4 },
{ x: 1.047, z: -1.047, r: 0.210, h: 0.065, color: 0xa58cff }
];
const colonies = [];
colonyLayout.forEach((item, index) => {
const colony = new THREE.Mesh(
new THREE.CylinderGeometry(item.r, item.r * 1.03, item.h, 7, 1),
new THREE.MeshStandardMaterial({
color: item.color,
emissive: item.color,
emissiveIntensity: 0.075,
roughness: 0.78,
metalness: 0.02,
flatShading: true
})
);
colony.position.set(item.x, 1.101 + item.h / 2, item.z);
colony.rotation.y = index * 0.47;
colony.castShadow = true;
colony.receiveShadow = true;
colony.userData.delay = (index % 6) * 0.055;
colony.scale.set(0.01, 0.01, 0.01);
dish.add(colony);
colonies.push(colony);
});
// A 3 × 3 grid clipped to a circle.
const gridRadius = 4.08;
const gridOffsets = [-2.75, 0, 2.75];
const gridVertices = [];
gridOffsets.forEach((offset) => {
const extent = Math.sqrt(gridRadius * gridRadius - offset * offset);
gridVertices.push(offset, 1.104, -extent, offset, 1.104, extent);
gridVertices.push(-extent, 1.104, offset, extent, 1.104, offset);
});
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridVertices, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x55d8c5,
transparent: true,
opacity: 0.43,
depthWrite: false
})
);
grid.renderOrder = 2;
dish.add(grid);
const boundaryPoints = [];
for (let i = 0; i < 64; i++) {
const a = (i / 64) * Math.PI * 2;
boundaryPoints.push(
Math.cos(a) * gridRadius,
1.104,
Math.sin(a) * gridRadius
);
}
const boundaryGeometry = new THREE.BufferGeometry();
boundaryGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(boundaryPoints, 3)
);
const boundary = new THREE.Line(
boundaryGeometry,
new THREE.LineBasicMaterial({
color: 0x75ead7,
transparent: true,
opacity: 0.34,
depthWrite: false
})
);
boundary.renderOrder = 2;
dish.add(boundary);
const tickVertices = [];
for (let i = 0; i < 24; i++) {
const a = (i / 24) * Math.PI * 2;
const inner = i % 2 === 0 ? 4.13 : 4.18;
const outer = 4.27;
tickVertices.push(
Math.cos(a) * inner, 1.105, Math.sin(a) * inner,
Math.cos(a) * outer, 1.105, Math.sin(a) * outer
);
}
const tickGeometry = new THREE.BufferGeometry();
tickGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(tickVertices, 3)
);
const ticks = new THREE.LineSegments(
tickGeometry,
new THREE.LineBasicMaterial({
color: 0x8ff2e3,
transparent: true,
opacity: 0.45,
depthWrite: false
})
);
ticks.renderOrder = 2;
dish.add(ticks);
function makeZoneLabel(text) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 64;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(5, 25, 29, 0.78)";
ctx.fillRect(8, 8, 112, 48);
ctx.strokeStyle = "rgba(115, 239, 221, 0.58)";
ctx.lineWidth = 3;
ctx.strokeRect(8, 8, 112, 48);
ctx.fillStyle = "#bff8ed";
ctx.font = "700 28px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 64, 33);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(0.40, 0.20, 1);
sprite.renderOrder = 5;
return sprite;
}
[
["A", -2.75, 3.15],
["B", 0, 3.15],
["C", 2.75, 3.15],
["1", -3.55, -2.20],
["2", -3.55, 0],
["3", -3.55, 2.20]
].forEach(([text, x, z]) => {
const label = makeZoneLabel(text);
label.position.set(x, 1.15, z);
dish.add(label);
});
// Transparent lid, gasket, and top disc visually indicate a sealed dish.
const lidSide = new THREE.Mesh(
new THREE.CylinderGeometry(4.73, 4.73, 0.38, 32, 1, true),
new THREE.MeshPhysicalMaterial({
color: 0xc5fff7,
roughness: 0.16,
metalness: 0,
transparent: true,
opacity: 0.13,
side: THREE.DoubleSide,
depthWrite: false
})
);
lidSide.position.y = 1.295;
lidSide.renderOrder = 6;
dish.add(lidSide);
const lidTop = new THREE.Mesh(
new THREE.CircleGeometry(4.73, 32),
new THREE.MeshPhysicalMaterial({
color: 0xd8fff9,
roughness: 0.14,
metalness: 0,
transparent: true,
opacity: 0.075,
side: THREE.DoubleSide,
depthWrite: false
})
);
lidTop.rotation.x = -Math.PI / 2;
lidTop.position.y = 1.487;
lidTop.renderOrder = 6;
dish.add(lidTop);
const lidEdge = new THREE.Mesh(
new THREE.TorusGeometry(4.66, 0.045, 5, 40),
new THREE.MeshStandardMaterial({
color: 0x9bfff0,
emissive: 0x2d9b88,
emissiveIntensity: 0.7,
roughness: 0.2,
transparent: true,
opacity: 0.78
})
);
lidEdge.rotation.x = Math.PI / 2;
lidEdge.position.y = 1.487;
lidEdge.renderOrder = 7;
dish.add(lidEdge);
// In-world plaque reinforces the synthetic, sealed nature of the illustration.
const plaqueCanvas = document.createElement("canvas");
plaqueCanvas.width = 1024;
plaqueCanvas.height = 256;
const plaqueCtx = plaqueCanvas.getContext("2d");
plaqueCtx.fillStyle = "#06181e";
plaqueCtx.fillRect(0, 0, 1024, 256);
plaqueCtx.strokeStyle = "#48cbb8";
plaqueCtx.lineWidth = 12;
plaqueCtx.strokeRect(12, 12, 1000, 232);
plaqueCtx.textAlign = "center";
plaqueCtx.fillStyle = "#e7fff9";
plaqueCtx.font = "800 58px system-ui, sans-serif";
plaqueCtx.fillText("SYNTHETIC PATTERN", 512, 103);
plaqueCtx.fillStyle = "#7ed8ca";
plaqueCtx.font = "700 34px system-ui, sans-serif";
plaqueCtx.fillText("SEALED • 18 DISKS", 512, 175);
const plaqueTexture = new THREE.CanvasTexture(plaqueCanvas);
plaqueTexture.colorSpace = THREE.SRGBColorSpace;
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(2.85, 0.7125),
new THREE.MeshBasicMaterial({
map: plaqueTexture,
toneMapped: false
})
);
plaque.position.set(0, 0.42, 5.465);
scene.add(plaque);
// Camera controls implemented directly, without external control modules.
const controls = {
target: new THREE.Vector3(0, 1.05, 0),
theta: 0,
phi: 0,
radius: 16.4,
minRadius: 8,
maxRadius: 25,
minPhi: 0.25,
maxPhi: 1.46
};
const initialOffset = camera.position.clone().sub(controls.target);
const initialSpherical = new THREE.Spherical().setFromVector3(initialOffset);
controls.theta = initialSpherical.theta;
controls.phi = initialSpherical.phi;
controls.radius = initialSpherical.radius;
const pointerState = {
pointers: new Map(),
mode: "orbit",
lastX: 0,
lastY: 0,
lastPinchDistance: 0,
lastMidX: 0,
lastMidY: 0
};
const canvas = renderer.domElement;
function midpoint() {
const values = [...pointerState.pointers.values()];
return {
x: (values[0].x + values[1].x) * 0.5,
y: (values[0].y + values[1].y) * 0.5
};
}
function pinchDistance() {
const values = [...pointerState.pointers.values()];
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
function clampControls() {
controls.phi = THREE.MathUtils.clamp(
controls.phi,
controls.minPhi,
controls.maxPhi
);
controls.radius = THREE.MathUtils.clamp(
controls.radius,
controls.minRadius,
controls.maxRadius
);
}
function panCamera(dx, dy) {
camera.updateMatrixWorld();
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const scale = controls.radius * 0.00125;
controls.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
}
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointerState.pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: event.button
});
if (pointerState.pointers.size === 1) {
pointerState.mode =
event.button === 2 || event.shiftKey ? "pan" : "orbit";
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
} else if (pointerState.pointers.size === 2) {
pointerState.mode = "pinch";
pointerState.lastPinchDistance = pinchDistance();
const mid = midpoint();
pointerState.lastMidX = mid.x;
pointerState.lastMidY = mid.y;
}
});
canvas.addEventListener("pointermove", event => {
if (!pointerState.pointers.has(event.pointerId)) return;
pointerState.pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: event.button
});
if (pointerState.pointers.size >= 2) {
const distance = pinchDistance();
const mid = midpoint();
if (pointerState.lastPinchDistance > 0) {
controls.radius *= pointerState.lastPinchDistance / Math.max(distance, 1);
controls.theta -= (mid.x - pointerState.lastMidX) * 0.004;
controls.phi -= (mid.y - pointerState.lastMidY) * 0.004;
}
pointerState.lastPinchDistance = distance;
pointerState.lastMidX = mid.x;
pointerState.lastMidY = mid.y;
clampControls();
return;
}
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
if (pointerState.mode === "pan") {
panCamera(dx, dy);
} else {
controls.theta -= dx * 0.005;
controls.phi -= dy * 0.005;
}
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
clampControls();
});
function endPointer(event) {
pointerState.pointers.delete(event.pointerId);
if (pointerState.pointers.size === 1) {
const remaining = [...pointerState.pointers.values()][0];
pointerState.mode = "orbit";
pointerState.lastX = remaining.x;
pointerState.lastY = remaining.y;
} else if (pointerState.pointers.size === 0) {
pointerState.mode = "orbit";
pointerState.lastPinchDistance = 0;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
controls.radius *= Math.exp(event.deltaY * 0.001);
clampControls();
}, { passive: false });
function updateCamera() {
const offset = new THREE.Vector3().setFromSpherical(
new THREE.Spherical(controls.radius, controls.phi, controls.theta)
);
camera.position.copy(controls.target).add(offset);
camera.lookAt(controls.target);
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", resize);
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
colonies.forEach(colony => {
const localTime = Math.max(0, elapsed - 0.18 - colony.userData.delay);
const t = Math.min(localTime / 0.65, 1);
const eased = 1 - Math.pow(1 - t, 3);
const scale = Math.max(0.01, eased);
colony.scale.set(scale, scale, scale);
});
lidEdge.material.emissiveIntensity =
0.62 + Math.sin(elapsed * 1.7) * 0.09;
updateCamera();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
requestAnimationFrame(() => loading.classList.add("hidden"));
}
}
animate();
</script>
</body>
</html>
```