Prompt specification
Build or customize the Three.js 3D scene "Tea color diffusion cup" 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: Tea color diffusion cup
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/tea-color-diffusion-cup-x0158
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this low-poly scene: Lower the infuser into clear water and spread a colored concentration field outward over time; keep leaves inside while the surrounding liquid changes progressively.
Working Three.js Starter (tea-color-diffusion-cup-x0158):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Slow Infusion — Botanical Study</title>
<style>
:root {
--ink: #242722;
--muted: #6e7169;
--paper: rgba(247, 246, 239, 0.78);
--line: rgba(45, 48, 40, 0.14);
--accent: #b76532;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e6dd;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app,
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.brand {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
pointer-events: none;
}
.kicker {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.kicker::before {
width: 22px;
height: 1px;
background: var(--accent);
content: "";
}
h1 {
margin: 0;
max-width: 430px;
font-size: clamp(30px, 4vw, 58px);
font-weight: 520;
letter-spacing: -0.055em;
line-height: 0.98;
}
.brand p {
margin: 13px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.02em;
}
.panel {
border: 1px solid var(--line);
border-radius: 16px;
background: var(--paper);
box-shadow:
0 18px 50px rgba(60, 56, 44, 0.08),
inset 0 1px 0 rgba(255, 255, 255, 0.58);
backdrop-filter: blur(18px) saturate(1.08);
-webkit-backdrop-filter: blur(18px) saturate(1.08);
}
.status-panel {
position: fixed;
top: 28px;
right: 30px;
z-index: 5;
width: 286px;
padding: 17px 18px 16px;
}
.status-top {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.15em;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent);
}
#time {
font-variant-numeric: tabular-nums;
letter-spacing: 0.06em;
}
.metric {
display: flex;
align-items: end;
justify-content: space-between;
margin-top: 21px;
}
.metric span {
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.15em;
}
.metric strong {
font-size: 30px;
font-weight: 520;
letter-spacing: -0.06em;
line-height: 0.8;
}
.progress-track {
position: relative;
height: 3px;
margin: 17px 0 20px;
overflow: visible;
border-radius: 10px;
background: rgba(42, 45, 38, 0.11);
}
.progress-track::before,
.progress-track::after {
position: absolute;
top: -3px;
width: 1px;
height: 9px;
background: rgba(42, 45, 38, 0.22);
content: "";
}
.progress-track::before {
left: 33.33%;
}
.progress-track::after {
left: 66.66%;
}
#progress-fill {
position: absolute;
inset: 0 auto 0 0;
width: 0;
border-radius: inherit;
background: var(--accent);
transition: background-color 240ms ease;
}
.phase-label {
margin-bottom: 6px;
font-size: 15px;
font-weight: 650;
letter-spacing: -0.025em;
}
.phase-description {
min-height: 32px;
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.controls-panel {
position: fixed;
right: 30px;
bottom: 28px;
z-index: 5;
width: 286px;
padding: 16px 18px;
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
}
.control-row + .control-row {
margin-top: 15px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.control-label {
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.swatches {
display: flex;
gap: 7px;
}
.swatch {
width: 22px;
height: 22px;
padding: 0;
border: 2px solid rgba(255, 255, 255, 0.7);
border-radius: 50%;
outline: 1px solid transparent;
background: var(--swatch);
cursor: pointer;
transition:
transform 160ms ease,
outline-color 160ms ease;
}
.swatch:hover {
transform: scale(1.1);
}
.swatch.active {
outline-color: var(--ink);
outline-offset: 2px;
}
.range-wrap {
display: flex;
align-items: center;
gap: 10px;
}
#strength {
width: 95px;
height: 3px;
accent-color: var(--accent);
cursor: pointer;
}
#strength-value {
width: 33px;
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
text-align: right;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.buttons button {
padding: 10px 9px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.36);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
cursor: pointer;
transition:
background-color 160ms ease,
transform 160ms ease;
}
.buttons button:hover {
background: rgba(255, 255, 255, 0.72);
transform: translateY(-1px);
}
.buttons button:active {
transform: translateY(0);
}
.footer-note {
position: fixed;
bottom: 31px;
left: 30px;
z-index: 5;
display: flex;
align-items: center;
gap: 13px;
color: var(--muted);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.11em;
text-transform: uppercase;
pointer-events: none;
}
.footer-note span {
display: inline-block;
width: 4px;
height: 4px;
border-radius: 50%;
background: var(--accent);
}
.callout {
position: fixed;
top: 0;
left: 0;
z-index: 4;
width: 158px;
padding-left: 22px;
pointer-events: none;
will-change: transform;
}
.callout::before {
position: absolute;
top: 15px;
left: 0;
width: 13px;
height: 1px;
background: var(--accent);
content: "";
}
.callout::after {
position: absolute;
top: 12px;
left: 0;
width: 6px;
height: 6px;
border: 1px solid var(--accent);
border-radius: 50%;
background: #e9e6dd;
content: "";
}
.callout b {
display: block;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.callout small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
}
@media (max-width: 760px) {
.brand {
top: 20px;
left: 20px;
}
h1 {
max-width: 270px;
font-size: 36px;
}
.brand p,
.callout,
.footer-note {
display: none;
}
.status-panel {
top: 20px;
right: 16px;
width: 188px;
padding: 13px 14px;
}
.metric {
margin-top: 15px;
}
.metric strong {
font-size: 24px;
}
.progress-track {
margin: 13px 0 15px;
}
.phase-description {
display: none;
}
.controls-panel {
right: 16px;
bottom: 16px;
left: 16px;
width: auto;
padding: 13px 14px;
}
.control-row + .control-row {
margin-top: 11px;
padding-top: 11px;
}
.buttons button {
padding: 9px;
}
}
</style>
</head>
<body>
<main id="app">
<div id="scene" aria-label="Interactive 3D botanical infusion scene"></div>
<header class="brand">
<div class="kicker">Botanical study / 04</div>
<h1>Color, released<br>slowly.</h1>
<p>A contained infusion in a faceted glass vessel.</p>
</header>
<aside class="panel status-panel">
<div class="status-top">
<span class="status-dot"></span>
<span>LIVE PROCESS</span>
<span id="time">00:00</span>
</div>
<div class="metric">
<span>CONCENTRATION</span>
<strong id="percent">0%</strong>
</div>
<div class="progress-track">
<div id="progress-fill"></div>
</div>
<div id="phase-label" class="phase-label">Lowering the infuser</div>
<p id="phase-description" class="phase-description">
The botanical basket descends toward a clear-water bath.
</p>
</aside>
<div id="callout" class="callout">
<b>Botanical infuser</b>
<small>Leaves remain contained</small>
</div>
<aside class="panel controls-panel">
<div class="control-row">
<span class="control-label">Infusion color</span>
<div class="swatches" aria-label="Choose infusion color">
<button
class="swatch active"
style="--swatch:#b76532"
data-palette="amber"
aria-label="Amber"
></button>
<button
class="swatch"
style="--swatch:#a94d76"
data-palette="rose"
aria-label="Rose"
></button>
<button
class="swatch"
style="--swatch:#2e6f95"
data-palette="blue"
aria-label="Blue"
></button>
</div>
</div>
<div class="control-row">
<label class="control-label" for="strength">Strength</label>
<div class="range-wrap">
<input
id="strength"
type="range"
min="0.65"
max="1.45"
step="0.05"
value="1"
>
<span id="strength-value">1.0×</span>
</div>
</div>
<div class="control-row">
<div class="buttons">
<button id="pause" type="button">Ⅱ Pause</button>
<button id="replay" type="button">↺ Replay</button>
</div>
</div>
</aside>
<div class="footer-note">
<span></span>
Drag to orbit · Scroll to zoom · R to replay
</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Scene and renderer
// ---------------------------------------------------------------------
const sceneHost = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e6dd);
scene.fog = new THREE.Fog(0xe9e6dd, 10, 18);
const camera = new THREE.PerspectiveCamera(
35,
window.innerWidth / window.innerHeight,
0.1,
40
);
const cameraTarget = new THREE.Vector3(0, 1.55, 0);
const orbit = {
azimuth: 0.62,
polar: 1.12,
radius: 7.7,
targetAzimuth: 0.62,
targetPolar: 1.12,
targetRadius: 7.7
};
function updateCamera() {
const s = Math.sin(orbit.polar);
const c = Math.cos(orbit.polar);
camera.position.set(
cameraTarget.x + orbit.radius * s * Math.sin(orbit.azimuth),
cameraTarget.y + orbit.radius * c,
cameraTarget.z + orbit.radius * s * Math.cos(orbit.azimuth)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// ---------------------------------------------------------------------
// Lighting and low-poly set
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xfff9e9, 0x8a9185, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffefd6, 3.4);
keyLight.position.set(4.5, 7.5, 5.2);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 18;
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9d8df, 1.1);
fillLight.position.set(-4, 3, -3);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0xe4e0d6,
roughness: 1,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const plinth = new THREE.Mesh(
new THREE.CylinderGeometry(2.22, 2.3, 0.17, 32),
new THREE.MeshStandardMaterial({
color: 0xd6d1c5,
roughness: 0.92,
metalness: 0,
flatShading: true
})
);
plinth.position.y = 0.085;
plinth.receiveShadow = true;
plinth.castShadow = true;
scene.add(plinth);
// ---------------------------------------------------------------------
// Glass vessel
// ---------------------------------------------------------------------
const vessel = new THREE.Group();
scene.add(vessel);
const glassMaterial = new THREE.MeshPhongMaterial({
color: 0xd9eeee,
transparent: true,
opacity: 0.13,
side: THREE.DoubleSide,
depthWrite: false,
shininess: 100,
specular: 0xffffff
});
const glassGeometry = new THREE.CylinderGeometry(
1.62,
1.48,
3.15,
12,
1,
true
);
const glassWall = new THREE.Mesh(glassGeometry, glassMaterial);
glassWall.position.y = 1.765;
glassWall.renderOrder = 5;
vessel.add(glassWall);
const glassEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(glassGeometry, 15),
new THREE.LineBasicMaterial({
color: 0xf8ffff,
transparent: true,
opacity: 0.34,
depthWrite: false
})
);
glassEdges.position.copy(glassWall.position);
glassEdges.renderOrder = 6;
vessel.add(glassEdges);
const rimMaterial = new THREE.MeshStandardMaterial({
color: 0xe6f4f1,
roughness: 0.2,
metalness: 0.08,
transparent: true,
opacity: 0.68
});
const topRim = new THREE.Mesh(
new THREE.TorusGeometry(1.62, 0.026, 6, 36),
rimMaterial
);
topRim.rotation.x = Math.PI / 2;
topRim.position.y = 3.34;
vessel.add(topRim);
const bottomRim = new THREE.Mesh(
new THREE.TorusGeometry(1.48, 0.035, 6, 36),
rimMaterial
);
bottomRim.rotation.x = Math.PI / 2;
bottomRim.position.y = 0.19;
vessel.add(bottomRim);
const glassBase = new THREE.Mesh(
new THREE.CylinderGeometry(1.48, 1.48, 0.08, 12),
new THREE.MeshPhongMaterial({
color: 0xd8eeee,
transparent: true,
opacity: 0.17,
depthWrite: false
})
);
glassBase.position.y = 0.21;
vessel.add(glassBase);
// Subtle measurement marks on the front-right wall.
const tickPositions = [];
for (let i = 0; i < 6; i++) {
const y = 0.55 + i * 0.39;
const t = (y - 0.19) / 3.15;
const radius = THREE.MathUtils.lerp(1.48, 1.62, t);
const a = 0.36;
const b = 0.36 + (i % 2 === 0 ? 0.1 : 0.06);
tickPositions.push(
Math.cos(a) * radius,
y,
Math.sin(a) * radius,
Math.cos(b) * radius,
y,
Math.sin(b) * radius
);
}
const tickGeometry = new THREE.BufferGeometry();
tickGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(tickPositions, 3)
);
const ticks = new THREE.LineSegments(
tickGeometry,
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.42
})
);
vessel.add(ticks);
// ---------------------------------------------------------------------
// Water volume shader
// ---------------------------------------------------------------------
const palettes = {
amber: {
color: "#b76532",
light: "#f2b46f"
},
rose: {
color: "#a94d76",
light: "#eaa0bd"
},
blue: {
color: "#2e6f95",
light: "#78b7d4"
}
};
const waterUniforms = {
uFill: { value: 0 },
uStrength: { value: 1 },
uTime: { value: 0 },
uColor: { value: new THREE.Color(palettes.amber.color) },
uLight: { value: new THREE.Color(palettes.amber.light) },
uSource: { value: new THREE.Vector3(0, 1.82, 0) }
};
const waterMaterial = new THREE.ShaderMaterial({
uniforms: waterUniforms,
transparent: true,
depthWrite: false,
side: THREE.FrontSide,
vertexShader: `
varying vec3 vWorld;
void main() {
vec4 worldPosition = modelMatrix * vec4(position, 1.0);
vWorld = worldPosition.xyz;
gl_Position = projectionMatrix * viewMatrix * worldPosition;
}
`,
fragmentShader: `
precision highp float;
uniform float uFill;
uniform float uStrength;
uniform float uTime;
uniform vec3 uColor;
uniform vec3 uLight;
uniform vec3 uSource;
varying vec3 vWorld;
float concentrationAt(vec3 point) {
float vesselRadius = length(point.xz);
if (
point.y < 0.25 ||
point.y > 2.68 ||
vesselRadius > 1.51
) {
return 0.0;
}
vec3 offset = point - uSource;
offset.y *= 0.76;
float distanceToSource = length(offset);
float progress = clamp(uFill, 0.0, 1.0);
float reach = 0.12 + 2.25 * pow(progress, 0.72);
float core = 1.0 - smoothstep(
reach * 0.43,
reach,
distanceToSource
);
float veil = 0.20 * (1.0 - smoothstep(
reach * 0.76,
reach + 0.38,
distanceToSource
));
float lowerFade = smoothstep(0.15, 0.48, point.y);
float upperFade = 1.0 - smoothstep(2.42, 2.69, point.y);
float drift = 0.92 + 0.08 * sin(
point.x * 4.0 +
point.z * 3.5 +
uTime * 0.45
);
return clamp(
(core + veil) *
lowerFade *
upperFade *
drift *
uStrength,
0.0,
1.3
);
}
void main() {
vec3 rayDirection = normalize(vWorld - cameraPosition);
float stepSize = 0.09;
vec3 accumulatedColor = vec3(0.0);
float accumulatedAlpha = 0.0;
for (int index = 0; index < 42; index++) {
float distanceAlongRay =
(float(index) + 0.5) * stepSize;
vec3 samplePoint =
vWorld + rayDirection * distanceAlongRay;
float density = concentrationAt(samplePoint);
float sampleAlpha = 1.0 - exp(
-density * stepSize * 1.55
);
vec3 sampleColor = mix(
uColor,
uLight,
0.12 + 0.12 * sin(samplePoint.y * 3.0)
);
accumulatedColor +=
(1.0 - accumulatedAlpha) *
sampleAlpha *
sampleColor;
accumulatedAlpha +=
(1.0 - accumulatedAlpha) *
sampleAlpha;
}
float colorMix = clamp(
accumulatedAlpha * 2.25,
0.0,
1.0
);
vec3 clearWater = vec3(0.72, 0.88, 0.88);
vec3 finalColor = mix(
clearWater,
accumulatedColor / max(accumulatedAlpha, 0.0001),
colorMix
);
float finalAlpha = clamp(
accumulatedAlpha * 0.70,
0.0,
0.43
);
gl_FragColor = vec4(finalColor, finalAlpha);
#include <tonemapping_fragment>
#include <colorspace_fragment>
}
`
});
const waterBody = new THREE.Mesh(
new THREE.CylinderGeometry(
1.51,
1.39,
2.42,
24,
1,
true
),
waterMaterial
);
waterBody.position.y = 1.46;
waterBody.renderOrder = 2;
vessel.add(waterBody);
const surfaceMaterial = new THREE.MeshPhongMaterial({
color: 0xcfe8e6,
transparent: true,
opacity: 0.18,
side: THREE.DoubleSide,
depthWrite: false,
shininess: 120,
specular: 0xffffff
});
const waterSurface = new THREE.Mesh(
new THREE.CircleGeometry(1.515, 36),
surfaceMaterial
);
waterSurface.rotation.x = -Math.PI / 2;
waterSurface.position.y = 2.683;
waterSurface.renderOrder = 4;
vessel.add(waterSurface);
const waterline = new THREE.Mesh(
new THREE.TorusGeometry(1.515, 0.012, 5, 40),
new THREE.MeshBasicMaterial({
color: 0xefffff,
transparent: true,
opacity: 0.45,
depthWrite: false
})
);
waterline.rotation.x = Math.PI / 2;
waterline.position.y = 2.685;
waterline.renderOrder = 6;
vessel.add(waterline);
// ---------------------------------------------------------------------
// Faceted botanical infuser
// ---------------------------------------------------------------------
const infuser = new THREE.Group();
infuser.position.y = 3.92;
scene.add(infuser);
const metalMaterial = new THREE.MeshStandardMaterial({
color: 0xa87943,
roughness: 0.36,
metalness: 0.62,
flatShading: true
});
const darkMetalMaterial = new THREE.MeshStandardMaterial({
color: 0x665037,
roughness: 0.42,
metalness: 0.55,
flatShading: true
});
const cage = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.63, 2),
new THREE.MeshStandardMaterial({
color: 0xb68a55,
roughness: 0.4,
metalness: 0.58,
wireframe: true,
flatShading: true
})
);
cage.castShadow = true;
infuser.add(cage);
// Horizontal cage rings.
const ringHeights = [-0.47, -0.32, -0.1, 0.13, 0.35, 0.5];
for (const y of ringHeights) {
const radius = Math.sqrt(Math.max(0, 0.62 * 0.62 - y * y));
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.011, 5, 28),
metalMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.y = y;
ring.castShadow = true;
infuser.add(ring);
}
// Curved vertical ribs.
for (let ribIndex = 0; ribIndex < 6; ribIndex++) {
const angle = (ribIndex / 6) * Math.PI * 2;
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, -0.62, 0),
new THREE.Vector3(cos * 0.2, -0.45, sin * 0.2),
new THREE.Vector3(cos * 0.51, 0, sin * 0.51),
new THREE.Vector3(cos * 0.25, 0.43, sin * 0.25),
new THREE.Vector3(0, 0.62, 0)
]);
const rib = new THREE.Mesh(
new THREE.TubeGeometry(curve, 14, 0.012, 5, false),
metalMaterial
);
rib.castShadow = true;
infuser.add(rib);
}
// Small dark discs suggest perforations while preserving visibility.
const holeGeometry = new THREE.CircleGeometry(0.023, 5);
const holeMaterial = new THREE.MeshBasicMaterial({
color: 0x594936,
side: THREE.DoubleSide
});
const holes = new THREE.InstancedMesh(
holeGeometry,
holeMaterial,
42
);
const dummy = new THREE.Object3D();
const zAxis = new THREE.Vector3(0, 0, 1);
const goldenAngle = Math.PI * (3 - Math.sqrt(5));
for (let i = 0; i < 42; i++) {
const y = 1 - 2 * ((i + 0.5) / 42);
const radius = Math.sqrt(Math.max(0, 1 - y * y));
const angle = i * goldenAngle;
const normal = new THREE.Vector3(
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
);
dummy.position.copy(normal).multiplyScalar(0.632);
dummy.quaternion.setFromUnitVectors(zAxis, normal);
dummy.updateMatrix();
holes.setMatrixAt(i, dummy.matrix);
}
holes.instanceMatrix.needsUpdate = true;
infuser.add(holes);
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.19, 0.09, 10),
darkMetalMaterial
);
cap.position.y = 0.64;
cap.castShadow = true;
infuser.add(cap);
const hook = new THREE.Mesh(
new THREE.TorusGeometry(0.115, 0.017, 6, 18, Math.PI * 1.72),
metalMaterial
);
hook.position.y = 0.77;
hook.rotation.y = Math.PI * 0.15;
infuser.add(hook);
const chainCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, 0.78, 0),
new THREE.Vector3(0.015, 0.98, 0),
new THREE.Vector3(-0.035, 1.18, 0),
new THREE.Vector3(0.025, 1.36, 0)
]);
const chain = new THREE.Mesh(
new THREE.TubeGeometry(chainCurve, 16, 0.012, 5, false),
darkMetalMaterial
);
chain.castShadow = true;
infuser.add(chain);
// ---------------------------------------------------------------------
// Low-poly leaves, parented to the infuser so they remain contained
// ---------------------------------------------------------------------
const leafGeometry = new THREE.BufferGeometry();
leafGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
0.00, 0.00, 0.00,
-0.48, 0.03, 0.24,
1.00, 0.00, 0.00,
-0.48, 0.03, -0.24,
0.04, 0.14, 0.00
], 3)
);
leafGeometry.setIndex([
0, 1, 4,
1, 2, 4,
2, 3, 4,
3, 0, 4,
0, 3, 1
]);
leafGeometry.computeVertexNormals();
const leafColors = [
0x66713c,
0x788044,
0x8f8245,
0x4f633a,
0x9a8750,
0x596b3f
];
const leaves = [];
for (let i = 0; i < 18; i++) {
const leafMaterial = new THREE.MeshStandardMaterial({
color: leafColors[i % leafColors.length],
roughness: 0.86,
metalness: 0,
side: THREE.DoubleSide,
flatShading: true
});
const leaf = new THREE.Mesh(leafGeometry, leafMaterial);
const radius = 0.08 + Math.random() * 0.21;
const angle = Math.random() * Math.PI * 2;
leaf.position.set(
Math.cos(angle) * radius,
(Math.random() - 0.5) * 0.52,
Math.sin(angle) * radius
);
const scale = 0.15 + Math.random() * 0.1;
leaf.scale.setScalar(scale);
leaf.rotation.set(
Math.random() * Math.PI,
Math.random() * Math.PI,
Math.random() * Math.PI
);
leaf.userData.baseRotation = leaf.rotation.clone();
leaf.castShadow = true;
leaves.push(leaf);
infuser.add(leaf);
}
// ---------------------------------------------------------------------
// Suspended concentration particles
// ---------------------------------------------------------------------
const particleCount = 900;
const particlePositions = new Float32Array(particleCount * 3);
const particleAlpha = new Float32Array(particleCount);
const particleSize = new Float32Array(particleCount);
const particleSeed = new Float32Array(particleCount);
const particleData = [];
for (let i = 0; i < particleCount; i++) {
particleData.push({
delay: 2.35 + Math.pow(Math.random(), 0.72) * 5.25,
life: 8.5 + Math.random() * 7.5,
angle: Math.random() * Math.PI * 2,
radial: 0.65 + Math.random() * 0.7,
vertical: (Math.random() - 0.5) * 0.6,
curl: (Math.random() - 0.5) * 0.9
});
particleSize[i] = 0.07 + Math.random() * 0.075;
particleSeed[i] = Math.random();
}
const particleGeometry = new THREE.BufferGeometry();
const positionAttribute = new THREE.BufferAttribute(
particlePositions,
3
);
positionAttribute.setUsage(THREE.DynamicDrawUsage);
const alphaAttribute = new THREE.BufferAttribute(
particleAlpha,
1
);
alphaAttribute.setUsage(THREE.DynamicDrawUsage);
const sizeAttribute = new THREE.BufferAttribute(
particleSize,
1
);
sizeAttribute.setUsage(THREE.DynamicDrawUsage);
particleGeometry.setAttribute(
"position",
positionAttribute
);
particleGeometry.setAttribute(
"aAlpha",
alphaAttribute
);
particleGeometry.setAttribute(
"aSize",
sizeAttribute
);
particleGeometry.setAttribute(
"aSeed",
new THREE.BufferAttribute(particleSeed, 1)
);
const particleUniforms = {
uColor: { value: new THREE.Color(palettes.amber.color) },
uLight: { value: new THREE.Color(palettes.amber.light) }
};
const particleMaterial = new THREE.ShaderMaterial({
uniforms: particleUniforms,
transparent: true,
depthWrite: false,
blending: THREE.NormalBlending,
vertexShader: `
attribute float aAlpha;
attribute float aSize;
attribute float aSeed;
varying float vAlpha;
varying float vSeed;
void main() {
vAlpha = aAlpha;
vSeed = aSeed;
vec4 viewPosition =
modelViewMatrix * vec4(position, 1.0);
gl_PointSize =
aSize * (335.0 / max(1.0, -viewPosition.z));
gl_Position =
projectionMatrix * viewPosition;
}
`,
fragmentShader: `
precision highp float;
uniform vec3 uColor;
uniform vec3 uLight;
varying float vAlpha;
varying float vSeed;
void main() {
float distanceToCenter =
length(gl_PointCoord - vec2(0.5));
if (distanceToCenter > 0.5) {
discard;
}
float softCircle = 1.0 - smoothstep(
0.12,
0.5,
distanceToCenter
);
vec3 color = mix(
uColor,
uLight,
0.18 + vSeed * 0.32
);
gl_FragColor = vec4(
color,
softCircle * vAlpha * 0.68
);
#include <tonemapping_fragment>
#include <colorspace_fragment>
}
`
});
const concentrationParticles = new THREE.Points(
particleGeometry,
particleMaterial
);
concentrationParticles.renderOrder = 3;
concentrationParticles.frustumCulled = false;
scene.add(concentrationParticles);
// ---------------------------------------------------------------------
// Interaction
// ---------------------------------------------------------------------
let paused = false;
let simulationTime = 0;
let strength = 1;
const pauseButton = document.querySelector("#pause");
const replayButton = document.querySelector("#replay");
const strengthInput = document.querySelector("#strength");
const strengthValue = document.querySelector("#strength-value");
const progressFill = document.querySelector("#progress-fill");
const percentLabel = document.querySelector("#percent");
const timeLabel = document.querySelector("#time");
const phaseLabel = document.querySelector("#phase-label");
const phaseDescription = document.querySelector(
"#phase-description"
);
const callout = document.querySelector("#callout");
const swatches = [...document.querySelectorAll(".swatch")];
function setPaused(value) {
paused = value;
pauseButton.textContent = paused ? "▶ Resume" : "Ⅱ Pause";
}
function replay() {
simulationTime = 0;
setPaused(false);
}
pauseButton.addEventListener("click", () => {
setPaused(!paused);
});
replayButton.addEventListener("click", replay);
strengthInput.addEventListener("input", () => {
strength = Number(strengthInput.value);
strengthValue.textContent = `${strength.toFixed(1)}×`;
waterUniforms.uStrength.value = strength;
});
swatches.forEach((button) => {
button.addEventListener("click", () => {
const palette = palettes[button.dataset.palette];
swatches.forEach((item) => {
item.classList.toggle("active", item === button);
});
waterUniforms.uColor.value.set(palette.color);
waterUniforms.uLight.value.set(palette.light);
particleUniforms.uColor.value.set(palette.color);
particleUniforms.uLight.value.set(palette.light);
document.documentElement.style.setProperty(
"--accent",
palette.color
);
});
});
window.addEventListener("keydown", (event) => {
if (
event.target instanceof HTMLInputElement ||
event.target instanceof HTMLButtonElement
) {
return;
}
if (event.code === "Space") {
event.preventDefault();
setPaused(!paused);
}
if (event.key.toLowerCase() === "r") {
replay();
}
});
// Direct camera controls; no external controls addon.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.targetAzimuth -= dx * 0.006;
orbit.targetPolar = THREE.MathUtils.clamp(
orbit.targetPolar + dy * 0.005,
0.7,
1.4
);
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
renderer.domElement.hasPointerCapture &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.targetRadius = THREE.MathUtils.clamp(
orbit.targetRadius + event.deltaY * 0.004,
5.6,
10.5
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
orbit.targetAzimuth = 0.62;
orbit.targetPolar = 1.12;
orbit.targetRadius = 7.7;
});
// ---------------------------------------------------------------------
// Simulation helpers
// ---------------------------------------------------------------------
const clamp01 = (value) =>
THREE.MathUtils.clamp(value, 0, 1);
function smoothstep01(value) {
const x = clamp01(value);
return x * x * (3 - 2 * x);
}
function sourceYAt(time) {
const progress = clamp01(time / 4.8);
const eased = 1 - Math.pow(1 - progress, 3);
return THREE.MathUtils.lerp(3.92, 1.82, eased);
}
const projected = new THREE.Vector3();
const clearSurfaceColor = new THREE.Color(0xcfe8e6);
const temporaryColor = new THREE.Color();
function updateParticles(time, fill) {
for (let i = 0; i < particleCount; i++) {
const data = particleData[i];
const progress = (time - data.delay) / data.life;
if (progress <= 0 || progress >= 1) {
particleAlpha[i] = 0;
continue;
}
const angle =
data.angle +
data.curl *
Math.sin(progress * Math.PI * 1.5) *
0.22;
const radius =
0.18 +
progress * data.radial;
let x = Math.cos(angle) * radius;
let z = Math.sin(angle) * radius;
const originY = sourceYAt(data.delay);
let y =
originY +
data.vertical * 0.34 +
Math.sin(progress * Math.PI) * 0.16 -
progress * 0.22;
const maximumRadius = 1.32;
const currentRadius = Math.hypot(x, z);
if (currentRadius > maximumRadius) {
const scale = maximumRadius / currentRadius;
x *= scale;
z *= scale;
}
y = THREE.MathUtils.clamp(y, 0.37, 2.56);
const index = i * 3;
particlePositions[index] = x;
particlePositions[index + 1] = y;
particlePositions[index + 2] = z;
const fadeIn = smoothstep01(progress / 0.09);
const fadeOut = 1 - smoothstep01(
(progress - 0.68) / 0.32
);
particleAlpha[i] =
fadeIn *
fadeOut *
(0.26 + fill * 0.48) *
strength;
particleSize[i] =
(0.07 + (i % 17) * 0.0042) *
(1 + progress * 0.45);
}
positionAttribute.needsUpdate = true;
alphaAttribute.needsUpdate = true;
sizeAttribute.needsUpdate = true;
}
function updateInterface(fill) {
const percent = Math.round(fill * 100);
progressFill.style.width = `${percent}%`;
percentLabel.textContent = `${percent}%`;
const minutes = Math.floor(simulationTime / 60);
const seconds = Math.floor(simulationTime % 60);
timeLabel.textContent =
`${String(minutes).padStart(2, "0")}:` +
`${String(seconds).padStart(2, "0")}`;
if (simulationTime < 4.8) {
phaseLabel.textContent = "Lowering the infuser";
phaseDescription.textContent =
"The botanical basket descends toward a clear-water bath.";
} else if (simulationTime < 8.5) {
phaseLabel.textContent = "First color released";
phaseDescription.textContent =
"Fine compounds begin moving through the surrounding water.";
} else if (simulationTime < 16.5) {
phaseLabel.textContent = "Diffusing outward";
phaseDescription.textContent =
"The concentration field expands while the leaves stay inside.";
} else {
phaseLabel.textContent = "Infusion developed";
phaseDescription.textContent =
"A deeper color fills the vessel; the botanical basket remains sealed.";
}
}
function updateCallout() {
projected.set(
0.34,
infuser.position.y + 0.25,
0.2
).project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
callout.style.transform =
`translate(${x + 20}px, ${y - 16}px)`;
}
// ---------------------------------------------------------------------
// Render loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
simulationTime += delta;
}
const infusionDuration = 14 / strength;
const fill = smoothstep01(
(simulationTime - 2.35) / infusionDuration
);
// Lower the complete infuser and all leaves as one contained unit.
const settling = clamp01((simulationTime - 4.8) / 1.8);
const bob = Math.sin(simulationTime * 1.15) * 0.018 * settling;
infuser.position.y = sourceYAt(simulationTime) + bob;
infuser.rotation.y =
Math.sin(simulationTime * 0.36) * 0.045 * settling;
// Small leaf motion stays inside the cage.
leaves.forEach((leaf, index) => {
const base = leaf.userData.baseRotation;
leaf.rotation.z =
base.z +
Math.sin(simulationTime * 1.3 + index * 0.71) *
0.055 *
settling;
leaf.rotation.x =
base.x +
Math.cos(simulationTime * 1.05 + index) *
0.025 *
settling;
});
waterUniforms.uFill.value = fill;
waterUniforms.uTime.value = simulationTime;
waterUniforms.uSource.value.set(
0,
infuser.position.y,
0
);
temporaryColor
.copy(clearSurfaceColor)
.lerp(waterUniforms.uColor.value, fill * 0.26);
surfaceMaterial.color.copy(temporaryColor);
surfaceMaterial.opacity = 0.18 + fill * 0.075;
updateParticles(simulationTime, fill);
updateInterface(fill);
orbit.azimuth +=
(orbit.targetAzimuth - orbit.azimuth) * 0.075;
orbit.polar +=
(orbit.targetPolar - orbit.polar) * 0.075;
orbit.radius +=
(orbit.targetRadius - orbit.radius) * 0.075;
updateCamera();
updateCallout();
renderer.render(scene, camera);
}
animate();
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(
Math.min(window.devicePixelRatio, 2)
);
renderer.setSize(
window.innerWidth,
window.innerHeight
);
});
</script>
</body>
</html>
```