Prompt specification
Build or customize the Three.js 3D scene "Water vessel with uneven interval marks" 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: Water vessel with uneven interval marks
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/water-vessel-with-uneven-interval-marks-x2553
Scene Description Prompt:
A stylized water clock drains through an outlet; compare falling water height with elapsed time. Make one HTML file with Three.js from cdnjs.
Working Three.js Starter (water-vessel-with-uneven-interval-marks-x2553):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Clepsydra — Water Clock</title>
<style>
:root {
color-scheme: dark;
--bg: #071219;
--panel: #0d1b24;
--panel-2: #10232d;
--line: #213944;
--text: #edf6f3;
--muted: #8ca6ad;
--aqua: #42d6d2;
--aqua-soft: rgba(66, 214, 210, 0.14);
--amber: #e9b86e;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
}
body {
overflow: hidden;
background:
radial-gradient(circle at 20% 10%, rgba(47, 134, 146, 0.12), transparent 34%),
var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
.app {
display: grid;
grid-template-rows: 76px minmax(0, 1fr);
width: 100%;
height: 100vh;
}
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 28px;
border-bottom: 1px solid var(--line);
background: rgba(7, 18, 25, 0.82);
backdrop-filter: blur(16px);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
display: grid;
place-items: center;
width: 38px;
height: 38px;
flex: 0 0 auto;
border: 1px solid rgba(66, 214, 210, 0.32);
border-radius: 12px;
background: var(--aqua-soft);
color: var(--aqua);
}
.brand-mark svg {
width: 21px;
height: 21px;
fill: currentColor;
}
.brand-copy {
min-width: 0;
}
.brand-name {
margin: 0;
font-size: 14px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.brand-subtitle {
margin: 3px 0 0;
overflow: hidden;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.04em;
text-overflow: ellipsis;
white-space: nowrap;
}
.top-meta {
display: flex;
align-items: center;
gap: 10px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.top-meta::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--aqua);
box-shadow: 0 0 13px var(--aqua);
content: "";
}
.workspace {
display: grid;
grid-template-columns: minmax(0, 1fr) 410px;
min-height: 0;
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 42%, rgba(38, 113, 125, 0.18), transparent 42%),
linear-gradient(180deg, #0a1922, #061117);
}
.stage::after {
position: absolute;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(5, 13, 18, 0.12), transparent 28%, transparent 70%, rgba(5, 13, 18, 0.34));
content: "";
}
#scene {
position: absolute;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.stage-top {
position: absolute;
z-index: 2;
top: 24px;
left: 24px;
display: flex;
align-items: flex-start;
gap: 12px;
pointer-events: none;
}
.status-pill,
.metric-card {
border: 1px solid rgba(134, 183, 190, 0.16);
background: rgba(9, 24, 32, 0.7);
box-shadow: 0 16px 44px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(14px);
}
.status-pill {
display: flex;
align-items: center;
gap: 9px;
min-width: 120px;
padding: 10px 13px;
border-radius: 999px;
color: #bcd0d4;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 12px rgba(233, 184, 110, 0.65);
}
.status-pill[data-state="flowing"] .status-dot {
background: var(--aqua);
box-shadow: 0 0 12px rgba(66, 214, 210, 0.8);
animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
50% {
opacity: 0.4;
transform: scale(0.8);
}
}
.metric-card {
min-width: 142px;
padding: 13px 15px;
border-radius: 14px;
}
.metric-label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.metric-value {
display: block;
font-size: 25px;
font-weight: 650;
font-variant-numeric: tabular-nums;
letter-spacing: -0.04em;
}
.metric-value small {
margin-left: 3px;
color: var(--muted);
font-size: 12px;
font-weight: 550;
letter-spacing: 0;
}
.stage-bottom {
position: absolute;
z-index: 2;
right: 24px;
bottom: 22px;
left: 24px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.caption {
max-width: 340px;
color: rgba(194, 215, 218, 0.66);
font-size: 11px;
line-height: 1.65;
}
.caption strong {
display: block;
margin-bottom: 3px;
color: rgba(232, 245, 242, 0.9);
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.orbit-hint {
padding: 9px 12px;
border: 1px solid rgba(138, 181, 188, 0.13);
border-radius: 999px;
background: rgba(7, 18, 24, 0.58);
color: rgba(190, 212, 215, 0.63);
font-size: 10px;
letter-spacing: 0.05em;
white-space: nowrap;
backdrop-filter: blur(10px);
}
.sidepanel {
min-height: 0;
overflow-y: auto;
padding: 28px 27px 24px;
border-left: 1px solid var(--line);
background: linear-gradient(180deg, rgba(13, 29, 38, 0.97), rgba(9, 22, 29, 0.97));
scrollbar-color: #29434e transparent;
scrollbar-width: thin;
}
.eyebrow {
margin: 0 0 9px;
color: var(--aqua);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 2.3vw, 34px);
font-weight: 620;
line-height: 1.08;
letter-spacing: -0.045em;
}
.intro {
margin: 12px 0 22px;
color: var(--muted);
font-size: 12px;
line-height: 1.65;
}
.controls {
display: flex;
gap: 9px;
margin-bottom: 24px;
}
.primary-button,
.secondary-button,
.speed-button {
border: 1px solid var(--line);
border-radius: 11px;
color: var(--text);
cursor: pointer;
transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}
.primary-button:hover,
.secondary-button:hover,
.speed-button:hover {
border-color: rgba(66, 214, 210, 0.52);
transform: translateY(-1px);
}
.primary-button {
display: flex;
flex: 1;
align-items: center;
justify-content: center;
gap: 9px;
min-height: 43px;
border-color: rgba(66, 214, 210, 0.42);
background: var(--aqua);
color: #062025;
font-size: 12px;
font-weight: 780;
}
.primary-button:hover {
background: #65e4df;
}
#toggleIcon {
min-width: 13px;
font-size: 14px;
text-align: center;
}
.secondary-button {
width: 43px;
min-height: 43px;
background: #132630;
font-size: 19px;
}
.speed-wrap {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 26px;
}
.control-label {
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.speed-buttons {
display: flex;
gap: 5px;
padding: 4px;
border: 1px solid var(--line);
border-radius: 10px;
background: #091820;
}
.speed-button {
min-width: 37px;
padding: 6px 8px;
border-color: transparent;
background: transparent;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.speed-button.active {
border-color: rgba(66, 214, 210, 0.2);
background: var(--aqua-soft);
color: var(--aqua);
}
.chart-card {
padding: 18px 16px 13px;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(7, 19, 26, 0.58);
}
.chart-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
}
.chart-heading h2 {
margin: 0;
font-size: 13px;
font-weight: 650;
}
.chart-heading span {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.chart-wrap {
position: relative;
}
#chart {
display: block;
width: 100%;
height: auto;
overflow: visible;
}
.chart-tooltip {
position: absolute;
z-index: 4;
display: none;
min-width: 96px;
padding: 8px 10px;
border: 1px solid rgba(66, 214, 210, 0.3);
border-radius: 9px;
background: rgba(5, 17, 23, 0.94);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
color: #dff7f4;
font-size: 10px;
line-height: 1.55;
pointer-events: none;
white-space: nowrap;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 14px;
margin: 0 5px 17px;
color: var(--muted);
font-size: 9px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.legend-line {
width: 18px;
height: 2px;
border-radius: 2px;
background: var(--aqua);
}
.legend-line.reference {
height: 0;
border-top: 1px dashed #8ca6ad;
background: transparent;
}
.legend-line.projected {
height: 2px;
opacity: 0.28;
background: var(--aqua);
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 16px;
}
.data-card {
min-height: 78px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(15, 34, 44, 0.72);
}
.data-label {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.data-value {
font-size: 18px;
font-weight: 620;
font-variant-numeric: tabular-nums;
letter-spacing: -0.03em;
}
.data-value small {
margin-left: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 500;
}
.physics-note {
margin-top: 18px;
padding: 15px 16px;
border-left: 2px solid rgba(66, 214, 210, 0.55);
background: linear-gradient(90deg, rgba(66, 214, 210, 0.08), transparent);
color: var(--muted);
font-size: 10px;
line-height: 1.65;
}
.physics-note strong {
color: #c9dedd;
font-weight: 700;
}
.formula {
display: block;
margin: 6px 0;
color: var(--aqua);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
}
.footer-note {
margin: 18px 0 0;
color: #58727a;
font-size: 8px;
letter-spacing: 0.11em;
text-align: center;
text-transform: uppercase;
}
@media (max-width: 960px) {
body {
overflow: auto;
}
.app {
height: auto;
min-height: 100vh;
grid-template-rows: 70px auto;
}
.workspace {
grid-template-columns: 1fr;
}
.stage {
min-height: 63vh;
}
.sidepanel {
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
.top-meta {
display: none;
}
}
@media (max-width: 560px) {
.topbar {
padding: 0 17px;
}
.brand-subtitle {
max-width: 200px;
}
.stage {
min-height: 58vh;
}
.stage-top {
top: 15px;
left: 15px;
}
.status-pill {
display: none;
}
.metric-card {
min-width: 124px;
}
.stage-bottom {
right: 15px;
bottom: 15px;
left: 15px;
}
.caption {
max-width: 220px;
}
.caption span {
display: none;
}
.orbit-hint {
padding: 8px 10px;
}
.sidepanel {
padding: 24px 17px;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24">
<path d="M12 2.5C9.3 6.2 5.2 10.3 5.2 14.4A6.8 6.8 0 0 0 12 21.2a6.8 6.8 0 0 0 6.8-6.8C18.8 10.3 14.7 6.2 12 2.5Zm0 16.5c-2.1 0-3.8-1.5-3.8-3.5 0-2.1 1.7-3.9 3.8-6.5 2.1 2.6 3.8 4.4 3.8 6.5 0 2-1.7 3.5-3.8 3.5Z"/>
</svg>
</div>
<div class="brand-copy">
<p class="brand-name">Clepsydra</p>
<p class="brand-subtitle">A study in gravity, water, and elapsed time</p>
</div>
</div>
<div class="top-meta">Interactive water clock · 48 second scale</div>
</header>
<main class="workspace">
<section class="stage" id="stage" aria-label="Interactive three-dimensional water clock">
<div id="scene"></div>
<div class="stage-top">
<div class="status-pill" id="statusPill" data-state="flowing">
<span class="status-dot"></span>
<span id="statusLabel">Flowing</span>
</div>
<div class="metric-card">
<span class="metric-label">Elapsed time</span>
<strong class="metric-value" id="stageElapsed">00:00.0</strong>
</div>
</div>
<div class="stage-bottom">
<div class="caption">
<strong>Torricelli-style drain</strong>
<span>Water level follows a nonlinear outflow curve through the lower outlet.</span>
</div>
<div class="orbit-hint">Drag to orbit · Scroll to zoom</div>
</div>
</section>
<aside class="sidepanel">
<p class="eyebrow">Live comparison</p>
<h1>Height over time</h1>
<p class="intro">
Watch the vessel drain while its measured water height is plotted against
elapsed time.
</p>
<div class="controls">
<button class="primary-button" id="toggleButton" type="button">
<span id="toggleIcon">Ⅱ</span>
<span id="toggleText">Pause</span>
</button>
<button class="secondary-button" id="resetButton" type="button" aria-label="Reset water clock" title="Reset">
↻
</button>
</div>
<div class="speed-wrap">
<span class="control-label">Clock speed</span>
<div class="speed-buttons" aria-label="Clock speed">
<button class="speed-button active" data-speed="1" type="button">1×</button>
<button class="speed-button" data-speed="2" type="button">2×</button>
<button class="speed-button" data-speed="4" type="button">4×</button>
</div>
</div>
<section class="chart-card">
<div class="chart-heading">
<h2>Water height / elapsed time</h2>
<span>30 cm scale</span>
</div>
<div class="chart-wrap" id="chartWrap">
<svg id="chart" viewBox="0 0 640 320" role="img" aria-label="Graph of water height against elapsed time">
<defs>
<linearGradient id="areaGradient" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stop-color="#42d6d2" stop-opacity="0.24"/>
<stop offset="100%" stop-color="#42d6d2" stop-opacity="0"/>
</linearGradient>
</defs>
<g id="gridLayer"></g>
<path id="projectedPath" fill="none" stroke="#42d6d2" stroke-width="2" opacity="0.22"></path>
<path id="referencePath" fill="none" stroke="#8ca6ad" stroke-width="1.25" stroke-dasharray="5 6" opacity="0.75"></path>
<path id="areaPath" fill="url(#areaGradient)"></path>
<path id="actualPath" fill="none" stroke="#42d6d2" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"></path>
<circle id="currentDot" r="5" fill="#42d6d2" stroke="#d7fffa" stroke-width="2"></circle>
<g id="hoverGuide" opacity="0">
<line id="hoverLine" y1="28" y2="274" stroke="#9ab9bd" stroke-width="1" stroke-dasharray="3 4"></line>
<circle id="hoverDot" r="4" fill="#0d1b24" stroke="#9fd8d7" stroke-width="2"></circle>
</g>
</svg>
<div class="chart-tooltip" id="chartTooltip"></div>
</div>
<div class="legend">
<span class="legend-item"><i class="legend-line"></i>Measured</span>
<span class="legend-item"><i class="legend-line projected"></i>Projected</span>
<span class="legend-item"><i class="legend-line reference"></i>Linear reference</span>
</div>
<div class="metrics">
<div class="data-card">
<span class="data-label">Water height</span>
<span class="data-value"><span id="heightValue">30.0</span><small>cm</small></span>
</div>
<div class="data-card">
<span class="data-label">Time remaining</span>
<span class="data-value" id="remainingValue">00:48.0</span>
</div>
<div class="data-card">
<span class="data-label">Relative outflow</span>
<span class="data-value"><span id="flowValue">100</span><small>%</small></span>
</div>
<div class="data-card">
<span class="data-label">Level descent</span>
<span class="data-value"><span id="paceValue">75.0</span><small>mm/min</small></span>
</div>
</div>
</section>
<div class="physics-note">
<strong>Why the curve bends</strong>
As the surface falls, the pressure head decreases and the outflow slows.
<span class="formula">h(t) = h₀(1 − t/T)²</span>
The dashed line shows what a constant-rate drain would look like.
</div>
<p class="footer-note">Three.js r160 · Core module only</p>
</aside>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Constants and state
// ------------------------------------------------------------
const DURATION = 48;
const MAX_HEIGHT_CM = 30;
const TANK_HEIGHT = 3;
const TANK_BOTTOM = 2.35;
const TANK_TOP = TANK_BOTTOM + TANK_HEIGHT;
const STREAM_TOP = 1.91;
const STREAM_BOTTOM = 0.76;
let elapsed = 0;
let speed = 1;
let running = !window.matchMedia("(prefers-reduced-motion: reduce)").matches;
let previousTime = performance.now();
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function normalizedHeight(time) {
const remaining = Math.max(0, 1 - time / DURATION);
return remaining * remaining;
}
function formatTime(seconds) {
const safe = Math.max(0, seconds);
const minutes = Math.floor(safe / 60);
const wholeSeconds = Math.floor(safe % 60);
const tenths = Math.floor((safe % 1) * 10);
return `${String(minutes).padStart(2, "0")}:${String(wholeSeconds).padStart(2, "0")}.${tenths}`;
}
// ------------------------------------------------------------
// Three.js scene
// ------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const stage = document.getElementById("stage");
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x071219, 0.025);
const camera = new THREE.PerspectiveCamera(36, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x071219, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Drag to rotate and scroll to zoom the water clock");
sceneHost.appendChild(renderer.domElement);
// Direct camera controls: no OrbitControls or other addons.
const cameraTarget = new THREE.Vector3(0, 2.55, 0);
const cameraState = {
radius: 9.6,
theta: 0.58,
phi: 1.13
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraTarget.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraTarget.y + cameraState.radius * Math.cos(cameraState.phi),
cameraTarget.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraState.radius = 9.6;
cameraState.theta = 0.58;
cameraState.phi = 1.13;
updateCamera();
}
updateCamera();
const drag = {
active: false,
x: 0,
y: 0
};
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
drag.active = true;
drag.x = event.clientX;
drag.y = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!drag.active) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.48,
1.46
);
updateCamera();
});
function endDrag(event) {
drag.active = false;
if (event.pointerId !== undefined && 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();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
6.4,
14
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
// ------------------------------------------------------------
// Lights and materials
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xc8f6ff, 0x17232a, 1.45));
scene.add(new THREE.AmbientLight(0xb5d6db, 0.28));
const keyLight = new THREE.DirectionalLight(0xfff0d3, 3.1);
keyLight.position.set(4.5, 8.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
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.0005;
scene.add(keyLight);
const aquaLight = new THREE.PointLight(0x35d7db, 20, 11, 2);
aquaLight.position.set(-3.2, 3.5, 2.2);
scene.add(aquaLight);
const amberLight = new THREE.PointLight(0xffb45f, 15, 9, 2);
amberLight.position.set(3.2, 2.4, -2.2);
scene.add(amberLight);
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0x26363b,
roughness: 0.82,
metalness: 0.08
});
const darkMetalMaterial = new THREE.MeshStandardMaterial({
color: 0x223239,
roughness: 0.38,
metalness: 0.78
});
const brassMaterial = new THREE.MeshStandardMaterial({
color: 0xb38a52,
roughness: 0.3,
metalness: 0.82
});
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xc4f0f2,
transparent: true,
opacity: 0.18,
roughness: 0.08,
metalness: 0,
transmission: 0.15,
thickness: 0.25,
side: THREE.DoubleSide,
depthWrite: false
});
const waterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x24c6cf,
emissive: 0x073f46,
emissiveIntensity: 0.65,
transparent: true,
opacity: 0.72,
roughness: 0.16,
metalness: 0.05,
transmission: 0.12,
thickness: 0.6,
depthWrite: false
});
const surfaceMaterial = new THREE.MeshPhysicalMaterial({
color: 0x63ece6,
emissive: 0x0a5b60,
emissiveIntensity: 0.55,
transparent: true,
opacity: 0.9,
roughness: 0.12,
side: THREE.DoubleSide
});
const streamMaterial = new THREE.MeshPhysicalMaterial({
color: 0x59e9e4,
emissive: 0x0b7778,
emissiveIntensity: 1.1,
transparent: true,
opacity: 0.76,
roughness: 0.08
});
// ------------------------------------------------------------
// Environment and clock geometry
// ------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x08151c,
roughness: 0.95,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.02;
floor.receiveShadow = true;
scene.add(floor);
const clock = new THREE.Group();
scene.add(clock);
// Pedestal
const lowerBase = new THREE.Mesh(
new THREE.CylinderGeometry(1.28, 1.38, 0.16, 64),
stoneMaterial
);
lowerBase.position.y = 0.08;
lowerBase.castShadow = true;
lowerBase.receiveShadow = true;
clock.add(lowerBase);
const upperBase = new THREE.Mesh(
new THREE.CylinderGeometry(1.08, 1.22, 0.16, 64),
darkMetalMaterial
);
upperBase.position.y = 0.22;
upperBase.castShadow = true;
upperBase.receiveShadow = true;
clock.add(upperBase);
const topPlate = new THREE.Mesh(
new THREE.CylinderGeometry(1.04, 1.04, 0.08, 64),
brassMaterial
);
topPlate.position.y = 0.34;
topPlate.castShadow = true;
clock.add(topPlate);
// Catch basin
const basin = new THREE.Mesh(
new THREE.CylinderGeometry(1.0, 0.77, 0.3, 64, 1, true),
new THREE.MeshStandardMaterial({
color: 0x9e7444,
roughness: 0.34,
metalness: 0.78,
side: THREE.DoubleSide
})
);
basin.position.y = 0.49;
basin.castShadow = true;
clock.add(basin);
const basinRim = new THREE.Mesh(
new THREE.TorusGeometry(0.99, 0.035, 12, 64),
brassMaterial
);
basinRim.rotation.x = Math.PI / 2;
basinRim.position.y = 0.64;
basinRim.castShadow = true;
clock.add(basinRim);
const basinWater = new THREE.Mesh(
new THREE.CircleGeometry(0.86, 64),
surfaceMaterial.clone()
);
basinWater.material.opacity = 0.72;
basinWater.rotation.x = -Math.PI / 2;
basinWater.position.y = 0.565;
clock.add(basinWater);
const basinRipple = new THREE.Mesh(
new THREE.TorusGeometry(0.48, 0.009, 8, 64),
new THREE.MeshBasicMaterial({
color: 0xa8fffa,
transparent: true,
opacity: 0.34
})
);
basinRipple.rotation.x = Math.PI / 2;
basinRipple.position.y = 0.58;
clock.add(basinRipple);
// Upright supports
for (const x of [-1.08, 1.08]) {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.075, 2.0, 20),
darkMetalMaterial
);
post.position.set(x, 1.31, 0);
post.castShadow = true;
clock.add(post);
const collar = new THREE.Mesh(
new THREE.CylinderGeometry(0.105, 0.105, 0.12, 24),
brassMaterial
);
collar.position.set(x, 2.22, 0);
collar.castShadow = true;
clock.add(collar);
}
const supportBar = new THREE.Mesh(
new THREE.BoxGeometry(2.4, 0.12, 0.2),
darkMetalMaterial
);
supportBar.position.set(0, 2.24, 0);
supportBar.castShadow = true;
clock.add(supportBar);
// Tank bottom
const tankBottom = new THREE.Mesh(
new THREE.CylinderGeometry(0.97, 1.0, 0.13, 64),
brassMaterial
);
tankBottom.position.y = TANK_BOTTOM - 0.025;
tankBottom.castShadow = true;
clock.add(tankBottom);
// Glass vessel
const glassVessel = new THREE.Mesh(
new THREE.CylinderGeometry(0.93, 0.93, TANK_HEIGHT, 64, 1, true),
glassMaterial
);
glassVessel.position.y = TANK_BOTTOM + TANK_HEIGHT / 2;
glassVessel.renderOrder = 3;
clock.add(glassVessel);
// Tank rims
for (const y of [TANK_BOTTOM + 0.015, TANK_TOP]) {
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.935, 0.032, 12, 64),
brassMaterial
);
rim.rotation.x = Math.PI / 2;
rim.position.y = y;
rim.castShadow = true;
clock.add(rim);
}
// Water body
const waterBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.845, 0.845, 1, 64),
waterMaterial
);
waterBody.renderOrder = 1;
clock.add(waterBody);
// Water surface
const waterSurface = new THREE.Mesh(
new THREE.CircleGeometry(0.835, 64),
surfaceMaterial
);
waterSurface.rotation.x = -Math.PI / 2;
waterSurface.renderOrder = 2;
clock.add(waterSurface);
const surfaceRing = new THREE.Mesh(
new THREE.TorusGeometry(0.76, 0.008, 8, 64),
new THREE.MeshBasicMaterial({
color: 0xc6fffa,
transparent: true,
opacity: 0.28
})
);
surfaceRing.rotation.x = Math.PI / 2;
surfaceRing.renderOrder = 4;
clock.add(surfaceRing);
// Outlet and stream
const nozzle = new THREE.Mesh(
new THREE.CylinderGeometry(0.095, 0.155, 0.37, 32),
brassMaterial
);
nozzle.position.y = 2.10;
nozzle.castShadow = true;
clock.add(nozzle);
const outletRing = new THREE.Mesh(
new THREE.TorusGeometry(0.15, 0.024, 10, 32),
darkMetalMaterial
);
outletRing.rotation.x = Math.PI / 2;
outletRing.position.y = 1.92;
clock.add(outletRing);
const stream = new THREE.Mesh(
new THREE.CylinderGeometry(0.04, 0.047, 1, 20),
streamMaterial
);
stream.renderOrder = 3;
clock.add(stream);
// Falling droplets
const droplets = [];
const dropletGeometry = new THREE.SphereGeometry(0.037, 12, 10);
const dropletMaterial = new THREE.MeshBasicMaterial({
color: 0x8cfff7,
transparent: true,
opacity: 0.88
});
for (let i = 0; i < 15; i++) {
const droplet = new THREE.Mesh(dropletGeometry, dropletMaterial);
droplet.userData.offset = i / 15;
clock.add(droplet);
droplets.push(droplet);
}
// ------------------------------------------------------------
// Vertical ruler
// ------------------------------------------------------------
function createTextSprite(text) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 96;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "#91b0b5";
context.font = "600 38px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 128, 48);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(0.48, 0.18, 1);
return sprite;
}
const ruler = new THREE.Group();
ruler.position.z = -0.34;
clock.add(ruler);
const rulerLine = new THREE.Mesh(
new THREE.BoxGeometry(0.022, TANK_HEIGHT, 0.025),
new THREE.MeshBasicMaterial({
color: 0x78959b,
transparent: true,
opacity: 0.7
})
);
rulerLine.position.set(1.25, TANK_BOTTOM + TANK_HEIGHT / 2, 0);
ruler.add(rulerLine);
for (let i = 0; i <= 12; i++) {
const height = i * 0.25;
const major = i % 4 === 0;
const tick = new THREE.Mesh(
new THREE.BoxGeometry(major ? 0.23 : 0.12, 0.016, 0.025),
new THREE.MeshBasicMaterial({
color: major ? 0xa3b8bb : 0x607f87,
transparent: true,
opacity: major ? 0.82 : 0.62
})
);
tick.position.set(1.25 + (major ? 0.115 : 0.06), TANK_BOTTOM + height, 0);
ruler.add(tick);
}
for (const [value, height] of [[0, 0], [10, 1], [20, 2], [30, 3]]) {
const label = createTextSprite(String(value));
label.position.set(1.64, TANK_BOTTOM + height, 0.02);
ruler.add(label);
}
// Decorative dust motes
const dustPositions = new Float32Array(90 * 3);
for (let i = 0; i < 90; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 12;
dustPositions[i * 3 + 1] = Math.random() * 7 + 0.3;
dustPositions[i * 3 + 2] = (Math.random() - 0.5) * 9;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute("position", new THREE.BufferAttribute(dustPositions, 3));
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0x91c7ca,
size: 0.025,
transparent: true,
opacity: 0.28,
depthWrite: false
})
);
scene.add(dust);
// ------------------------------------------------------------
// Chart
// ------------------------------------------------------------
const chart = document.getElementById("chart");
const chartWrap = document.getElementById("chartWrap");
const gridLayer = document.getElementById("gridLayer");
const projectedPath = document.getElementById("projectedPath");
const referencePath = document.getElementById("referencePath");
const areaPath = document.getElementById("areaPath");
const actualPath = document.getElementById("actualPath");
const currentDot = document.getElementById("currentDot");
const hoverGuide = document.getElementById("hoverGuide");
const hoverLine = document.getElementById("hoverLine");
const hoverDot = document.getElementById("hoverDot");
const chartTooltip = document.getElementById("chartTooltip");
const plot = {
left: 56,
right: 620,
top: 28,
bottom: 274
};
plot.width = plot.right - plot.left;
plot.height = plot.bottom - plot.top;
const svgNamespace = "http://www.w3.org/2000/svg";
function makeSvgElement(name, attributes = {}) {
const element = document.createElementNS(svgNamespace, name);
for (const [key, value] of Object.entries(attributes)) {
element.setAttribute(key, value);
}
return element;
}
function chartX(time) {
return plot.left + (time / DURATION) * plot.width;
}
function chartY(heightRatio) {
return plot.top + (1 - heightRatio) * plot.height;
}
function addGridLine(x1, y1, x2, y2) {
gridLayer.appendChild(makeSvgElement("line", {
x1, y1, x2, y2,
stroke: "#203741",
"stroke-width": 1
}));
}
function addAxisLabel(x, y, text, anchor = "middle") {
const label = makeSvgElement("text", {
x, y,
fill: "#718c93",
"font-size": 10,
"font-family": "system-ui, sans-serif",
"text-anchor": anchor
});
label.textContent = text;
gridLayer.appendChild(label);
}
for (let i = 0; i <= 4; i++) {
const x = plot.left + (i / 4) * plot.width;
addGridLine(x, plot.top, x, plot.bottom);
addAxisLabel(x, 298, `${i * 12}s`);
}
for (let i = 0; i <= 4; i++) {
const y = plot.top + (i / 4) * plot.height;
addGridLine(plot.left, y, plot.right, y);
addAxisLabel(plot.left - 11, y + 3, String(30 - i * 7.5), "end");
}
addAxisLabel((plot.left + plot.right) / 2, 316, "ELAPSED TIME", "middle");
addAxisLabel(16, (plot.top + plot.bottom) / 2, "HEIGHT", "middle");
function buildPath(timeStep = 0.5) {
const points = [];
for (let time = 0; time <= DURATION + 0.001; time += timeStep) {
points.push([chartX(time), chartY(normalizedHeight(time))]);
}
return points.map((point, index) =>
`${index === 0 ? "M" : "L"}${point[0].toFixed(2)},${point[1].toFixed(2)}`
).join(" ");
}
projectedPath.setAttribute("d", buildPath());
referencePath.setAttribute(
"d",
`M${chartX(0)},${chartY(1)} L${chartX(DURATION)},${chartY(0)}`
);
function updateChart() {
const currentRatio = normalizedHeight(elapsed);
const endX = chartX(elapsed);
const endY = chartY(currentRatio);
let path = "";
if (elapsed > 0.025) {
const step = Math.max(0.08, elapsed / 90);
for (let time = 0; time <= elapsed + 0.001; time += step) {
const x = chartX(Math.min(time, elapsed));
const y = chartY(normalizedHeight(Math.min(time, elapsed)));
path += `${path ? " L" : "M"}${x.toFixed(2)},${y.toFixed(2)}`;
}
}
actualPath.setAttribute("d", path);
areaPath.setAttribute(
"d",
path
? `${path} L${endX.toFixed(2)},${plot.bottom} L${plot.left},${plot.bottom} Z`
: ""
);
currentDot.setAttribute("cx", endX);
currentDot.setAttribute("cy", endY);
currentDot.setAttribute("opacity", elapsed > 0 ? 1 : 0.7);
}
chart.addEventListener("pointermove", (event) => {
const bounds = chart.getBoundingClientRect();
const svgX = ((event.clientX - bounds.left) / bounds.width) * 640;
const clampedX = THREE.MathUtils.clamp(svgX, plot.left, plot.right);
const time = ((clampedX - plot.left) / plot.width) * DURATION;
const ratio = normalizedHeight(time);
const y = chartY(ratio);
hoverGuide.setAttribute("opacity", 1);
hoverLine.setAttribute("x1", clampedX);
hoverLine.setAttribute("x2", clampedX);
hoverDot.setAttribute("cx", clampedX);
hoverDot.setAttribute("cy", y);
chartTooltip.style.display = "block";
chartTooltip.innerHTML =
`<strong>${time.toFixed(1)} seconds</strong><br>` +
`${(ratio * MAX_HEIGHT_CM).toFixed(1)} cm remaining`;
const wrapBounds = chartWrap.getBoundingClientRect();
const tooltipX = event.clientX - wrapBounds.left + 12;
const tooltipY = event.clientY - wrapBounds.top - 20;
chartTooltip.style.left =
`${Math.min(tooltipX, wrapBounds.width - 120)}px`;
chartTooltip.style.top = `${Math.max(5, tooltipY)}px`;
});
chart.addEventListener("pointerleave", () => {
hoverGuide.setAttribute("opacity", 0);
chartTooltip.style.display = "none";
});
// ------------------------------------------------------------
// UI controls
// ------------------------------------------------------------
const toggleButton = document.getElementById("toggleButton");
const toggleIcon = document.getElementById("toggleIcon");
const toggleText = document.getElementById("toggleText");
const resetButton = document.getElementById("resetButton");
const statusPill = document.getElementById("statusPill");
const statusLabel = document.getElementById("statusLabel");
const stageElapsed = document.getElementById("stageElapsed");
const heightValue = document.getElementById("heightValue");
const remainingValue = document.getElementById("remainingValue");
const flowValue = document.getElementById("flowValue");
const paceValue = document.getElementById("paceValue");
function updateControls() {
const complete = elapsed >= DURATION;
if (complete) {
toggleIcon.textContent = "↻";
toggleText.textContent = "Run again";
} else if (running) {
toggleIcon.textContent = "Ⅱ";
toggleText.textContent = "Pause";
} else {
toggleIcon.textContent = "▶";
toggleText.textContent = "Start";
}
if (complete) {
statusPill.dataset.state = "complete";
statusLabel.textContent = "Drained";
} else if (running) {
statusPill.dataset.state = "flowing";
statusLabel.textContent = "Flowing";
} else {
statusPill.dataset.state = "paused";
statusLabel.textContent = "Paused";
}
}
toggleButton.addEventListener("click", () => {
if (elapsed >= DURATION) {
elapsed = 0;
running = true;
} else {
running = !running;
}
updateControls();
});
resetButton.addEventListener("click", () => {
elapsed = 0;
running = true;
updateControls();
});
document.querySelectorAll(".speed-button").forEach((button) => {
button.addEventListener("click", () => {
speed = Number(button.dataset.speed);
document.querySelectorAll(".speed-button").forEach((otherButton) => {
otherButton.classList.toggle("active", otherButton === button);
});
});
});
// ------------------------------------------------------------
// Responsive rendering
// ------------------------------------------------------------
function resize() {
const width = Math.max(1, sceneHost.clientWidth);
const height = Math.max(1, sceneHost.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(sceneHost);
resize();
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
function updateScene(ratio) {
const worldHeight = ratio * TANK_HEIGHT;
const waterY = TANK_BOTTOM + worldHeight / 2;
waterBody.scale.y = Math.max(0.001, worldHeight);
waterBody.position.y = waterY;
waterSurface.position.y = TANK_BOTTOM + worldHeight + 0.003;
const ripple = reducedMotion ? 1 : 1 + Math.sin(elapsed * 4.2) * 0.006;
waterSurface.scale.set(ripple, ripple, 1);
surfaceRing.position.y = TANK_BOTTOM + worldHeight + 0.009;
surfaceRing.scale.setScalar(0.96 + Math.sin(elapsed * 2.3) * 0.018);
surfaceRing.material.opacity = ratio > 0.002 ? 0.28 : 0;
const outflow = Math.sqrt(ratio);
const streamLength = STREAM_TOP - STREAM_BOTTOM;
stream.visible = ratio > 0.0015;
stream.scale.set(
0.52 + outflow * 0.48,
streamLength,
0.52 + outflow * 0.48
);
stream.position.set(
0,
STREAM_BOTTOM + streamLength / 2,
0
);
droplets.forEach((droplet, index) => {
droplet.visible = ratio > 0.0015;
const phase = (elapsed * (1.4 + (index % 3) * 0.08) + droplet.userData.offset) % 1;
const x = Math.sin(index * 12.73 + elapsed * 3.2) * 0.024;
const z = Math.cos(index * 8.41 + elapsed * 2.7) * 0.024;
droplet.position.set(x, STREAM_TOP - phase * streamLength, z);
const scale = 0.7 + outflow * 0.5;
droplet.scale.setScalar(scale);
});
basinWater.position.y = 0.555 + (1 - ratio) * 0.075;
basinRipple.position.y = basinWater.position.y + 0.008;
const rippleScale = 0.7 + ((elapsed * 0.65) % 1) * 0.55;
basinRipple.scale.setScalar(rippleScale);
basinRipple.material.opacity = 0.12 + outflow * 0.2;
}
function updateUI(ratio) {
stageElapsed.textContent = formatTime(elapsed);
heightValue.textContent = (ratio * MAX_HEIGHT_CM).toFixed(1);
remainingValue.textContent = formatTime(DURATION - elapsed);
flowValue.textContent = Math.round(Math.sqrt(ratio) * 100);
const descentMmPerMinute =
(2 * MAX_HEIGHT_CM / DURATION) * (1 - elapsed / DURATION) * 60;
paceValue.textContent = descentMmPerMinute.toFixed(1);
}
renderer.setAnimationLoop((now) => {
const dt = Math.min((now - previousTime) / 1000, 0.1);
previousTime = now;
if (running && elapsed < DURATION) {
elapsed = Math.min(DURATION, elapsed + dt * speed);
if (elapsed >= DURATION) {
running = false;
updateControls();
}
}
const ratio = normalizedHeight(elapsed);
updateScene(ratio);
updateUI(ratio);
updateChart();
if (!reducedMotion) {
dust.rotation.y += dt * 0.012;
dust.position.y = Math.sin(now * 0.0002) * 0.08;
}
renderer.render(scene, camera);
});
updateControls();
updateScene(normalizedHeight(elapsed));
updateUI(normalizedHeight(elapsed));
updateChart();
</script>
</body>
</html>
```