Prompt specification
Build or customize the Three.js 3D scene "Popcorn event timeline" 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: Popcorn event timeline
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/popcorn-event-timeline-x0138
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a small popcorn event timeline in low-poly form. Place a handful of distinct kernels inside a transparent vessel, each with a stable identifier shown by a small nearby marker. During playback, kernels change into enlarged irregular popcorn shapes at different authored moments, staying within the vessel and retaining their identities. Show the before and after counts on a short timeline beneath the display. Use a gentle transformation and a small upward hop rather than an explosive burst. This is a schematic illustration of expansion, so it should not provide realistic heating temperatures or cooking instructions.
Working Three.js Starter (popcorn-event-timeline-x0138):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Popcorn Expansion Timeline</title>
<style>
:root {
--ink: #2d302c;
--muted: #72776f;
--paper: #f4f0e7;
--card: rgba(255, 253, 248, 0.88);
--line: #d9d5ca;
--accent: #d47a43;
--accent-soft: #f0d8c7;
--green: #668f7b;
--shadow: 0 18px 55px rgba(57, 53, 42, 0.11);
}
* {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100svh;
color: var(--ink);
background:
radial-gradient(circle at 14% 10%, #fffaf1 0, transparent 30%),
radial-gradient(circle at 88% 82%, #dce8df 0, transparent 32%),
var(--paper);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
.app {
width: min(1160px, calc(100% - 32px));
margin: 0 auto;
padding: 26px 0 34px;
}
header {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 24px;
margin-bottom: 18px;
}
.eyebrow {
margin: 0 0 7px;
color: var(--accent);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.7rem, 4vw, 3rem);
font-weight: 720;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
max-width: 510px;
margin: 12px 0 0;
color: var(--muted);
font-size: 0.94rem;
line-height: 1.55;
}
.identity-note {
flex: 0 0 auto;
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 1px solid rgba(70, 93, 80, 0.18);
border-radius: 999px;
background: rgba(255, 255, 255, 0.46);
color: #4f665a;
font-size: 0.78rem;
font-weight: 700;
white-space: nowrap;
}
.identity-note::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 5px rgba(102, 143, 123, 0.12);
content: "";
}
.stage {
position: relative;
height: clamp(390px, 58svh, 610px);
overflow: hidden;
border: 1px solid rgba(101, 103, 92, 0.16);
border-radius: 24px;
background:
linear-gradient(180deg, rgba(255, 255, 255, 0.48), rgba(244, 240, 231, 0.16)),
radial-gradient(circle at 50% 45%, #fffefb 0%, #e9eee8 72%, #dce4df 100%);
box-shadow: var(--shadow);
isolation: isolate;
}
#canvasHost {
position: absolute;
inset: 0;
}
#canvasHost canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#canvasHost canvas:active {
cursor: grabbing;
}
.stage-top {
position: absolute;
z-index: 2;
top: 18px;
left: 18px;
right: 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.scene-label,
.state-pill {
border: 1px solid rgba(80, 85, 76, 0.12);
border-radius: 999px;
background: rgba(255, 255, 255, 0.7);
box-shadow: 0 6px 20px rgba(63, 65, 57, 0.06);
backdrop-filter: blur(10px);
}
.scene-label {
padding: 9px 12px;
color: #656a62;
font-size: 0.73rem;
font-weight: 760;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.state-pill {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 12px;
color: #59625a;
font-size: 0.76rem;
font-weight: 700;
}
.state-pill::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
content: "";
}
.drag-hint {
position: absolute;
z-index: 2;
left: 18px;
bottom: 17px;
padding: 7px 10px;
border-radius: 9px;
background: rgba(255, 255, 255, 0.55);
color: #81857e;
font-size: 0.69rem;
pointer-events: none;
}
.timeline-card {
margin-top: 14px;
padding: 16px 18px 13px;
border: 1px solid rgba(101, 103, 92, 0.15);
border-radius: 20px;
background: var(--card);
box-shadow: 0 10px 35px rgba(61, 58, 48, 0.07);
backdrop-filter: blur(16px);
}
.transport {
display: flex;
align-items: center;
gap: 9px;
padding-bottom: 13px;
border-bottom: 1px solid rgba(103, 105, 96, 0.11);
}
.play-button,
.reset-button {
min-height: 36px;
border-radius: 10px;
cursor: pointer;
transition:
transform 140ms ease,
background 140ms ease,
border-color 140ms ease;
}
.play-button {
min-width: 138px;
padding: 0 15px;
border: 1px solid #b96337;
background: var(--accent);
color: white;
font-size: 0.79rem;
font-weight: 760;
box-shadow: 0 5px 12px rgba(212, 122, 67, 0.2);
}
.reset-button {
padding: 0 12px;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.65);
color: #666b64;
font-size: 0.78rem;
font-weight: 680;
}
.play-button:hover,
.reset-button:hover {
transform: translateY(-1px);
}
.play-button:active,
.reset-button:active {
transform: translateY(0);
}
.clock {
margin-left: auto;
color: #747970;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.76rem;
font-variant-numeric: tabular-nums;
}
.timeline-grid {
display: grid;
grid-template-columns: 112px minmax(220px, 1fr) 112px;
align-items: center;
gap: 18px;
padding-top: 14px;
}
.count-card {
min-width: 0;
padding: 10px 12px;
border: 1px solid rgba(105, 108, 99, 0.12);
border-radius: 13px;
background: rgba(255, 255, 255, 0.5);
}
.count-card.after {
text-align: right;
}
.count-label {
display: block;
color: #8a8e86;
font-size: 0.62rem;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.count-value {
display: inline-block;
margin: 3px 6px 0 0;
font-size: 1.45rem;
font-weight: 760;
line-height: 1;
font-variant-numeric: tabular-nums;
}
.count-unit {
color: #777c74;
font-size: 0.7rem;
font-weight: 650;
}
.timeline-center {
min-width: 0;
}
.track-wrap {
position: relative;
height: 61px;
}
.track-label {
position: absolute;
top: 0;
transform: translateX(-50%);
color: #92958f;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.59rem;
font-weight: 750;
pointer-events: none;
}
.event-dot {
position: absolute;
z-index: 3;
top: 17px;
width: 9px;
height: 9px;
transform: translate(-50%, -50%);
border: 2px solid #fffaf0;
border-radius: 50%;
background: #aeb2aa;
box-shadow: 0 0 0 1px #bfc2ba;
pointer-events: none;
transition: background 180ms ease, box-shadow 180ms ease;
}
.event-dot.passed {
background: var(--accent);
box-shadow: 0 0 0 1px var(--accent), 0 0 0 5px var(--accent-soft);
}
#scrubber {
--progress: 0%;
position: absolute;
z-index: 4;
top: 9px;
left: 0;
width: 100%;
height: 22px;
margin: 0;
appearance: none;
background: transparent;
cursor: pointer;
}
#scrubber::-webkit-slider-runnable-track {
height: 4px;
border-radius: 999px;
background:
linear-gradient(
to right,
var(--accent) 0%,
var(--accent) var(--progress),
#d9d5ca var(--progress),
#d9d5ca 100%
);
}
#scrubber::-moz-range-track {
height: 4px;
border-radius: 999px;
background: #d9d5ca;
}
#scrubber::-moz-range-progress {
height: 4px;
border-radius: 999px;
background: var(--accent);
}
#scrubber::-webkit-slider-thumb {
width: 16px;
height: 16px;
margin-top: -6px;
appearance: none;
border: 3px solid white;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 1px 6px rgba(72, 55, 42, 0.3);
}
#scrubber::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid white;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 1px 6px rgba(72, 55, 42, 0.3);
}
.timeline-caption {
display: flex;
justify-content: space-between;
gap: 12px;
color: #989b94;
font-size: 0.61rem;
font-weight: 650;
}
.timeline-note {
margin: 12px 2px 0;
color: #8a8e86;
font-size: 0.69rem;
line-height: 1.45;
}
@media (max-width: 720px) {
.app {
width: min(100% - 20px, 1160px);
padding-top: 18px;
}
header {
align-items: flex-start;
flex-direction: column;
gap: 13px;
}
.identity-note {
align-self: flex-start;
}
.stage {
height: 470px;
border-radius: 18px;
}
.timeline-grid {
grid-template-columns: 86px minmax(170px, 1fr) 86px;
gap: 8px;
}
.count-card {
padding: 9px;
}
.count-value {
font-size: 1.25rem;
}
.count-unit {
display: block;
margin-top: 3px;
}
.timeline-card {
padding-right: 12px;
padding-left: 12px;
}
.state-pill {
max-width: 55%;
text-align: right;
}
}
@media (prefers-reduced-motion: reduce) {
button,
.event-dot {
transition: none;
}
}
</style>
</head>
<body>
<div class="app">
<header>
<div>
<p class="eyebrow">Microscopic expansion study</p>
<h1>Five kernels. Five identities.</h1>
<p class="subtitle">
A schematic low-poly timeline showing kernels expanding into popcorn
while their markers remain attached to the same objects.
</p>
</div>
<div class="identity-note">5 tracked identities</div>
</header>
<main>
<section class="stage" aria-label="Interactive three-dimensional popcorn vessel">
<div id="canvasHost"></div>
<div class="stage-top">
<div class="scene-label">Transparent vessel / fixed identities</div>
<div class="state-pill" id="stateText">All 5 kernels unexpanded</div>
</div>
<div class="drag-hint">Drag to orbit · scroll to zoom</div>
</section>
<section class="timeline-card" aria-label="Popcorn expansion timeline">
<div class="transport">
<button class="play-button" id="playButton" type="button">Play expansion</button>
<button class="reset-button" id="resetButton" type="button">Reset</button>
<div class="clock" id="clock">0.0s / 9.6s</div>
</div>
<div class="timeline-grid">
<div class="count-card before">
<span class="count-label">Before</span>
<span class="count-value" id="beforeCount">5</span>
<span class="count-unit">unexpanded</span>
</div>
<div class="timeline-center">
<div class="track-wrap" id="trackWrap">
<input
id="scrubber"
type="range"
min="0"
max="9.6"
step="0.01"
value="0"
aria-label="Expansion timeline"
/>
</div>
<div class="timeline-caption">
<span>Start</span>
<span id="transitionText">0 in transition</span>
<span>End</span>
</div>
</div>
<div class="count-card after">
<span class="count-label">After</span>
<span class="count-value" id="afterCount">0</span>
<span class="count-unit">expanded</span>
</div>
</div>
<p class="timeline-note">
Illustrative expansion timing only. This is a schematic animation,
not a heating guide or a set of cooking instructions.
</p>
</section>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const host = document.getElementById("canvasHost");
const playButton = document.getElementById("playButton");
const resetButton = document.getElementById("resetButton");
const scrubber = document.getElementById("scrubber");
const clock = document.getElementById("clock");
const beforeCount = document.getElementById("beforeCount");
const afterCount = document.getElementById("afterCount");
const stateText = document.getElementById("stateText");
const transitionText = document.getElementById("transitionText");
const trackWrap = document.getElementById("trackWrap");
const DURATION = 9.6;
const TRANSITION_DURATION = 1.75;
// Authored moments are relative to the illustration's playback timeline.
const events = [1.15, 2.70, 4.05, 5.55, 7.00];
const kernelColors = [
0xd6a23c,
0xe1b451,
0xc98f32,
0xe4ba60,
0xd09a3d
];
const markerColors = [
"#cb714c",
"#648c78",
"#8b78a2",
"#4f829a",
"#b38a35"
];
const scene = new THREE.Scene();
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x000000, 0);
host.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.28, 0);
// Small custom orbit implementation; no external controls are imported.
const orbit = {
radius: 8.15,
phi: 1.16,
theta: 0.56,
dragging: false,
pointerX: 0,
pointerY: 0
};
function updateCamera() {
const spherical = new THREE.Spherical(
orbit.radius,
orbit.phi,
orbit.theta
);
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
orbit.dragging = true;
orbit.pointerX = event.clientX;
orbit.pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!orbit.dragging) return;
const dx = event.clientX - orbit.pointerX;
const dy = event.clientY - orbit.pointerY;
orbit.pointerX = event.clientX;
orbit.pointerY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.72,
1.43
);
});
function stopDragging(event) {
orbit.dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.005,
6.4,
10.7
);
},
{ passive: false }
);
const hemisphere = new THREE.HemisphereLight(0xfff8e8, 0x8ca7a2, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2d7, 3.1);
keyLight.position.set(4.5, 7, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -4;
keyLight.shadow.camera.right = 4;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -3;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 18;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc8e5e4, 1.25);
fillLight.position.set(-4, 3.5, -3);
scene.add(fillLight);
const shadowPlane = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.ShadowMaterial({
color: 0x5f6259,
opacity: 0.14
})
);
shadowPlane.rotation.x = -Math.PI / 2;
shadowPlane.position.y = -0.015;
shadowPlane.receiveShadow = true;
scene.add(shadowPlane);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(2.38, 2.46, 0.16, 64),
new THREE.MeshStandardMaterial({
color: 0xe9e3d6,
roughness: 0.92,
metalness: 0
})
);
platform.position.y = 0.08;
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const platformRing = new THREE.Mesh(
new THREE.RingGeometry(2.06, 2.095, 64),
new THREE.MeshBasicMaterial({
color: 0xd4b268,
transparent: true,
opacity: 0.55,
side: THREE.DoubleSide
})
);
platformRing.rotation.x = -Math.PI / 2;
platformRing.position.y = 0.162;
scene.add(platformRing);
// Transparent vessel.
const vesselHeight = 2.35;
const vesselY = 1.42;
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xb7d9d4,
transparent: true,
opacity: 0.17,
roughness: 0.18,
metalness: 0,
clearcoat: 0.45,
clearcoatRoughness: 0.25,
side: THREE.DoubleSide,
depthWrite: false
});
const vessel = new THREE.Mesh(
new THREE.CylinderGeometry(
1.68,
1.48,
vesselHeight,
48,
1,
true
),
glassMaterial
);
vessel.position.y = vesselY;
vessel.renderOrder = 4;
scene.add(vessel);
const rimMaterial = new THREE.MeshStandardMaterial({
color: 0x729995,
transparent: true,
opacity: 0.66,
roughness: 0.36,
metalness: 0.08,
depthWrite: false
});
const topRim = new THREE.Mesh(
new THREE.TorusGeometry(1.68, 0.025, 8, 72),
rimMaterial
);
topRim.rotation.x = Math.PI / 2;
topRim.position.y = vesselY + vesselHeight / 2;
topRim.renderOrder = 5;
scene.add(topRim);
const bottomRim = new THREE.Mesh(
new THREE.TorusGeometry(1.48, 0.023, 8, 72),
rimMaterial
);
bottomRim.rotation.x = Math.PI / 2;
bottomRim.position.y = vesselY - vesselHeight / 2;
bottomRim.renderOrder = 5;
scene.add(bottomRim);
const vesselFloor = new THREE.Mesh(
new THREE.CylinderGeometry(1.48, 1.48, 0.045, 48),
new THREE.MeshPhysicalMaterial({
color: 0xc7e2dc,
transparent: true,
opacity: 0.19,
roughness: 0.25,
depthWrite: false
})
);
vesselFloor.position.y = vesselY - vesselHeight / 2 + 0.02;
vesselFloor.renderOrder = 3;
scene.add(vesselFloor);
function seededRandom(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function smoothStep(value) {
const x = THREE.MathUtils.clamp(value, 0, 1);
return x * x * (3 - 2 * x);
}
function makeRoundedRect(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.arcTo(x + width, y, x + width, y + height, r);
context.arcTo(x + width, y + height, x, y + height, r);
context.arcTo(x, y + height, x, y, r);
context.arcTo(x, y, x + width, y, r);
context.closePath();
}
function makeMarkerTexture(index) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 96;
const context = canvas.getContext("2d");
const accent = markerColors[index];
makeRoundedRect(context, 10, 13, 236, 70, 22);
context.fillStyle = "rgba(255, 253, 248, 0.94)";
context.fill();
context.lineWidth = 3;
context.strokeStyle = accent;
context.stroke();
context.beginPath();
context.arc(42, 48, 9, 0, Math.PI * 2);
context.fillStyle = accent;
context.fill();
context.fillStyle = "#414740";
context.font = "700 31px ui-monospace, SFMono-Regular, Menlo, monospace";
context.textBaseline = "middle";
context.fillText(
`K${String(index + 1).padStart(2, "0")}`,
64,
49
);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.needsUpdate = true;
return texture;
}
function makePopcornShape(index) {
const random = seededRandom(804 + index * 97);
const group = new THREE.Group();
const warmColors = [
0xffefd0,
0xfff2d8,
0xf7e8c9,
0xffedc7,
0xf5e5c5
];
const material = new THREE.MeshStandardMaterial({
color: warmColors[index],
roughness: 0.82,
metalness: 0,
flatShading: true
});
const cavityMaterial = new THREE.MeshStandardMaterial({
color: 0xd7b979,
roughness: 0.95,
flatShading: true
});
const core = new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 1),
material
);
core.scale.set(0.25, 0.22, 0.24);
core.position.y = 0.015;
core.castShadow = true;
group.add(core);
const lobeGeometry = new THREE.IcosahedronGeometry(1, 0);
const cavityGeometry = new THREE.SphereGeometry(1, 8, 5);
for (let lobeIndex = 0; lobeIndex < 7; lobeIndex++) {
const angle = random() * Math.PI * 2;
const radius = 0.20 + random() * 0.075;
const size = 0.17 + random() * 0.095;
const lobe = new THREE.Mesh(lobeGeometry, material);
lobe.position.set(
Math.cos(angle) * radius,
(random() - 0.43) * 0.25,
Math.sin(angle) * radius
);
lobe.scale.set(
size * (0.85 + random() * 0.28),
size * (0.7 + random() * 0.25),
size * (0.82 + random() * 0.3)
);
lobe.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
lobe.castShadow = true;
group.add(lobe);
if (lobeIndex < 3) {
const cavity = new THREE.Mesh(cavityGeometry, cavityMaterial);
cavity.position.copy(lobe.position);
cavity.position.x *= 1.13;
cavity.position.z *= 1.13;
cavity.position.y += 0.025;
cavity.scale.set(0.048, 0.027, 0.014);
cavity.rotation.y = -angle;
group.add(cavity);
}
}
group.userData.baseRotationY = random() * Math.PI * 2;
group.rotation.y = group.userData.baseRotationY;
return group;
}
const kernels = [];
for (let index = 0; index < 5; index++) {
const angle = index * (Math.PI * 2 / 5) + 0.28;
const radius = 0.87;
const baseY = 0.68 + (index % 2) * 0.10;
const identityGroup = new THREE.Group();
identityGroup.position.set(
Math.cos(angle) * radius,
baseY,
Math.sin(angle) * radius
);
scene.add(identityGroup);
const rawGroup = new THREE.Group();
const random = seededRandom(300 + index * 41);
const rawMaterial = new THREE.MeshStandardMaterial({
color: kernelColors[index],
roughness: 0.88,
metalness: 0,
flatShading: true
});
const rawKernel = new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 1),
rawMaterial
);
rawKernel.scale.set(0.285, 0.185, 0.225);
rawKernel.rotation.set(
random() * 0.35,
random() * Math.PI * 2,
random() * 0.25
);
rawKernel.castShadow = true;
rawGroup.add(rawKernel);
const creaseMaterial = new THREE.MeshStandardMaterial({
color: 0x936b31,
roughness: 0.95,
flatShading: true
});
const crease = new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 0),
creaseMaterial
);
crease.scale.set(0.075, 0.028, 0.025);
crease.position.set(0.08, 0.105, 0.18);
crease.rotation.set(0.3, 0.4, -0.25);
rawGroup.add(crease);
identityGroup.add(rawGroup);
const popcornGroup = makePopcornShape(index);
popcornGroup.scale.setScalar(0.001);
identityGroup.add(popcornGroup);
const marker = new THREE.Sprite(
new THREE.SpriteMaterial({
map: makeMarkerTexture(index),
transparent: true,
depthTest: false,
depthWrite: false
})
);
marker.scale.set(0.55, 0.206, 1);
marker.renderOrder = 20;
scene.add(marker);
const kernel = {
identityGroup,
rawGroup,
popcornGroup,
marker,
baseY,
event: events[index],
index
};
kernels.push(kernel);
const label = document.createElement("span");
label.className = "track-label";
label.style.left = `${(events[index] / DURATION) * 100}%`;
label.textContent = `K${String(index + 1).padStart(2, "0")}`;
label.setAttribute("aria-hidden", "true");
trackWrap.appendChild(label);
const dot = document.createElement("span");
dot.className = "event-dot";
dot.style.left = `${(events[index] / DURATION) * 100}%`;
dot.title = `K${String(index + 1).padStart(2, "0")} begins expansion`;
trackWrap.appendChild(dot);
kernel.eventDot = dot;
}
let elapsed = 0;
let playing = false;
let lastTime = performance.now();
function setPlaying(value) {
playing = value;
if (value && elapsed >= DURATION) {
elapsed = 0;
}
playButton.textContent = playing
? "Pause"
: elapsed >= DURATION
? "Replay expansion"
: "Play expansion";
}
function updateScene(time) {
for (const kernel of kernels) {
const progress = THREE.MathUtils.clamp(
(time - kernel.event) / TRANSITION_DURATION,
0,
1
);
const eased = smoothStep(progress);
// The same group represents the kernel before and after expansion,
// so the object and its identity marker are never replaced.
kernel.rawGroup.visible = progress < 0.995;
kernel.rawGroup.scale.setScalar(
Math.max(0.025, 1 - eased * 0.94)
);
kernel.popcornGroup.visible = progress > 0;
const popcornScale = Math.max(
0.001,
eased * (1 + Math.sin(Math.PI * eased) * 0.045)
);
kernel.popcornGroup.scale.setScalar(popcornScale);
kernel.popcornGroup.rotation.y =
kernel.popcornGroup.userData.baseRotationY + eased * 0.24;
// A restrained upward hop, with no particles or radial burst.
const hop = Math.sin(Math.PI * progress) * 0.24;
kernel.identityGroup.position.y = kernel.baseY + hop;
kernel.marker.position.set(
kernel.identityGroup.position.x,
kernel.identityGroup.position.y + 0.57,
kernel.identityGroup.position.z
);
}
}
function updateUI(time) {
let before = 0;
let after = 0;
let transitioning = 0;
let activeId = "";
for (const kernel of kernels) {
if (time < kernel.event) {
before++;
} else if (time >= kernel.event + TRANSITION_DURATION) {
after++;
} else {
transitioning++;
activeId = `K${String(kernel.index + 1).padStart(2, "0")}`;
}
kernel.eventDot.classList.toggle("passed", time >= kernel.event);
}
beforeCount.textContent = before;
afterCount.textContent = after;
transitionText.textContent = transitioning
? `${transitioning} in transition`
: "0 in transition";
if (transitioning) {
stateText.textContent = `${activeId} expanding gently`;
} else if (after === kernels.length) {
stateText.textContent = "Expansion complete · 5 identities preserved";
} else if (before === kernels.length) {
stateText.textContent = "All 5 kernels unexpanded";
} else {
stateText.textContent = `${after} expanded · ${before} unexpanded`;
}
scrubber.value = time.toFixed(2);
scrubber.style.setProperty(
"--progress",
`${(time / DURATION) * 100}%`
);
clock.textContent = `${time.toFixed(1)}s / ${DURATION.toFixed(1)}s`;
}
playButton.addEventListener("click", () => {
setPlaying(!playing);
});
resetButton.addEventListener("click", () => {
elapsed = 0;
setPlaying(false);
});
scrubber.addEventListener("input", () => {
elapsed = Number(scrubber.value);
setPlaying(false);
});
window.addEventListener("keydown", (event) => {
const tag = document.activeElement?.tagName;
if (event.code === "Space" && tag !== "INPUT" && tag !== "BUTTON") {
event.preventDefault();
setPlaying(!playing);
}
});
function resize() {
const width = Math.max(1, host.clientWidth);
const height = Math.max(1, host.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(host);
resize();
updateCamera();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (playing) {
elapsed = Math.min(DURATION, elapsed + delta);
if (elapsed >= DURATION) {
setPlaying(false);
}
}
updateCamera();
updateScene(elapsed);
updateUI(elapsed);
renderer.render(scene, camera);
}
updateScene(0);
updateUI(0);
requestAnimationFrame(animate);
</script>
</body>
</html>
```