Prompt specification
Build or customize the Three.js 3D scene "Overlapping colony counting comparison" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Overlapping colony counting comparison
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/overlapping-colony-counting-comparison-x0830
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this stylized scene: Show sparse and crowded invented colony patterns side by side; highlight merged regions that make visual counts ambiguous and separate observed spots from actual cell numbers.
Working Three.js Starter (overlapping-colony-counting-comparison-x0830):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Colony Count — Observed Spots vs. Actual Cells</title>
<style>
:root {
--bg: #071118;
--panel: rgba(13, 28, 37, 0.82);
--line: rgba(175, 220, 224, 0.15);
--text: #eef8f5;
--muted: #91a9ad;
--cyan: #64e4cc;
--amber: #ffb45c;
--pearl: #ffe9ed;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 35%, #102631 0, transparent 48%),
var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body::after {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
background-image:
linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
background-size: 44px 44px;
mask-image: linear-gradient(to bottom, transparent, black 25%, black 75%, transparent);
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.topbar {
position: fixed;
z-index: 10;
top: 26px;
left: 30px;
right: 30px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 24px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 1px;
background: var(--cyan);
box-shadow: 0 0 10px rgba(100, 228, 204, 0.7);
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 43px);
font-weight: 680;
line-height: 0.98;
letter-spacing: -0.045em;
}
h1 span {
color: var(--muted);
font-weight: 430;
}
.subtitle {
margin: 12px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.035em;
}
.controls {
display: flex;
gap: 9px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 999px;
padding: 10px 15px;
background: rgba(12, 26, 34, 0.78);
color: var(--text);
font: inherit;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.035em;
cursor: pointer;
backdrop-filter: blur(14px);
transition:
border-color 160ms ease,
background 160ms ease,
color 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(100, 228, 204, 0.55);
background: rgba(22, 46, 55, 0.9);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 3px;
}
#revealButton {
border-color: rgba(100, 228, 204, 0.38);
color: var(--cyan);
}
#revealButton[aria-pressed="true"] {
color: #071118;
background: var(--cyan);
border-color: var(--cyan);
}
.legend {
position: fixed;
z-index: 10;
left: 30px;
top: 145px;
display: flex;
flex-wrap: wrap;
gap: 8px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 999px;
background: rgba(7, 17, 24, 0.55);
color: #bfd0d1;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.swatch {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
}
.swatch.spot {
background: var(--cyan);
box-shadow: 0 0 8px rgba(100, 228, 204, 0.6);
}
.swatch.merge {
border: 2px solid var(--amber);
background: transparent;
box-shadow: 0 0 8px rgba(255, 180, 92, 0.4);
}
.swatch.cell {
background: var(--pearl);
box-shadow: 0 0 8px rgba(255, 233, 237, 0.55);
transition: opacity 180ms ease;
}
.legend-item.dim .swatch.cell {
opacity: 0.28;
}
.scene-label {
position: fixed;
z-index: 6;
pointer-events: none;
transform: translate(-50%, -100%);
padding: 8px 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 9px;
background: rgba(7, 17, 24, 0.74);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(12px);
white-space: nowrap;
}
.scene-label span {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.scene-label strong {
font-size: 12px;
font-weight: 650;
letter-spacing: 0.02em;
}
.callout {
position: fixed;
z-index: 8;
pointer-events: none;
transform: translate(-50%, calc(-100% - 15px));
padding: 7px 10px;
border: 1px solid rgba(255, 180, 92, 0.52);
border-radius: 8px;
background: rgba(30, 24, 18, 0.88);
color: #ffd3a0;
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(10px);
white-space: nowrap;
}
.callout::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 15px;
background: linear-gradient(var(--amber), transparent);
}
.callout span {
display: block;
margin-bottom: 2px;
color: var(--amber);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.callout b {
font-size: 10px;
font-weight: 720;
letter-spacing: 0.035em;
}
.readouts {
position: fixed;
z-index: 10;
left: 50%;
bottom: 20px;
width: min(930px, calc(100% - 40px));
transform: translateX(-50%);
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
pointer-events: none;
}
.readout-card {
position: relative;
overflow: hidden;
padding: 15px 17px 14px;
border: 1px solid var(--line);
border-radius: 15px;
background:
linear-gradient(135deg, rgba(255, 255, 255, 0.035), transparent 55%),
var(--panel);
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(18px);
}
.readout-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 3px;
background: var(--cyan);
box-shadow: 0 0 16px rgba(100, 228, 204, 0.45);
}
.readout-card.crowded::before {
background: var(--amber);
box-shadow: 0 0 16px rgba(255, 180, 92, 0.4);
}
.readout-head {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
}
.readout-index {
color: var(--cyan);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
}
.crowded .readout-index {
color: var(--amber);
}
.readout-head h2 {
margin: 0;
font-size: 12px;
font-weight: 700;
}
.readout-head p {
margin: 2px 0 0;
color: var(--muted);
font-size: 9px;
}
.observed-badge {
margin-left: auto;
padding: 5px 8px;
border: 1px solid rgba(100, 228, 204, 0.24);
border-radius: 999px;
color: var(--cyan);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.crowded .observed-badge {
border-color: rgba(255, 180, 92, 0.28);
color: var(--amber);
}
.metric-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.metric {
padding-top: 10px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.metric span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 780;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 3px;
font-size: 25px;
font-weight: 620;
line-height: 1;
letter-spacing: -0.04em;
}
.metric.actual strong {
color: var(--pearl);
}
.delta {
margin-top: 11px;
color: #ffca8e;
font-size: 9px;
font-weight: 650;
letter-spacing: 0.025em;
}
.hint {
position: fixed;
z-index: 10;
left: 30px;
bottom: 145px;
color: rgba(185, 207, 208, 0.58);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.06em;
pointer-events: none;
}
.tooltip {
position: fixed;
z-index: 20;
display: none;
min-width: 165px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 9px;
background: rgba(6, 15, 21, 0.94);
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.38);
pointer-events: none;
backdrop-filter: blur(14px);
}
.tooltip strong {
display: block;
color: var(--cyan);
font-size: 10px;
letter-spacing: 0.04em;
}
.tooltip span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
@media (max-width: 720px) {
.topbar {
top: 18px;
left: 18px;
right: 18px;
}
h1 {
max-width: 240px;
font-size: 25px;
}
h1 span {
display: block;
margin-top: 3px;
font-size: 18px;
}
.subtitle,
.legend,
.hint {
display: none;
}
.controls {
flex-direction: column;
align-items: flex-end;
}
button {
padding: 8px 11px;
font-size: 9px;
}
.readouts {
width: calc(100% - 24px);
bottom: 12px;
gap: 7px;
}
.readout-card {
padding: 11px;
border-radius: 12px;
}
.readout-head {
margin-bottom: 8px;
}
.readout-head p,
.observed-badge {
display: none;
}
.metric span {
font-size: 7px;
}
.metric strong {
font-size: 20px;
}
.delta {
font-size: 7px;
line-height: 1.35;
}
.callout {
transform: translate(-50%, calc(-100% - 8px)) scale(0.88);
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="topbar">
<div>
<div class="eyebrow">Synthetic morphology study · 01</div>
<h1>Morphology <span>≠ Count</span></h1>
<p class="subtitle">
Two invented colony patterns. Visible spots are not always individual cells.
</p>
</div>
<div class="controls">
<button id="revealButton" type="button" aria-pressed="false">
Reveal actual cells
</button>
<button id="resetButton" type="button">Reset view</button>
</div>
</header>
<div class="legend" aria-label="Scene legend">
<div class="legend-item">
<i class="swatch spot"></i>
Observed spot
</div>
<div class="legend-item">
<i class="swatch merge"></i>
Merged region
</div>
<div class="legend-item dim" id="cellLegend">
<i class="swatch cell"></i>
Actual cell
</div>
</div>
<div class="scene-label" id="sparseLabel">
<span>Culture 01</span>
<strong>Sparse / separated colonies</strong>
</div>
<div class="scene-label" id="crowdedLabel">
<span>Culture 02</span>
<strong>Crowded / overlapping colonies</strong>
</div>
<div class="callout" id="sparseCallout">
<span>Ambiguous merged region</span>
<b>3 cells → 1 observed spot</b>
</div>
<div class="callout" id="crowdedCallout">
<span>Ambiguous merged region</span>
<b>6 cells → 1 observed spot</b>
</div>
<div class="hint">
DRAG TO ORBIT · SHIFT/RIGHT-DRAG TO PAN · SCROLL TO ZOOM · HOVER A SPOT
</div>
<section class="readouts" aria-label="Observed and actual colony counts">
<article class="readout-card">
<div class="readout-head">
<span class="readout-index">01</span>
<div>
<h2>Sparse culture</h2>
<p>Mostly distinguishable colonies</p>
</div>
<span class="observed-badge">Lower ambiguity</span>
</div>
<div class="metric-row">
<div class="metric">
<span>Observed spots</span>
<strong id="sparseObserved">—</strong>
</div>
<div class="metric actual">
<span>Actual cells</span>
<strong id="sparseActual">—</strong>
</div>
</div>
<div class="delta" id="sparseDelta">—</div>
</article>
<article class="readout-card crowded">
<div class="readout-head">
<span class="readout-index">02</span>
<div>
<h2>Crowded culture</h2>
<p>Dense growth with substantial merging</p>
</div>
<span class="observed-badge">High ambiguity</span>
</div>
<div class="metric-row">
<div class="metric">
<span>Observed spots</span>
<strong id="crowdedObserved">—</strong>
</div>
<div class="metric actual">
<span>Actual cells</span>
<strong id="crowdedActual">—</strong>
</div>
</div>
<div class="delta" id="crowdedDelta">—</div>
</article>
</section>
<div class="tooltip" id="tooltip"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const tooltip = document.querySelector("#tooltip");
const revealButton = document.querySelector("#revealButton");
const resetButton = document.querySelector("#resetButton");
const cellLegend = document.querySelector("#cellLegend");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071118);
scene.fog = new THREE.Fog(0x071118, 25, 52);
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.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D comparison of sparse and crowded colony patterns"
);
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
120
);
const view = {
theta: 0,
phi: 0.72,
radius: 21,
target: new THREE.Vector3(0, 0, 0)
};
let userAdjustedCamera = false;
let revealActualCells = false;
let hoveredRecord = null;
const hemisphere = new THREE.HemisphereLight(0xbce8ed, 0x16232d, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xe8fffb, 3.2);
keyLight.position.set(-7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1536, 1536);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 15;
keyLight.shadow.camera.bottom = -15;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x48d8ca, 22, 35, 2);
rimLight.position.set(0, 5, -8);
scene.add(rimLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshStandardMaterial({
color: 0x08151d,
roughness: 0.96,
metalness: 0.02
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.45;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(52, 52, 0x1a4550, 0x102a33);
grid.position.y = -0.425;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
function mulberry32(seed) {
return function random() {
let value = seed += 0x6D2B79F5;
value = Math.imul(value ^ value >>> 15, value | 1);
value ^= value + Math.imul(value ^ value >>> 7, value | 61);
return ((value ^ value >>> 14) >>> 0) / 4294967296;
};
}
function roundedRectangle(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const shape = new THREE.Shape();
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
function createPanelBase(parent, accent) {
const shape = roundedRectangle(8, 8.8, 0.48);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.22,
bevelEnabled: true,
bevelSegments: 4,
steps: 1,
bevelSize: 0.06,
bevelThickness: 0.05,
curveSegments: 16
});
geometry.rotateX(-Math.PI / 2);
const panel = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: 0x10222b,
roughness: 0.72,
metalness: 0.14
})
);
panel.position.y = -0.34;
panel.receiveShadow = true;
parent.add(panel);
const borderPoints = shape
.getPoints(20)
.map(point => new THREE.Vector3(point.x, point.y, 0.025));
const border = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(borderPoints),
new THREE.LineBasicMaterial({
color: accent,
transparent: true,
opacity: 0.24
})
);
border.rotation.x = -Math.PI / 2;
border.position.y = -0.065;
parent.add(border);
const dish = new THREE.Mesh(
new THREE.CylinderGeometry(3.5, 3.5, 0.11, 96),
new THREE.MeshPhysicalMaterial({
color: 0x4db6b3,
transparent: true,
opacity: 0.15,
roughness: 0.25,
metalness: 0.05,
clearcoat: 0.7,
clearcoatRoughness: 0.25,
depthWrite: false
})
);
dish.position.y = -0.005;
parent.add(dish);
const cultureField = new THREE.Mesh(
new THREE.CircleGeometry(3.36, 96),
new THREE.MeshStandardMaterial({
color: 0x0b2931,
roughness: 0.9,
metalness: 0.02,
transparent: true,
opacity: 0.94,
side: THREE.DoubleSide
})
);
cultureField.rotation.x = -Math.PI / 2;
cultureField.position.y = 0.055;
cultureField.receiveShadow = true;
parent.add(cultureField);
const outerRing = new THREE.Mesh(
new THREE.TorusGeometry(3.48, 0.035, 10, 96),
new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0.62
})
);
outerRing.rotation.x = Math.PI / 2;
outerRing.position.y = 0.072;
parent.add(outerRing);
const innerRing = new THREE.Mesh(
new THREE.TorusGeometry(3.22, 0.012, 8, 96),
new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0.18
})
);
innerRing.rotation.x = Math.PI / 2;
innerRing.position.y = 0.066;
parent.add(innerRing);
}
const cellMaterial = new THREE.MeshStandardMaterial({
color: 0xffedf1,
roughness: 0.3,
metalness: 0.05,
emissive: 0x5a2634,
emissiveIntensity: 0.3
});
const hitTargets = [];
function createCulture(config) {
const root = new THREE.Group();
root.position.x = config.x;
scene.add(root);
createPanelBase(root, config.accent);
const actualCells = new THREE.Group();
actualCells.visible = false;
root.add(actualCells);
const random = mulberry32(config.seed);
const records = [];
const goldenAngle = Math.PI * (3 - Math.sqrt(5));
config.counts.forEach((cellCount, index) => {
const count = config.counts.length;
const angle =
index * goldenAngle + (random() - 0.5) * 0.15;
const radial =
2.43 * Math.sqrt((index + 0.5) / count) +
(random() - 0.5) * 0.08;
const centerX = Math.cos(angle) * radial;
const centerZ = Math.sin(angle) * radial;
const merged = cellCount > 1;
const radiusX = merged
? cellCount <= 3
? 0.34
: 0.48
: 0.135;
const radiusZ = radiusX * (0.78 + random() * 0.25);
if (merged) {
const mergeHalo = new THREE.Mesh(
new THREE.CircleGeometry(1, 48),
new THREE.MeshBasicMaterial({
color: 0xffb45c,
transparent: true,
opacity: 0.09,
depthWrite: false,
side: THREE.DoubleSide
})
);
mergeHalo.rotation.x = -Math.PI / 2;
mergeHalo.position.set(centerX, 0.066, centerZ);
mergeHalo.scale.set(radiusX * 1.18, radiusZ * 1.18, 1);
mergeHalo.renderOrder = 1;
root.add(mergeHalo);
}
const observedDisc = new THREE.Mesh(
new THREE.CircleGeometry(1, 48),
new THREE.MeshBasicMaterial({
color: merged ? 0x57dbc5 : 0x72efd7,
transparent: true,
opacity: merged ? 0.28 : 0.47,
depthWrite: false,
side: THREE.DoubleSide
})
);
observedDisc.rotation.x = -Math.PI / 2;
observedDisc.position.set(centerX, 0.074, centerZ);
observedDisc.scale.set(radiusX, radiusZ, 1);
observedDisc.renderOrder = 2;
root.add(observedDisc);
const outline = new THREE.Mesh(
new THREE.RingGeometry(0.88, 1.02, 64),
new THREE.MeshBasicMaterial({
color: merged ? 0xffb45c : 0x64e4cc,
transparent: true,
opacity: merged ? 0.72 : 0.42,
depthWrite: false,
side: THREE.DoubleSide
})
);
outline.rotation.x = -Math.PI / 2;
outline.position.set(centerX, 0.087, centerZ);
outline.scale.set(radiusX, radiusZ, 1);
outline.renderOrder = 3;
root.add(outline);
const cellPositions = [];
for (let cellIndex = 0; cellIndex < cellCount; cellIndex++) {
let offsetX = 0;
let offsetZ = 0;
if (cellCount > 1) {
const cellAngle =
cellIndex * goldenAngle + random() * 0.22;
const cellRadius = cellCount <= 3
? 0.115
: 0.28 * Math.sqrt((cellIndex + 0.5) / cellCount);
offsetX = Math.cos(cellAngle) * cellRadius;
offsetZ = Math.sin(cellAngle) * cellRadius;
}
const position = {
x: centerX + offsetX,
z: centerZ + offsetZ
};
cellPositions.push(position);
const cell = new THREE.Mesh(
new THREE.SphereGeometry(0.067, 14, 10),
cellMaterial
);
cell.position.set(position.x, 0.17, position.z);
cell.castShadow = true;
actualCells.add(cell);
}
const hitTarget = new THREE.Mesh(
new THREE.CircleGeometry(1, 32),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false,
side: THREE.DoubleSide
})
);
hitTarget.rotation.x = -Math.PI / 2;
hitTarget.position.set(centerX, 0.095, centerZ);
hitTarget.scale.set(radiusX * 1.25, radiusZ * 1.25, 1);
root.add(hitTarget);
const record = {
id: index + 1,
count: cellCount,
merged,
observedDisc,
outline,
hitTarget,
baseScaleX: radiusX,
baseScaleZ: radiusZ,
phase: random() * Math.PI * 2,
cellPositions
};
hitTarget.userData.record = record;
hitTargets.push(hitTarget);
records.push(record);
});
const labelAnchor = new THREE.Object3D();
labelAnchor.position.set(0, 0.15, -3.92);
root.add(labelAnchor);
const calloutRecord =
records.find(record => record.count === config.calloutCount) ||
records.find(record => record.merged);
return {
root,
actualCells,
records,
labelAnchor,
calloutRecord,
counts: config.counts
};
}
const sparse = createCulture({
x: -4.55,
seed: 4281,
accent: 0x64e4cc,
calloutCount: 3,
// 18 observed spots: 15 single cells + 3 merged groups of 3.
counts: [
3, 1, 1, 3, 1, 3,
1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1
]
});
const crowded = createCulture({
x: 4.55,
seed: 9173,
accent: 0xffb45c,
calloutCount: 6,
// 20 observed spots: 8 singles + 8 groups of 5 + 4 groups of 6.
counts: [
5, 1, 5, 1, 6, 1, 5, 1, 6, 1,
5, 1, 5, 5, 6, 1, 5, 5, 6, 1
]
});
function updateReadouts(culture, prefix) {
const observed = culture.records.length;
const actual = culture.counts.reduce((sum, count) => sum + count, 0);
const mergedRegions = culture.records.filter(record => record.merged).length;
const concealed = actual - observed;
document.querySelector(`#${prefix}Observed`).textContent = observed;
document.querySelector(`#${prefix}Actual`).textContent = actual;
document.querySelector(`#${prefix}Delta`).textContent =
`${concealed} cells concealed across ${mergedRegions} merged regions`;
}
updateReadouts(sparse, "sparse");
updateReadouts(crowded, "crowded");
const sparseCalloutAnchor = new THREE.Object3D();
sparseCalloutAnchor.position.set(
sparse.calloutRecord.hitTarget.position.x,
0.24,
sparse.calloutRecord.hitTarget.position.z
);
sparse.root.add(sparseCalloutAnchor);
const crowdedCalloutAnchor = new THREE.Object3D();
crowdedCalloutAnchor.position.set(
crowded.calloutRecord.hitTarget.position.x,
0.24,
crowded.calloutRecord.hitTarget.position.z
);
crowded.root.add(crowdedCalloutAnchor);
function updateRevealState() {
revealButton.setAttribute("aria-pressed", String(revealActualCells));
revealButton.textContent = revealActualCells
? "Hide actual cells"
: "Reveal actual cells";
cellLegend.classList.toggle("dim", !revealActualCells);
for (const culture of [sparse, crowded]) {
culture.actualCells.visible = revealActualCells;
for (const record of culture.records) {
record.observedDisc.material.opacity = revealActualCells
? record.merged
? 0.13
: 0.2
: record.merged
? 0.28
: 0.47;
}
}
}
revealButton.addEventListener("click", () => {
revealActualCells = !revealActualCells;
updateRevealState();
});
function fittedRadius() {
const halfVerticalFov = THREE.MathUtils.degToRad(camera.fov * 0.5);
const horizontalFit =
9.6 / (Math.tan(halfVerticalFov) * camera.aspect);
return Math.max(20.5, horizontalFit);
}
function applyCamera() {
const sinPhi = Math.sin(view.phi);
const cosPhi = Math.cos(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * cosPhi,
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
camera.updateMatrixWorld();
}
function resetView() {
view.theta = 0;
view.phi = 0.72;
view.radius = fittedRadius();
view.target.set(0, 0, 0);
userAdjustedCamera = false;
applyCamera();
}
resetButton.addEventListener("click", resetView);
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
if (!userAdjustedCamera) {
view.radius = fittedRadius();
}
applyCamera();
}
window.addEventListener("resize", onResize);
// Custom orbit / pan / zoom controls, implemented without Three.js addons.
const canvas = renderer.domElement;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let dragMode = "orbit";
let previousX = 0;
let previousY = 0;
let activePointerId = null;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
dragging = true;
activePointerId = event.pointerId;
dragMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = dragMode === "pan" ? "grabbing" : "move";
tooltip.style.display = "none";
});
canvas.addEventListener("pointermove", event => {
if (dragging && event.pointerId === activePointerId) {
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
userAdjustedCamera = true;
if (dragMode === "orbit") {
view.theta = THREE.MathUtils.clamp(
view.theta - deltaX * 0.0045,
-0.62,
0.62
);
view.phi = THREE.MathUtils.clamp(
view.phi + deltaY * 0.0035,
0.42,
1.18
);
} else {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3()
.subVectors(camera.position, view.target);
forward.y = 0;
forward.normalize();
const scale = view.radius * 0.0014;
view.target.addScaledVector(right, -deltaX * scale);
view.target.addScaledVector(forward, -deltaY * scale);
view.target.x = THREE.MathUtils.clamp(view.target.x, -2.2, 2.2);
view.target.z = THREE.MathUtils.clamp(view.target.z, -1.4, 1.4);
}
applyCamera();
return;
}
pointer.x = event.clientX / window.innerWidth * 2 - 1;
pointer.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(hitTargets, false);
if (intersections.length) {
const record = intersections[0].object.userData.record;
if (hoveredRecord && hoveredRecord !== record) {
hoveredRecord.outline.material.opacity = hoveredRecord.merged
? 0.72
: 0.42;
}
hoveredRecord = record;
record.outline.material.opacity = record.merged ? 1 : 0.8;
tooltip.innerHTML = revealActualCells
? `<strong>Observed spot ${String(record.id).padStart(2, "0")}</strong>
<span>${record.count} actual cell${record.count === 1 ? "" : "s"} in this visible region</span>`
: `<strong>Observed spot ${String(record.id).padStart(2, "0")}</strong>
<span>${record.merged ? "Merged region — internal cells are hidden" : "A single visible colony spot"}</span>`;
tooltip.style.display = "block";
const tooltipWidth = 230;
const left = Math.min(
event.clientX + 15,
window.innerWidth - tooltipWidth - 10
);
const top = Math.min(
event.clientY + 15,
window.innerHeight - 65
);
tooltip.style.left = `${left}px`;
tooltip.style.top = `${top}px`;
canvas.style.cursor = "pointer";
} else {
if (hoveredRecord) {
hoveredRecord.outline.material.opacity = hoveredRecord.merged
? 0.72
: 0.42;
}
hoveredRecord = null;
tooltip.style.display = "none";
canvas.style.cursor = "grab";
}
});
function endDrag(event) {
if (!dragging) return;
dragging = false;
activePointerId = null;
canvas.style.cursor = "grab";
if (event.pointerId !== undefined &&
canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("pointerleave", () => {
if (!dragging) {
tooltip.style.display = "none";
}
});
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
userAdjustedCamera = true;
const zoomFactor = Math.exp(event.deltaY * 0.001);
view.radius = THREE.MathUtils.clamp(
view.radius * zoomFactor,
fittedRadius() * 0.65,
fittedRadius() * 1.45
);
applyCamera();
},
{ passive: false }
);
window.addEventListener("keydown", event => {
if (event.key === "ArrowLeft") {
view.theta = THREE.MathUtils.clamp(view.theta - 0.07, -0.62, 0.62);
} else if (event.key === "ArrowRight") {
view.theta = THREE.MathUtils.clamp(view.theta + 0.07, -0.62, 0.62);
} else if (event.key === "ArrowUp") {
view.phi = THREE.MathUtils.clamp(view.phi - 0.05, 0.42, 1.18);
} else if (event.key === "ArrowDown") {
view.phi = THREE.MathUtils.clamp(view.phi + 0.05, 0.42, 1.18);
} else if (event.key === "+" || event.key === "=") {
view.radius = Math.max(fittedRadius() * 0.65, view.radius - 0.8);
} else if (event.key === "-") {
view.radius = Math.min(fittedRadius() * 1.45, view.radius + 0.8);
} else if (event.key.toLowerCase() === "r") {
resetView();
} else {
return;
}
userAdjustedCamera = true;
applyCamera();
});
const projectionPoint = new THREE.Vector3();
function placeOverlay(element, object) {
object.getWorldPosition(projectionPoint);
projectionPoint.project(camera);
const visible = projectionPoint.z > -1 && projectionPoint.z < 1;
const x = (projectionPoint.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projectionPoint.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = visible ? "1" : "0";
}
const sparseLabel = document.querySelector("#sparseLabel");
const crowdedLabel = document.querySelector("#crowdedLabel");
const sparseCallout = document.querySelector("#sparseCallout");
const crowdedCallout = document.querySelector("#crowdedCallout");
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
for (const culture of [sparse, crowded]) {
for (const record of culture.records) {
if (!record.merged) continue;
const pulse = reducedMotion
? 1
: 1 + Math.sin(elapsed * 2.1 + record.phase) * 0.025;
record.outline.scale.set(
record.baseScaleX * pulse,
record.baseScaleZ * pulse,
1
);
if (!reducedMotion) {
record.outline.material.opacity =
record === hoveredRecord
? 0.98
: 0.64 + Math.sin(elapsed * 2.1 + record.phase) * 0.12;
}
}
}
renderer.render(scene, camera);
placeOverlay(sparseLabel, sparse.labelAnchor);
placeOverlay(crowdedLabel, crowded.labelAnchor);
placeOverlay(sparseCallout, sparseCalloutAnchor);
placeOverlay(crowdedCallout, crowdedCalloutAnchor);
}
updateRevealState();
applyCamera();
animate();
</script>
</body>
</html>
```