Prompt specification
Build or customize the Three.js 3D scene "Time-lapse stem reorientation" 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: Time-lapse stem reorientation
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/time-lapse-stem-reorientation-x0762
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring plant phototropism. Animate successive stem shapes curving toward a shifted light source while roots remain anchored; label the sequence as an accelerated conceptual response rather than real-time movement. Low-poly.
Working Three.js Starter (time-lapse-stem-reorientation-x0762):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Phototropism — An Accelerated Conceptual Response</title>
<style>
:root {
color-scheme: dark;
--ink: #eef8ef;
--muted: #a6b9ac;
--green: #a6d96b;
--green-strong: #5fb65a;
--gold: #ffe39a;
--panel: rgba(7, 20, 16, 0.83);
--line: rgba(202, 235, 205, 0.17);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #071511;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(
circle at 48% 44%,
transparent 30%,
rgba(2, 8, 6, 0.24) 72%,
rgba(2, 8, 6, 0.72) 100%
);
}
#cycleFade {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
opacity: 0;
background: #071511;
}
.masthead {
position: fixed;
top: 24px;
left: 28px;
z-index: 3;
max-width: 560px;
pointer-events: none;
text-shadow: 0 2px 22px rgba(0, 0, 0, 0.48);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 26px;
height: 2px;
background: var(--green);
box-shadow: 0 0 16px rgba(166, 217, 107, 0.55);
}
h1 {
margin: 0;
font-size: clamp(29px, 4vw, 55px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 720;
}
.masthead p {
max-width: 490px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.concept-badge {
position: fixed;
z-index: 4;
top: 25px;
right: 26px;
display: flex;
align-items: center;
gap: 10px;
max-width: 330px;
padding: 11px 14px;
border: 1px solid rgba(255, 227, 154, 0.3);
border-radius: 999px;
background: rgba(23, 27, 14, 0.68);
color: var(--gold);
font-size: 10px;
font-weight: 800;
line-height: 1.35;
letter-spacing: 0.12em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.concept-badge i {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 14px rgba(255, 227, 154, 0.9);
}
.world-label {
position: fixed;
z-index: 3;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border: 1px solid var(--line);
border-radius: 6px;
background: rgba(5, 14, 11, 0.72);
color: #f5f8ec;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
backdrop-filter: blur(7px);
transition: opacity 160ms ease;
}
.world-label i {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
#sourceLabel {
color: var(--gold);
border-color: rgba(255, 227, 154, 0.28);
}
#rootLabel {
color: #d6b783;
border-color: rgba(214, 183, 131, 0.25);
}
.sequence-panel {
position: fixed;
z-index: 4;
left: 24px;
bottom: 24px;
width: min(485px, calc(100vw - 48px));
padding: 18px 19px 16px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 22px 70px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(14px);
}
.panel-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
}
.panel-kicker {
margin: 0 0 5px;
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.stage-title {
margin: 0;
font-size: 21px;
line-height: 1.1;
letter-spacing: -0.025em;
}
.stage-description {
min-height: 34px;
margin: 7px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.concept-note {
margin: 0 0 2px;
color: #d7c995;
font-size: 9px;
font-weight: 750;
line-height: 1.4;
letter-spacing: 0.08em;
text-align: right;
text-transform: uppercase;
}
.timeline {
position: relative;
display: grid;
grid-template-columns: repeat(6, 1fr);
gap: 6px;
margin-top: 17px;
}
.timeline::before {
content: "";
position: absolute;
top: 6px;
left: 4%;
right: 4%;
height: 1px;
background: rgba(220, 240, 220, 0.17);
}
.phase {
position: relative;
z-index: 1;
min-width: 0;
color: #718176;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
transition: color 220ms ease;
}
.phase span {
display: block;
width: 9px;
height: 9px;
margin-bottom: 7px;
border: 2px solid #526057;
border-radius: 50%;
background: #102019;
transition:
background 220ms ease,
border-color 220ms ease,
box-shadow 220ms ease;
}
.phase.active {
color: var(--green);
}
.phase.active span {
border-color: var(--green);
background: var(--green);
box-shadow: 0 0 13px rgba(166, 217, 107, 0.65);
}
.phase.complete {
color: #a2b2a4;
}
.phase.complete span {
border-color: #6f9f68;
background: #497a4a;
}
.panel-footer {
display: flex;
align-items: center;
gap: 13px;
margin-top: 14px;
}
.progress-track {
position: relative;
height: 3px;
flex: 1;
overflow: hidden;
border-radius: 3px;
background: rgba(220, 240, 220, 0.11);
}
#progressFill {
position: absolute;
inset: 0 auto 0 0;
width: 0;
border-radius: inherit;
background: linear-gradient(90deg, #4f9b54, #b6df76);
box-shadow: 0 0 12px rgba(166, 217, 107, 0.45);
}
#timeReadout {
min-width: 78px;
color: #8fa092;
font-size: 9px;
font-variant-numeric: tabular-nums;
text-align: right;
}
.button-row {
display: flex;
gap: 7px;
margin-left: 2px;
}
.small-button {
padding: 7px 10px;
border: 1px solid rgba(220, 240, 220, 0.17);
border-radius: 7px;
background: rgba(226, 245, 225, 0.06);
color: #dce9dd;
cursor: pointer;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition:
background 160ms ease,
border-color 160ms ease;
}
.small-button:hover {
border-color: rgba(166, 217, 107, 0.48);
background: rgba(166, 217, 107, 0.11);
}
.camera-card {
position: fixed;
z-index: 3;
right: 26px;
bottom: 26px;
width: 214px;
padding: 12px 13px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(7, 20, 16, 0.72);
color: var(--muted);
font-size: 10px;
line-height: 1.5;
backdrop-filter: blur(12px);
}
.camera-card strong {
display: block;
margin-bottom: 4px;
color: #dce9dd;
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.camera-card .small-button {
width: 100%;
margin-top: 9px;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #071511;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.masthead {
top: 18px;
left: 18px;
right: 18px;
}
.masthead p {
max-width: 92%;
font-size: 11px;
}
.concept-badge {
top: auto;
right: 15px;
bottom: 222px;
max-width: 230px;
padding: 8px 10px;
font-size: 8px;
}
.sequence-panel {
left: 14px;
bottom: 14px;
width: calc(100vw - 28px);
padding: 14px;
}
.stage-description {
min-height: 0;
}
.concept-note,
.camera-card {
display: none;
}
.phase {
font-size: 7px;
}
.panel-footer {
gap: 8px;
}
.small-button {
padding: 7px 8px;
font-size: 8px;
}
#timeReadout {
min-width: 67px;
}
#rootLabel {
display: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive low-poly plant demonstrating an accelerated conceptual response to a shifting light source"
></canvas>
<div id="vignette"></div>
<div id="cycleFade"></div>
<header class="masthead">
<div class="eyebrow">Botanical response study</div>
<h1>Phototropism</h1>
<p>
A rooted low-poly shoot advances through successive stem profiles as the
directional light shifts. The growing tip turns toward the new source.
</p>
</header>
<div class="concept-badge">
<i></i>
<span>Accelerated conceptual response — not real-time movement</span>
</div>
<div id="sourceLabel" class="world-label">
<i></i>
<span>LIGHT SOURCE · SHIFTING</span>
</div>
<div id="rootLabel" class="world-label">
<i></i>
<span>FIXED ROOT ANCHOR</span>
</div>
<section class="sequence-panel" aria-label="Phototropism sequence">
<div class="panel-top">
<div>
<p id="stageKicker" class="panel-kicker">01 / Baseline</p>
<h2 id="stageTitle" class="stage-title">Upright growth</h2>
<p id="stageDescription" class="stage-description">
An upright shoot begins from a fixed root crown.
</p>
</div>
<p class="concept-note">
Teaching model<br />
Not real-time growth
</p>
</div>
<div id="phases" class="timeline">
<div class="phase active"><span></span>Baseline</div>
<div class="phase"><span></span>Shift</div>
<div class="phase"><span></span>Curve</div>
<div class="phase"><span></span>Bend</div>
<div class="phase"><span></span>Align</div>
<div class="phase"><span></span>Hold</div>
</div>
<div class="panel-footer">
<div class="progress-track">
<div id="progressFill"></div>
</div>
<div id="timeReadout">0.0 / 22.0 s</div>
<div class="button-row">
<button id="pauseButton" class="small-button" type="button">Pause</button>
<button id="replayButton" class="small-button" type="button">Replay</button>
</div>
</div>
</section>
<aside class="camera-card">
<strong>Explore the model</strong>
Drag to orbit · Wheel to zoom<br />
Double-click the scene to reset the view.
<button id="resetCameraButton" class="small-button" type="button">
Reset camera
</button>
</aside>
<div id="loading">Preparing conceptual response…</div>
<script type="module">
let THREE;
try {
THREE = await import(
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js"
);
} catch (error) {
document.getElementById("loading").textContent =
"Unable to load the Three.js core module.";
throw error;
}
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071511);
scene.fog = new THREE.Fog(0x071511, 11, 25);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0.25, 1.85, 0);
const INITIAL_CAMERA = {
theta: 0.56,
phi: 1.12,
radius: 10.5
};
const desiredCamera = { ...INITIAL_CAMERA };
const currentCamera = { ...INITIAL_CAMERA };
function resetCamera() {
desiredCamera.theta = INITIAL_CAMERA.theta;
desiredCamera.phi = INITIAL_CAMERA.phi;
desiredCamera.radius = INITIAL_CAMERA.radius;
}
function updateCamera() {
currentCamera.theta +=
(desiredCamera.theta - currentCamera.theta) * 0.12;
currentCamera.phi +=
(desiredCamera.phi - currentCamera.phi) * 0.12;
currentCamera.radius +=
(desiredCamera.radius - currentCamera.radius) * 0.12;
const { theta, phi, radius } = currentCamera;
const sinPhi = Math.sin(phi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(cameraTarget);
}
// Direct camera controls: no examples/addons are used.
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
desiredCamera.theta -= dx * 0.006;
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - dy * 0.005,
0.48,
1.38
);
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius + event.deltaY * 0.008,
6.4,
15.5
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
document
.getElementById("resetCameraButton")
.addEventListener("click", resetCamera);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xc7efda,
0x102018,
1.35
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xe6ffe8, 2.4);
keyLight.position.set(-4, 7, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -3;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x82aee8, 0.55);
fillLight.position.set(5, 3, -5);
scene.add(fillLight);
// ------------------------------------------------------------
// Low-poly diorama
// ------------------------------------------------------------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x0b1b16,
roughness: 1,
metalness: 0,
flatShading: true
});
const ground = new THREE.Mesh(
new THREE.CircleGeometry(18, 32),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.69;
ground.receiveShadow = true;
scene.add(ground);
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0x173027,
roughness: 0.94,
flatShading: true
});
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(2.35, 2.62, 0.54, 12, 1),
platformMaterial
);
platform.position.y = -0.4;
platform.castShadow = true;
platform.receiveShadow = true;
scene.add(platform);
const upperPlatform = new THREE.Mesh(
new THREE.CylinderGeometry(2.21, 2.35, 0.12, 12, 1),
new THREE.MeshStandardMaterial({
color: 0x244838,
roughness: 0.95,
flatShading: true
})
);
upperPlatform.position.y = -0.07;
upperPlatform.receiveShadow = true;
scene.add(upperPlatform);
const soil = new THREE.Mesh(
new THREE.CylinderGeometry(1.72, 1.88, 0.38, 12, 1),
new THREE.MeshStandardMaterial({
color: 0x493522,
roughness: 1,
flatShading: true
})
);
soil.position.y = 0.16;
soil.receiveShadow = true;
soil.castShadow = true;
scene.add(soil);
const moundMaterial = new THREE.MeshStandardMaterial({
color: 0x55402b,
roughness: 1,
flatShading: true
});
[
[-0.78, 0.36, -0.38, 0.48],
[0.62, 0.34, -0.54, 0.35],
[-0.88, 0.33, 0.52, 0.31]
].forEach(([x, y, z, scale]) => {
const mound = new THREE.Mesh(
new THREE.IcosahedronGeometry(scale, 1),
moundMaterial
);
mound.position.set(x, y, z);
mound.scale.y = 0.45;
mound.castShadow = true;
mound.receiveShadow = true;
scene.add(mound);
});
const stoneMaterials = [
new THREE.MeshStandardMaterial({
color: 0x68736a,
roughness: 1,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x8c8c72,
roughness: 1,
flatShading: true
})
];
[
[-1.18, 0.4, 0.35, 0.2, 0],
[1.12, 0.4, 0.62, 0.18, 1],
[-0.55, 0.39, -1.0, 0.16, 0],
[1.26, 0.38, -0.36, 0.15, 1]
].forEach(([x, y, z, size, materialIndex]) => {
const stone = new THREE.Mesh(
new THREE.IcosahedronGeometry(size, 0),
stoneMaterials[materialIndex]
);
stone.position.set(x, y, z);
stone.scale.set(1.2, 0.7, 0.9);
stone.rotation.set(0.3, x, 0.15);
stone.castShadow = true;
stone.receiveShadow = true;
scene.add(stone);
});
// ------------------------------------------------------------
// Static roots: these objects are never animated or morphed.
// ------------------------------------------------------------
const rootMaterial = new THREE.MeshStandardMaterial({
color: 0xd0b47e,
roughness: 0.96,
flatShading: true
});
const UP = new THREE.Vector3(0, 1, 0);
function cylinderBetween(
start,
end,
radiusBottom,
radiusTop,
material,
radialSegments = 6
) {
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
length,
radialSegments,
1,
false
),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
UP,
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function addRootPath(points, thickness = 0.065) {
for (let i = 0; i < points.length - 1; i++) {
const fraction = i / (points.length - 1);
const nextFraction = (i + 1) / (points.length - 1);
cylinderBetween(
new THREE.Vector3(...points[i]),
new THREE.Vector3(...points[i + 1]),
thickness * (1 - fraction * 0.72),
thickness * (1 - nextFraction * 0.72),
rootMaterial,
6
);
}
}
addRootPath([
[0, 0.46, 0],
[-0.43, 0.51, 0.23],
[-0.88, 0.48, 0.43],
[-1.34, 0.34, 0.54]
]);
addRootPath([
[0, 0.46, 0],
[0.46, 0.52, 0.27],
[0.96, 0.46, 0.39],
[1.43, 0.27, 0.47]
]);
addRootPath([
[0, 0.46, 0],
[-0.07, 0.52, -0.43],
[-0.22, 0.41, -0.88],
[-0.14, 0.18, -1.28]
]);
addRootPath([
[0, 0.46, 0],
[0.18, 0.53, 0.43],
[0.47, 0.4, 0.83],
[0.71, 0.19, 1.08]
]);
addRootPath([
[-0.43, 0.51, 0.23],
[-0.72, 0.56, -0.11],
[-1.12, 0.48, -0.28]
], 0.045);
addRootPath([
[0.46, 0.52, 0.27],
[0.74, 0.55, -0.04],
[1.12, 0.45, -0.12]
], 0.045);
addRootPath([
[-0.07, 0.52, -0.43],
[0.34, 0.5, -0.67]
], 0.042);
const rootCrown = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.12, 1),
rootMaterial
);
rootCrown.position.set(0, 0.46, 0);
rootCrown.scale.set(1, 0.7, 1);
rootCrown.castShadow = true;
scene.add(rootCrown);
const anchorMaterial = new THREE.MeshBasicMaterial({
color: 0xd8ba7b,
transparent: true,
opacity: 0.4
});
const anchorRing = new THREE.Mesh(
new THREE.TorusGeometry(0.66, 0.018, 4, 24),
anchorMaterial
);
anchorRing.rotation.x = Math.PI / 2;
anchorRing.position.y = 0.47;
scene.add(anchorRing);
// ------------------------------------------------------------
// Stem shape keys
// ------------------------------------------------------------
const BASE_Y = 0.45;
const SEGMENTS = 28;
const RADIAL_SEGMENTS = 7;
function makeStemShape(amplitude, height) {
const points = [];
for (let i = 0; i <= SEGMENTS; i++) {
const u = i / SEGMENTS;
const x = amplitude * Math.pow(u, 1.32);
const y =
BASE_Y +
(height - BASE_Y) * u -
0.07 * amplitude * Math.pow(u, 3);
const z = -0.2 * amplitude * Math.pow(u, 1.55);
points.push(new THREE.Vector3(x, y, z));
}
return points;
}
const shapeAmplitudes = [0, 0, 0.42, 1.1, 1.9, 2.75];
const shapeHeights = [4.15, 4.15, 4.1, 4.02, 3.9, 3.72];
const STEM_SHAPES = shapeAmplitudes.map((amplitude, index) =>
makeStemShape(amplitude, shapeHeights[index])
);
const SHAPE_TIMES = [0, 0.14, 0.34, 0.54, 0.72, 0.84];
function smooth01(value) {
const x = THREE.MathUtils.clamp(value, 0, 1);
return x * x * (3 - 2 * x);
}
function smoothRange(start, end, value) {
return smooth01((value - start) / (end - start));
}
const currentCenters = Array.from(
{ length: SEGMENTS + 1 },
() => new THREE.Vector3()
);
function updateStemCenters(time) {
let shapeIndex = STEM_SHAPES.length - 2;
let blend = 1;
for (let i = 0; i < SHAPE_TIMES.length - 1; i++) {
if (time <= SHAPE_TIMES[i + 1]) {
shapeIndex = i;
blend = smoothRange(
SHAPE_TIMES[i],
SHAPE_TIMES[i + 1],
time
);
break;
}
}
const from = STEM_SHAPES[shapeIndex];
const to = STEM_SHAPES[shapeIndex + 1];
for (let i = 0; i <= SEGMENTS; i++) {
currentCenters[i].lerpVectors(from[i], to[i], blend);
}
}
const stemVertexCount = (SEGMENTS + 1) * (RADIAL_SEGMENTS + 1);
const stemPositions = new Float32Array(stemVertexCount * 3);
const stemColors = new Float32Array(stemVertexCount * 3);
const stemIndices = [];
const darkGreen = new THREE.Color(0x185a37);
const brightGreen = new THREE.Color(0x91cd58);
for (let i = 0; i <= SEGMENTS; i++) {
const u = i / SEGMENTS;
for (let j = 0; j <= RADIAL_SEGMENTS; j++) {
const vertexIndex = i * (RADIAL_SEGMENTS + 1) + j;
const color = darkGreen.clone().lerp(brightGreen, Math.pow(u, 0.72));
const variation =
0.9 + 0.1 * Math.sin(i * 1.73 + j * 2.31);
color.multiplyScalar(variation);
stemColors[vertexIndex * 3] = color.r;
stemColors[vertexIndex * 3 + 1] = color.g;
stemColors[vertexIndex * 3 + 2] = color.b;
if (i < SEGMENTS && j < RADIAL_SEGMENTS) {
const a = vertexIndex;
const b = a + RADIAL_SEGMENTS + 1;
stemIndices.push(a, a + 1, b);
stemIndices.push(a + 1, b + 1, b);
}
}
}
const stemGeometry = new THREE.BufferGeometry();
stemGeometry.setAttribute(
"position",
new THREE.BufferAttribute(stemPositions, 3).setUsage(
THREE.DynamicDrawUsage
)
);
stemGeometry.setAttribute(
"color",
new THREE.BufferAttribute(stemColors, 3)
);
stemGeometry.setIndex(stemIndices);
const stem = new THREE.Mesh(
stemGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.73,
metalness: 0,
flatShading: true
})
);
stem.castShadow = true;
stem.receiveShadow = true;
scene.add(stem);
const stemTangents = Array.from(
{ length: SEGMENTS + 1 },
() => new THREE.Vector3()
);
function updateStemGeometry() {
const previousNormal = new THREE.Vector3(1, 0, 0);
const tangent = new THREE.Vector3();
const normal = new THREE.Vector3();
const binormal = new THREE.Vector3();
const vertex = new THREE.Vector3();
for (let i = 0; i <= SEGMENTS; i++) {
const before = currentCenters[Math.max(0, i - 1)];
const after = currentCenters[Math.min(SEGMENTS, i + 1)];
tangent.copy(after).sub(before).normalize();
stemTangents[i].copy(tangent);
normal.copy(previousNormal);
normal.addScaledVector(
tangent,
-normal.dot(tangent)
);
if (normal.lengthSq() < 0.00001) {
normal.set(0, 0, 1);
normal.addScaledVector(
tangent,
-normal.dot(tangent)
);
}
normal.normalize();
previousNormal.copy(normal);
binormal.crossVectors(tangent, normal).normalize();
const u = i / SEGMENTS;
const radius =
0.025 + 0.135 * Math.pow(1 - u, 0.72);
for (let j = 0; j <= RADIAL_SEGMENTS; j++) {
const angle = (j / RADIAL_SEGMENTS) * Math.PI * 2;
const polygonVariation =
1 + 0.035 * Math.sin(i * 0.83 + j * 2.17);
vertex
.copy(currentCenters[i])
.addScaledVector(
normal,
Math.cos(angle) * radius * polygonVariation
)
.addScaledVector(
binormal,
Math.sin(angle) * radius * polygonVariation
);
const vertexIndex = i * (RADIAL_SEGMENTS + 1) + j;
stemPositions[vertexIndex * 3] = vertex.x;
stemPositions[vertexIndex * 3 + 1] = vertex.y;
stemPositions[vertexIndex * 3 + 2] = vertex.z;
}
}
stemGeometry.attributes.position.needsUpdate = true;
stemGeometry.computeVertexNormals();
stemGeometry.computeBoundingSphere();
}
// ------------------------------------------------------------
// Low-poly leaves that follow the morphing stem
// ------------------------------------------------------------
function makeLeafGeometry() {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
0.00, 0.000, 0.00,
1.05, 0.020, 0.00,
0.44, -0.015, -0.32,
0.44, -0.015, 0.32,
0.48, 0.130, 0.00
],
3
)
);
geometry.setIndex([
0, 2, 4,
2, 1, 4,
1, 3, 4,
3, 0, 4
]);
geometry.computeVertexNormals();
return geometry;
}
const leafGeometry = makeLeafGeometry();
const leafMaterials = [
new THREE.MeshStandardMaterial({
color: 0x4f9b4a,
roughness: 0.82,
flatShading: true,
side: THREE.DoubleSide
}),
new THREE.MeshStandardMaterial({
color: 0x76b64e,
roughness: 0.84,
flatShading: true,
side: THREE.DoubleSide
})
];
const leafSpecs = [
{ u: 0.23, side: -1, depth: -0.25, scale: 0.86, phase: 0.1 },
{ u: 0.35, side: 1, depth: 0.18, scale: 0.97, phase: 1.2 },
{ u: 0.47, side: -1, depth: -0.12, scale: 1.06, phase: 2.1 },
{ u: 0.59, side: 1, depth: -0.26, scale: 0.91, phase: 2.8 },
{ u: 0.71, side: -1, depth: 0.12, scale: 0.76, phase: 3.7 },
{ u: 0.82, side: 1, depth: 0.22, scale: 0.64, phase: 4.5 }
];
const leaves = leafSpecs.map((spec, index) => {
const leaf = new THREE.Mesh(
leafGeometry,
leafMaterials[index % leafMaterials.length]
);
leaf.castShadow = true;
leaf.receiveShadow = true;
scene.add(leaf);
return leaf;
});
const worldUp = new THREE.Vector3(0, 1, 0);
const worldForward = new THREE.Vector3(0, 0, 1);
const sideVector = new THREE.Vector3();
const forwardVector = new THREE.Vector3();
const leafDirection = new THREE.Vector3();
const xAxis = new THREE.Vector3();
const yAxis = new THREE.Vector3();
const zAxis = new THREE.Vector3();
const basis = new THREE.Matrix4();
function centerAndTangentAt(u) {
const scaled = u * SEGMENTS;
const index = Math.min(
SEGMENTS - 1,
Math.max(0, Math.floor(scaled))
);
const fraction = scaled - index;
const center = new THREE.Vector3().lerpVectors(
currentCenters[index],
currentCenters[index + 1],
fraction
);
const tangent = new THREE.Vector3().lerpVectors(
stemTangents[index],
stemTangents[index + 1],
fraction
).normalize();
return { center, tangent };
}
function updateLeaves(elapsedMilliseconds) {
leafSpecs.forEach((spec, index) => {
const { center, tangent } = centerAndTangentAt(spec.u);
const leaf = leaves[index];
leaf.position.copy(center);
sideVector.crossVectors(tangent, worldForward).normalize();
if (sideVector.lengthSq() < 0.001) {
sideVector.set(1, 0, 0);
}
forwardVector
.crossVectors(tangent, sideVector)
.normalize();
leafDirection
.copy(sideVector)
.multiplyScalar(spec.side)
.addScaledVector(forwardVector, spec.depth)
.addScaledVector(tangent, 0.16)
.normalize();
xAxis.copy(leafDirection);
yAxis
.copy(worldUp)
.addScaledVector(
xAxis,
-xAxis.dot(worldUp)
);
if (yAxis.lengthSq() < 0.001) {
yAxis.set(0, 0, 1);
}
yAxis.normalize();
zAxis.crossVectors(xAxis, yAxis).normalize();
basis.makeBasis(xAxis, yAxis, zAxis);
leaf.quaternion.setFromRotationMatrix(basis);
const sway = Math.sin(
elapsedMilliseconds * 0.0011 + spec.phase
) * 0.045;
leaf.rotateX(sway);
leaf.scale.setScalar(spec.scale);
});
}
// ------------------------------------------------------------
// Moving light source, beam, and directional guide
// ------------------------------------------------------------
const finalTip = STEM_SHAPES[STEM_SHAPES.length - 1][SEGMENTS];
const finalTangent = finalTip
.clone()
.sub(STEM_SHAPES[STEM_SHAPES.length - 1][SEGMENTS - 1])
.normalize();
const FINAL_SOURCE = finalTip
.clone()
.addScaledVector(finalTangent, 1.42);
const INITIAL_SOURCE = new THREE.Vector3(-2.55, 4.85, -0.55);
const sourcePosition = INITIAL_SOURCE.clone();
const sourceGroup = new THREE.Group();
scene.add(sourceGroup);
const sourceOrb = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.34, 1),
new THREE.MeshStandardMaterial({
color: 0xffe7a1,
emissive: 0xffbd45,
emissiveIntensity: 2.6,
roughness: 0.45,
flatShading: true
})
);
sourceOrb.castShadow = true;
sourceGroup.add(sourceOrb);
const haloMaterial = new THREE.MeshBasicMaterial({
color: 0xffdf8b,
transparent: true,
opacity: 0.62,
depthWrite: false
});
const haloA = new THREE.Mesh(
new THREE.TorusGeometry(0.53, 0.022, 4, 24),
haloMaterial
);
sourceGroup.add(haloA);
const haloB = new THREE.Mesh(
new THREE.TorusGeometry(0.7, 0.012, 4, 24),
new THREE.MeshBasicMaterial({
color: 0xffd877,
transparent: true,
opacity: 0.35,
depthWrite: false
})
);
haloB.rotation.x = 0.8;
haloB.rotation.y = 0.45;
sourceGroup.add(haloB);
const pointLight = new THREE.PointLight(0xffdc8b, 38, 8, 2);
sourceGroup.add(pointLight);
const glowCanvas = document.createElement("canvas");
glowCanvas.width = 128;
glowCanvas.height = 128;
const glowContext = glowCanvas.getContext("2d");
const glowGradient = glowContext.createRadialGradient(
64,
64,
0,
64,
64,
64
);
glowGradient.addColorStop(0, "rgba(255,238,176,0.8)");
glowGradient.addColorStop(0.28, "rgba(255,207,102,0.28)");
glowGradient.addColorStop(1, "rgba(255,191,65,0)");
glowContext.fillStyle = glowGradient;
glowContext.fillRect(0, 0, 128, 128);
const glowTexture = new THREE.CanvasTexture(glowCanvas);
const glow = new THREE.Sprite(
new THREE.SpriteMaterial({
map: glowTexture,
transparent: true,
opacity: 0.65,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
glow.scale.set(1.9, 1.9, 1.9);
sourceGroup.add(glow);
const beam = new THREE.Mesh(
new THREE.ConeGeometry(1, 1, 6, 1, true),
new THREE.MeshBasicMaterial({
color: 0xffdc84,
transparent: true,
opacity: 0.048,
side: THREE.DoubleSide,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
beam.renderOrder = 1;
scene.add(beam);
const guideGeometry = new THREE.BufferGeometry();
guideGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(6), 3)
);
const guideLine = new THREE.Line(
guideGeometry,
new THREE.LineDashedMaterial({
color: 0xffe2a0,
transparent: true,
opacity: 0.35,
dashSize: 0.12,
gapSize: 0.09,
depthTest: false
})
);
guideLine.renderOrder = 4;
scene.add(guideLine);
const plantBase = new THREE.Vector3(0, BASE_Y, 0);
const beamDirection = new THREE.Vector3();
const beamMidpoint = new THREE.Vector3();
function updateLight(time) {
const shift = smoothRange(0.03, 0.29, time);
sourcePosition.lerpVectors(
INITIAL_SOURCE,
FINAL_SOURCE,
shift
);
sourceGroup.position.copy(sourcePosition);
sourceGroup.quaternion.copy(camera.quaternion);
const distance = sourcePosition.distanceTo(plantBase);
beamDirection
.copy(sourcePosition)
.sub(plantBase)
.normalize();
beamMidpoint
.copy(sourcePosition)
.add(plantBase)
.multiplyScalar(0.5);
beam.position.copy(beamMidpoint);
beam.quaternion.setFromUnitVectors(UP, beamDirection);
beam.scale.set(0.95, distance, 0.95);
const guidePositions =
guideGeometry.attributes.position;
guidePositions.setXYZ(
0,
sourcePosition.x,
sourcePosition.y,
sourcePosition.z
);
guidePositions.setXYZ(
1,
currentCenters[SEGMENTS].x,
currentCenters[SEGMENTS].y,
currentCenters[SEGMENTS].z
);
guidePositions.needsUpdate = true;
guideLine.computeLineDistances();
guideLine.material.opacity = 0.18 + shift * 0.24;
}
// ------------------------------------------------------------
// Tip bud
// ------------------------------------------------------------
const budGroup = new THREE.Group();
const bud = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.17, 1),
new THREE.MeshStandardMaterial({
color: 0x7fbd4b,
roughness: 0.78,
flatShading: true
})
);
bud.scale.set(0.75, 1.25, 0.75);
bud.castShadow = true;
budGroup.add(bud);
const sepal = new THREE.Mesh(
new THREE.ConeGeometry(0.09, 0.22, 4),
new THREE.MeshStandardMaterial({
color: 0x3f8643,
roughness: 0.85,
flatShading: true
})
);
sepal.position.y = -0.13;
sepal.rotation.z = 0.18;
sepal.castShadow = true;
budGroup.add(sepal);
scene.add(budGroup);
const budDirection = new THREE.Vector3();
function updateBud() {
budGroup.position.copy(currentCenters[SEGMENTS]);
budDirection
.copy(sourcePosition)
.sub(currentCenters[SEGMENTS]);
if (budDirection.lengthSq() > 0.001) {
budDirection.normalize();
budGroup.quaternion.setFromUnitVectors(
UP,
budDirection
);
}
}
// ------------------------------------------------------------
// UI and projected labels
// ------------------------------------------------------------
const stageKicker = document.getElementById("stageKicker");
const stageTitle = document.getElementById("stageTitle");
const stageDescription =
document.getElementById("stageDescription");
const progressFill = document.getElementById("progressFill");
const timeReadout = document.getElementById("timeReadout");
const phaseElements = [
...document.querySelectorAll(".phase")
];
const sourceLabel = document.getElementById("sourceLabel");
const sourceLabelText = sourceLabel.querySelector("span");
const rootLabel = document.getElementById("rootLabel");
const STAGES = [
{
kicker: "01 / Baseline",
title: "Upright growth",
description:
"An upright shoot begins from a fixed root crown."
},
{
kicker: "02 / Source shift",
title: "The light moves right",
description:
"The directional cue changes while the root system remains fixed."
},
{
kicker: "03 / First curve",
title: "A new stem profile",
description:
"The shoot begins bowing toward the displaced light field."
},
{
kicker: "04 / Deeper bend",
title: "Successive profiles form",
description:
"Each conceptual stem shape strengthens the lateral curvature."
},
{
kicker: "05 / Alignment",
title: "The tip faces the source",
description:
"The upper shoot turns toward the shifted light and the bud aligns."
},
{
kicker: "06 / Held response",
title: "Aligned conceptual form",
description:
"The final accelerated teaching model is held for inspection."
}
];
const DURATION = 22000;
const pauseButton = document.getElementById("pauseButton");
const replayButton = document.getElementById("replayButton");
const cycleFade = document.getElementById("cycleFade");
let elapsed = 0;
let paused = false;
let lastStage = -1;
let hasLooped = false;
function stageForTime(time) {
if (time < 0.14) return 0;
if (time < 0.34) return 1;
if (time < 0.54) return 2;
if (time < 0.72) return 3;
if (time < 0.9) return 4;
return 5;
}
function updateUI(time) {
const stageIndex = stageForTime(time);
if (stageIndex !== lastStage) {
lastStage = stageIndex;
const stage = STAGES[stageIndex];
stageKicker.textContent = stage.kicker;
stageTitle.textContent = stage.title;
stageDescription.textContent = stage.description;
phaseElements.forEach((element, index) => {
element.classList.toggle(
"active",
index === stageIndex
);
element.classList.toggle(
"complete",
index < stageIndex
);
});
}
progressFill.style.width = `${time * 100}%`;
timeReadout.textContent =
`${((time * DURATION) / 1000).toFixed(1)} / 22.0 s`;
sourceLabelText.textContent =
time < 0.3
? "LIGHT SOURCE · SHIFTING"
: "SHIFTED LIGHT SOURCE";
}
function projectLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
element.style.opacity = visible ? "1" : "0";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateLabels() {
const sourceLabelPosition = sourcePosition
.clone()
.add(new THREE.Vector3(0, 0.68, 0));
projectLabel(sourceLabel, sourceLabelPosition);
projectLabel(
rootLabel,
new THREE.Vector3(-1.48, 0.34, 0.78)
);
}
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
replayButton.addEventListener("click", () => {
elapsed = 0;
lastStage = -1;
});
window.addEventListener("keydown", (event) => {
if (
event.target instanceof HTMLButtonElement ||
event.target instanceof HTMLInputElement
) {
return;
}
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
replayButton.click();
}
if (event.key.toLowerCase() === "c") {
resetCamera();
}
});
// ------------------------------------------------------------
// Resize and animation loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(
Math.min(window.devicePixelRatio, 2)
);
renderer.setSize(
window.innerWidth,
window.innerHeight,
false
);
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
elapsed += delta * 1000;
if (elapsed >= DURATION) {
elapsed %= DURATION;
hasLooped = true;
lastStage = -1;
}
}
const time = elapsed / DURATION;
updateCamera();
updateStemCenters(time);
updateStemGeometry();
updateLeaves(elapsed);
updateLight(time);
updateBud();
updateUI(time);
updateLabels();
const endFade = smoothRange(0.955, 1, time);
const startFade = hasLooped
? 1 - smoothRange(0, 0.035, time)
: 0;
cycleFade.style.opacity = Math.max(
endFade,
startFade
);
renderer.render(scene, camera);
}
document
.getElementById("loading")
.classList.add("hidden");
animate();
</script>
</body>
</html>
```