Prompt specification
Build or customize the Three.js 3D scene "Equal pH different buffering model" 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: Equal pH different buffering model
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/equal-ph-different-buffering-model-x1922
Scene Description Prompt:
Equal pH different buffering model. Compare two explicitly simplified solutions with matching initial pH but different buffer capacity; show different responses to the same symbolic addition without giving real chemical mixing instructions. Please build this with Three.js from cdnjs in one self-contained HTML file, using a 3D cutaway.
Working Three.js Starter (equal-ph-different-buffering-model-x1922):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Matched-pH Buffer Capacity — Three.js Cutaway</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(8, 17, 31, 0.84);
--panel-border: rgba(160, 218, 255, 0.16);
--text: #eef8ff;
--muted: #91a8bd;
--cyan: #5eead4;
--blue: #7aa7ff;
--acid: #ff6b83;
--base: #668fff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 38%, #122943 0%, #091728 43%, #040a13 100%);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
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:
linear-gradient(to bottom, rgba(4, 10, 19, 0.36), transparent 24%),
linear-gradient(to top, rgba(4, 10, 19, 0.52), transparent 36%);
}
.header {
position: fixed;
top: 25px;
left: 28px;
z-index: 5;
width: min(430px, calc(100vw - 56px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 23px;
height: 2px;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 12px rgba(94, 234, 212, 0.7);
}
h1 {
margin: 0;
font-size: clamp(27px, 3.4vw, 45px);
line-height: 1.02;
letter-spacing: -0.045em;
text-wrap: balance;
}
.subtitle {
max-width: 390px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.model-note {
position: fixed;
z-index: 5;
top: 24px;
right: 24px;
width: 330px;
padding: 17px 18px;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: rgba(7, 16, 29, 0.74);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(16px);
}
.note-title {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.equation {
margin: 10px 0 8px;
color: #e8f7ff;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 13px;
line-height: 1.55;
white-space: nowrap;
}
.beta-list {
display: flex;
gap: 14px;
margin-bottom: 10px;
color: #b7c9d8;
font-size: 11px;
}
.beta-list span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.beta-list i {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 9px currentColor;
}
.beta-list span:last-child i {
background: var(--blue);
}
.model-note p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.tank-tag {
position: fixed;
z-index: 4;
width: 156px;
padding: 10px 12px;
transform: translate(-50%, -100%);
border: 1px solid rgba(160, 218, 255, 0.22);
border-radius: 12px;
background: rgba(6, 15, 27, 0.82);
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(10px);
pointer-events: none;
text-align: left;
}
.tank-tag::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 17px;
background: linear-gradient(var(--cyan), transparent);
opacity: 0.7;
}
.tank-tag.high::after {
background: linear-gradient(var(--blue), transparent);
}
.tank-tag > span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
}
.tag-reading {
display: flex;
align-items: baseline;
gap: 6px;
}
.tag-reading strong {
font-size: 25px;
line-height: 1;
letter-spacing: -0.04em;
}
.tag-reading small,
.tank-tag em {
color: var(--muted);
font-size: 10px;
font-style: normal;
}
.tank-tag em {
display: block;
margin-top: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.scene-caption {
position: fixed;
z-index: 3;
left: 28px;
bottom: 226px;
color: #8199ae;
font-size: 10px;
line-height: 1.6;
letter-spacing: 0.05em;
pointer-events: none;
}
.scene-caption strong {
color: #c3d5e4;
font-weight: 700;
}
.controls {
position: fixed;
z-index: 10;
left: 50%;
bottom: 18px;
width: min(980px, calc(100vw - 32px));
transform: translateX(-50%);
border: 1px solid var(--panel-border);
border-radius: 20px;
background: var(--panel);
box-shadow:
0 22px 70px rgba(0, 0, 0, 0.38),
inset 0 1px rgba(255, 255, 255, 0.03);
backdrop-filter: blur(20px);
overflow: hidden;
}
.panel-grid {
display: grid;
grid-template-columns: minmax(0, 1.25fr) minmax(340px, 0.9fr);
}
.addition,
.results {
padding: 17px 20px 16px;
}
.results {
border-left: 1px solid rgba(160, 218, 255, 0.11);
background: rgba(255, 255, 255, 0.018);
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.mode-toggle {
display: inline-flex;
gap: 3px;
padding: 3px;
border: 1px solid rgba(160, 218, 255, 0.13);
border-radius: 10px;
background: rgba(0, 0, 0, 0.18);
}
.mode-toggle button {
padding: 7px 10px;
border: 0;
border-radius: 7px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
}
.mode-toggle button.active {
background: rgba(102, 143, 255, 0.18);
color: #dfe9ff;
box-shadow: inset 0 0 0 1px rgba(122, 167, 255, 0.22);
}
.mode-toggle button[data-mode="acid"].active {
background: rgba(255, 107, 131, 0.15);
color: #ffe2e8;
box-shadow: inset 0 0 0 1px rgba(255, 107, 131, 0.22);
}
.slider-label {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 9px;
font-size: 12px;
}
.slider-label span {
color: #b7c9d8;
}
.slider-label output {
color: var(--text);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 13px;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 4px 0 7px;
appearance: none;
border-radius: 99px;
background: linear-gradient(
90deg,
rgba(94, 234, 212, 0.7),
rgba(122, 167, 255, 0.7)
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
border: 3px solid #dffbff;
border-radius: 50%;
background: #173b52;
box-shadow: 0 0 0 4px rgba(94, 234, 212, 0.1);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #dffbff;
border-radius: 50%;
background: #173b52;
box-shadow: 0 0 0 4px rgba(94, 234, 212, 0.1);
}
.scale {
display: flex;
justify-content: space-between;
color: #667e92;
font-size: 9px;
}
.buttons {
display: flex;
gap: 9px;
margin-top: 15px;
}
button {
border: 1px solid rgba(160, 218, 255, 0.16);
border-radius: 10px;
color: var(--text);
cursor: pointer;
transition:
transform 140ms ease,
background 140ms ease,
border-color 140ms ease;
}
button:hover {
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.primary {
flex: 1;
padding: 11px 16px;
border-color: rgba(94, 234, 212, 0.36);
background: linear-gradient(135deg, rgba(94, 234, 212, 0.19), rgba(122, 167, 255, 0.18));
color: #ecffff;
font-size: 12px;
font-weight: 750;
}
.secondary {
padding: 10px 15px;
background: rgba(255, 255, 255, 0.025);
color: #a9bdce;
font-size: 11px;
}
.results-heading {
margin-bottom: 12px;
}
.separation {
padding: 5px 8px;
border: 1px solid rgba(160, 218, 255, 0.13);
border-radius: 99px;
color: #b9ccdc;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
letter-spacing: 0;
text-transform: none;
}
.model-row {
display: grid;
grid-template-columns: minmax(112px, 1fr) 77px minmax(75px, 0.85fr);
align-items: center;
gap: 10px;
padding: 9px 0;
border-top: 1px solid rgba(160, 218, 255, 0.08);
}
.model-name {
display: flex;
align-items: center;
gap: 7px;
color: #b7c9d8;
font-size: 10px;
font-weight: 750;
}
.model-name small {
display: block;
margin-left: 14px;
margin-top: 2px;
color: #6f879b;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
font-weight: 500;
}
.model-dot {
flex: 0 0 auto;
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 9px rgba(94, 234, 212, 0.65);
}
.model-dot.high {
background: var(--blue);
box-shadow: 0 0 9px rgba(122, 167, 255, 0.65);
}
.reading {
text-align: right;
}
.reading strong {
display: block;
font-size: 18px;
line-height: 1;
letter-spacing: -0.03em;
}
.reading span {
display: block;
margin-top: 4px;
color: #728a9d;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
}
.response-track {
position: relative;
height: 7px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.055);
}
.response-track::after {
content: "";
position: absolute;
left: 50%;
top: 0;
width: 1px;
height: 100%;
background: rgba(255, 255, 255, 0.3);
}
.response-track i {
position: absolute;
top: 0;
height: 100%;
border-radius: 99px;
background: var(--cyan);
box-shadow: 0 0 9px currentColor;
}
.panel-foot {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
min-height: 35px;
padding: 9px 20px;
border-top: 1px solid rgba(160, 218, 255, 0.1);
color: #71889a;
font-size: 10px;
line-height: 1.35;
background: rgba(0, 0, 0, 0.11);
}
.panel-foot strong {
color: #a8bdcc;
font-weight: 650;
}
#status {
color: #9fb5c5;
text-align: right;
}
@media (max-width: 820px) {
.model-note {
display: none;
}
.panel-grid {
grid-template-columns: 1fr;
}
.results {
display: none;
}
.scene-caption {
display: none;
}
.tank-tag {
display: none;
}
}
@media (max-width: 560px) {
.header {
top: 17px;
left: 18px;
width: calc(100vw - 36px);
}
h1 {
max-width: 320px;
font-size: 27px;
}
.subtitle {
max-width: 315px;
font-size: 11px;
}
.controls {
bottom: 9px;
width: calc(100vw - 18px);
border-radius: 16px;
}
.addition {
padding: 14px;
}
.panel-foot {
padding: 8px 14px;
font-size: 9px;
}
.panel-foot > span {
max-width: 48%;
}
.mode-toggle button {
padding: 6px 8px;
}
.primary,
.secondary {
padding: 10px 12px;
}
}
@media (prefers-reduced-motion: reduce) {
button {
transition: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive 3D cutaway comparing two abstract buffer-capacity models"
></canvas>
<div class="vignette"></div>
<header class="header">
<div class="eyebrow">Matched-pH cutaway study</div>
<h1>Same starting point.<br />Different reserve.</h1>
<p class="subtitle">
Two explicitly simplified models begin at the same pH. Apply one identical
symbolic addition to both and compare how far each model moves.
</p>
</header>
<aside class="model-note">
<div class="note-title">Illustrative response law</div>
<div class="equation">
pH(u) = 7.00 + sgn(u) log<sub>10</sub>(1 + |u|/β)
</div>
<div class="beta-list">
<span><i></i>Low capacity: β = 0.08</span>
<span><i></i>High capacity: β = 0.30</span>
</div>
<p>
A deliberately symmetric, non-quantitative visualization law. The dose
<strong>u</strong> is dimensionless; vessel marks are schematic. No reagent
quantities, preparation steps, or mixing procedure are represented.
</p>
</aside>
<div id="tagLow" class="tank-tag">
<span>LOW CAPACITY · β 0.08</span>
<div class="tag-reading">
<strong id="tagPhLow">7.00</strong><small>pH</small>
</div>
<em id="tagDeltaLow">Δ 0.000</em>
</div>
<div id="tagHigh" class="tank-tag high">
<span>HIGH CAPACITY · β 0.30</span>
<div class="tag-reading">
<strong id="tagPhHigh">7.00</strong><small>pH</small>
</div>
<em id="tagDeltaHigh">Δ 0.000</em>
</div>
<div class="scene-caption">
<strong>3D section view</strong><br />
Front walls intentionally omitted · internal marks are abstract<br />
Drag to orbit · wheel to zoom · double-click to reset view
</div>
<section class="controls" aria-label="Symbolic addition controls">
<div class="panel-grid">
<div class="addition">
<div class="panel-heading">
<span>Symbolic addition</span>
<div class="mode-toggle" role="group" aria-label="Addition direction">
<button type="button" data-mode="base" class="active">
Base direction (+u)
</button>
<button type="button" data-mode="acid">
Acid direction (−u)
</button>
</div>
</div>
<label class="slider-label" for="doseSlider">
<span>Magnitude of one shared dose</span>
<output id="doseValue" for="doseSlider">0.12 u</output>
</label>
<input
id="doseSlider"
type="range"
min="0.02"
max="0.24"
step="0.01"
value="0.12"
aria-label="Symbolic addition magnitude"
/>
<div class="scale">
<span>0.02</span>
<span>dimensionless symbolic units</span>
<span>0.24</span>
</div>
<div class="buttons">
<button id="apply" type="button" class="primary">
Apply +u to both models
</button>
<button id="reset" type="button" class="secondary">Reset</button>
</div>
</div>
<div class="results">
<div class="panel-heading results-heading">
<span>Live response</span>
<span id="separation" class="separation">separation 0.00</span>
</div>
<div class="model-row">
<div class="model-name">
<i class="model-dot"></i>
<span>
LOW CAPACITY
<small>β = 0.08</small>
</span>
</div>
<div class="reading">
<strong id="summaryPhLow">7.00</strong>
<span id="summaryDeltaLow">Δ 0.000</span>
</div>
<div class="response-track"><i id="barLow"></i></div>
</div>
<div class="model-row">
<div class="model-name">
<i class="model-dot high"></i>
<span>
HIGH CAPACITY
<small>β = 0.30</small>
</span>
</div>
<div class="reading">
<strong id="summaryPhHigh">7.00</strong>
<span id="summaryDeltaHigh">Δ 0.000</span>
</div>
<div class="response-track"><i id="barHigh"></i></div>
</div>
</div>
</div>
<div class="panel-foot">
<span>
<strong>Abstract comparison only.</strong>
Tokens indicate a symbolic addition, not a chemical substance.
</span>
<span id="status" aria-live="polite">
Ready — both models begin at pH 7.00.
</span>
</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// State and deliberately simplified response model
// ------------------------------------------------------------
const INITIAL_PH = 7.0;
const models = [
{
id: "low",
name: "LOW CAPACITY",
beta: 0.08,
x: -1.85,
markCount: 6
},
{
id: "high",
name: "HIGH CAPACITY",
beta: 0.30,
x: 1.85,
markCount: 18
}
];
const state = {
mode: "base",
magnitude: 0.12,
dose: 0,
animating: false,
animation: null
};
const reducedMotion =
window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function responsePH(dose, beta) {
const magnitude = Math.abs(dose);
if (magnitude < 1e-9) return INITIAL_PH;
return (
INITIAL_PH +
Math.sign(dose) * Math.log10(1 + magnitude / beta)
);
}
const acidColor = new THREE.Color(0xff617a);
const neutralColor = new THREE.Color(0x36d9bd);
const baseColor = new THREE.Color(0x648dff);
const whiteColor = new THREE.Color(0xffffff);
function colorForPH(ph) {
if (ph <= INITIAL_PH) {
const t = THREE.MathUtils.clamp((ph - 6.4) / 0.6, 0, 1);
return acidColor.clone().lerp(neutralColor, t);
}
const t = THREE.MathUtils.clamp((ph - 7.0) / 0.6, 0, 1);
return neutralColor.clone().lerp(baseColor, t);
}
// ------------------------------------------------------------
// Renderer, camera, and scene
// ------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x07111f, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07111f, 0.027);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
60
);
const sceneRoot = new THREE.Group();
scene.add(sceneRoot);
const hemisphere = new THREE.HemisphereLight(0xbfe9ff, 0x07101c, 1.5);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xd9f5ff, 2.8);
keyLight.position.set(-4, 7, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -3;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x5b79ff, 2.0);
rimLight.position.set(5, 3, -4);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0x07111e,
roughness: 0.92,
metalness: 0.08,
transparent: true,
opacity: 0.88
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.085;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 48, 0x31506a, 0x172d42);
grid.position.y = -0.078;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
const backdrop = new THREE.Mesh(
new THREE.CircleGeometry(4.7, 96),
new THREE.MeshBasicMaterial({
color: 0x0d2035,
transparent: true,
opacity: 0.5,
depthWrite: false
})
);
backdrop.position.set(0, 1.35, -2.55);
scene.add(backdrop);
const backdropRing = new THREE.Mesh(
new THREE.TorusGeometry(4.25, 0.012, 8, 128),
new THREE.MeshBasicMaterial({
color: 0x5eead4,
transparent: true,
opacity: 0.17
})
);
backdropRing.position.set(0, 1.35, -2.5);
scene.add(backdropRing);
// ------------------------------------------------------------
// Custom camera controls: orbit, zoom, and reset
// ------------------------------------------------------------
const cameraState = {
theta: 0.14,
phi: 1.18,
radius: window.innerWidth < 700 ? 14.0 : 8.8,
target: new THREE.Vector3(0, 1.22, 0),
dragging: false,
pointerX: 0,
pointerY: 0,
userAdjusted: false
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.theta = 0.14;
cameraState.phi = 1.18;
cameraState.radius = window.innerWidth < 700 ? 14.0 : 8.8;
cameraState.userAdjusted = false;
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) return;
cameraState.dragging = true;
cameraState.pointerX = event.clientX;
cameraState.pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!cameraState.dragging) return;
const dx = event.clientX - cameraState.pointerX;
const dy = event.clientY - cameraState.pointerY;
cameraState.pointerX = event.clientX;
cameraState.pointerY = event.clientY;
cameraState.theta = THREE.MathUtils.clamp(
cameraState.theta - dx * 0.005,
-0.78,
0.78
);
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.0045,
0.82,
1.42
);
cameraState.userAdjusted = true;
});
function endDrag(event) {
cameraState.dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
6.8,
16.5
);
cameraState.userAdjusted = true;
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
// ------------------------------------------------------------
// Tank construction
// ------------------------------------------------------------
const tankGeometry = {
bottom: new THREE.BoxGeometry(2.32, 0.14, 1.9),
back: new THREE.BoxGeometry(2.32, 2.3, 0.065),
side: new THREE.BoxGeometry(0.065, 2.3, 1.82),
sill: new THREE.BoxGeometry(2.32, 0.09, 0.09),
cutBeam: new THREE.BoxGeometry(0.035, 2.26, 0.035)
};
function makeTank(model) {
const root = new THREE.Group();
root.position.x = model.x;
sceneRoot.add(root);
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(1.48, 1.58, 0.16, 64),
new THREE.MeshStandardMaterial({
color: 0x0a1625,
metalness: 0.55,
roughness: 0.42
})
);
pedestal.position.y = 0.01;
pedestal.receiveShadow = true;
root.add(pedestal);
const groundGlow = new THREE.Mesh(
new THREE.CircleGeometry(1.43, 64),
new THREE.MeshBasicMaterial({
color: model.id === "low" ? 0x5eead4 : 0x668fff,
transparent: true,
opacity: 0.065,
depthWrite: false
})
);
groundGlow.rotation.x = -Math.PI / 2;
groundGlow.position.y = 0.095;
root.add(groundGlow);
const wallMaterial = new THREE.MeshPhysicalMaterial({
color: 0xbcecff,
transparent: true,
opacity: 0.14,
roughness: 0.16,
metalness: 0.12,
side: THREE.DoubleSide,
depthWrite: false
});
const cutMaterial = new THREE.MeshStandardMaterial({
color: 0x91f4e2,
emissive: 0x1b8e86,
emissiveIntensity: 1.25,
roughness: 0.3,
metalness: 0.25
});
const bottom = new THREE.Mesh(
tankGeometry.bottom,
new THREE.MeshPhysicalMaterial({
color: 0xa9d8ec,
transparent: true,
opacity: 0.2,
roughness: 0.2,
metalness: 0.1,
depthWrite: false
})
);
bottom.position.set(0, 0.22, 0);
root.add(bottom);
const back = new THREE.Mesh(tankGeometry.back, wallMaterial);
back.position.set(0, 1.37, -0.89);
root.add(back);
const left = new THREE.Mesh(tankGeometry.side, wallMaterial);
left.position.set(-1.13, 1.37, 0);
root.add(left);
const right = new THREE.Mesh(tankGeometry.side, wallMaterial);
right.position.set(1.13, 1.37, 0);
root.add(right);
const sill = new THREE.Mesh(tankGeometry.sill, cutMaterial);
sill.position.set(0, 0.29, 0.91);
root.add(sill);
const leftCut = new THREE.Mesh(tankGeometry.cutBeam, cutMaterial);
leftCut.position.set(-1.13, 1.38, 0.91);
root.add(leftCut);
const rightCut = new THREE.Mesh(tankGeometry.cutBeam, cutMaterial);
rightCut.position.set(1.13, 1.38, 0.91);
root.add(rightCut);
const rimPoints = [
new THREE.Vector3(-1.13, 2.52, -0.89),
new THREE.Vector3(1.13, 2.52, -0.89),
new THREE.Vector3(1.13, 2.52, 0.91),
new THREE.Vector3(-1.13, 2.52, 0.91),
new THREE.Vector3(-1.13, 2.52, -0.89)
];
const rim = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(rimPoints),
new THREE.LineBasicMaterial({
color: 0x8de8e0,
transparent: true,
opacity: 0.65
})
);
root.add(rim);
const liquidHeight = 1.72;
const liquidMaterial = new THREE.MeshPhysicalMaterial({
color: neutralColor,
emissive: neutralColor.clone().multiplyScalar(0.16),
emissiveIntensity: 0.55,
transparent: true,
opacity: 0.58,
roughness: 0.2,
metalness: 0,
side: THREE.DoubleSide,
depthWrite: false
});
const liquid = new THREE.Mesh(
new THREE.BoxGeometry(2.1, liquidHeight, 1.62),
liquidMaterial
);
liquid.position.set(0, 0.29 + liquidHeight / 2, 0.035);
liquid.renderOrder = 1;
root.add(liquid);
const surfaceMaterial = new THREE.MeshBasicMaterial({
color: neutralColor,
transparent: true,
opacity: 0.66,
side: THREE.DoubleSide,
depthWrite: false
});
const surface = new THREE.Mesh(
new THREE.PlaneGeometry(2.1, 1.62),
surfaceMaterial
);
surface.rotation.x = -Math.PI / 2;
surface.position.set(0, 0.29 + liquidHeight, 0.035);
surface.renderOrder = 2;
root.add(surface);
// Abstract capacity marks: intentionally not molecular symbols.
const markMaterial = new THREE.MeshStandardMaterial({
color: 0xdffff8,
emissive:
model.id === "low" ? 0x35bfa9 : 0x587bff,
emissiveIntensity: 1.45,
roughness: 0.28,
metalness: 0.05
});
const marks = [];
const columns = model.id === "low" ? 3 : 6;
const rows = model.id === "low" ? 2 : 3;
for (let i = 0; i < model.markCount; i++) {
const column = i % columns;
const row = Math.floor(i / columns);
const mark = new THREE.Mesh(
new THREE.SphereGeometry(
model.id === "low" ? 0.054 : 0.047,
12,
12
),
markMaterial
);
const xSpread =
columns === 3 ? 0.5 : 0.78;
mark.position.set(
-xSpread + (column / Math.max(1, columns - 1)) * xSpread * 2,
0.67 + row * 0.48,
-0.76
);
marks.push(mark);
root.add(mark);
}
// A small vertical response gauge.
const gaugeTrack = new THREE.Mesh(
new THREE.BoxGeometry(0.022, 1.45, 0.022),
new THREE.MeshBasicMaterial({
color: 0x7590a5,
transparent: true,
opacity: 0.55
})
);
gaugeTrack.position.set(1.37, 1.42, -0.48);
root.add(gaugeTrack);
const neutralTick = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.018, 0.022),
new THREE.MeshBasicMaterial({ color: 0xd9efff })
);
neutralTick.position.set(1.37, 1.42, -0.48);
root.add(neutralTick);
const gaugeMaterial = new THREE.MeshBasicMaterial({
color: neutralColor
});
const gaugeMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.064, 18, 18),
gaugeMaterial
);
gaugeMarker.position.set(1.37, 1.42, -0.48);
root.add(gaugeMarker);
// Symbolic floating +/− marker.
const marker = new THREE.Group();
marker.position.set(0, 3.02, 0);
root.add(marker);
const markerMaterial = new THREE.MeshStandardMaterial({
color: baseColor,
emissive: baseColor,
emissiveIntensity: 1.6,
roughness: 0.3
});
const markerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.235, 0.018, 8, 48),
markerMaterial
);
marker.add(markerRing);
const plus = new THREE.Group();
const plusVertical = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.24, 0.035),
markerMaterial
);
const plusHorizontal = new THREE.Mesh(
new THREE.BoxGeometry(0.24, 0.035, 0.035),
markerMaterial
);
plus.add(plusVertical, plusHorizontal);
marker.add(plus);
const minus = new THREE.Mesh(
new THREE.BoxGeometry(0.24, 0.035, 0.035),
markerMaterial
);
minus.visible = false;
marker.add(minus);
// Falling symbolic tokens.
const tokenMaterial = new THREE.MeshStandardMaterial({
color: baseColor,
emissive: baseColor,
emissiveIntensity: 1.8,
transparent: true,
opacity: 0.95,
roughness: 0.25
});
const tokens = [];
for (let i = 0; i < 6; i++) {
const token = new THREE.Mesh(
new THREE.OctahedronGeometry(0.085, 0),
tokenMaterial.clone()
);
token.visible = false;
token.userData.offsetX = (i - 2.5) * 0.15;
token.userData.phase = i * 0.075;
tokens.push(token);
root.add(token);
}
// Surface ripple rings.
const ripples = [];
for (let i = 0; i < 3; i++) {
const ripple = new THREE.Mesh(
new THREE.RingGeometry(0.12, 0.145, 64),
new THREE.MeshBasicMaterial({
color: neutralColor,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthWrite: false
})
);
ripple.rotation.x = -Math.PI / 2;
ripple.position.set(0, 0.29 + liquidHeight + 0.012, 0.035);
ripple.scale.setScalar(0.2);
ripples.push(ripple);
root.add(ripple);
}
const localLight = new THREE.PointLight(
neutralColor,
4.5,
4.8,
2
);
localLight.position.set(0, 1.25, 0.25);
root.add(localLight);
const labelAnchor = new THREE.Object3D();
labelAnchor.position.set(0, 3.35, 0);
root.add(labelAnchor);
Object.assign(model, {
root,
liquid,
liquidMaterial,
surface,
surfaceMaterial,
gaugeMarker,
gaugeMaterial,
marker,
markerRing,
markerMaterial,
plus,
minus,
tokens,
ripples,
localLight,
labelAnchor,
ph: INITIAL_PH,
delta: 0
});
}
models.forEach(makeTank);
// ------------------------------------------------------------
// DOM updates
// ------------------------------------------------------------
const ui = {
slider: document.querySelector("#doseSlider"),
doseValue: document.querySelector("#doseValue"),
apply: document.querySelector("#apply"),
reset: document.querySelector("#reset"),
status: document.querySelector("#status"),
separation: document.querySelector("#separation"),
modeButtons: [...document.querySelectorAll("[data-mode]")],
tagPhLow: document.querySelector("#tagPhLow"),
tagPhHigh: document.querySelector("#tagPhHigh"),
tagDeltaLow: document.querySelector("#tagDeltaLow"),
tagDeltaHigh: document.querySelector("#tagDeltaHigh"),
summaryPhLow: document.querySelector("#summaryPhLow"),
summaryPhHigh: document.querySelector("#summaryPhHigh"),
summaryDeltaLow: document.querySelector("#summaryDeltaLow"),
summaryDeltaHigh: document.querySelector("#summaryDeltaHigh"),
barLow: document.querySelector("#barLow"),
barHigh: document.querySelector("#barHigh")
};
function signed(value, digits = 3) {
const safe = Math.abs(value) < 0.0005 ? 0 : value;
return `${safe >= 0 ? "+" : ""}${safe.toFixed(digits)}`;
}
function setResponseBar(element, delta, color) {
const fraction = THREE.MathUtils.clamp(
Math.abs(delta) / 0.6,
0,
1
);
const width = fraction * 50;
element.style.background = `#${color.getHexString()}`;
element.style.width = `${width}%`;
if (delta >= 0) {
element.style.left = "50%";
element.style.right = "auto";
} else {
element.style.right = "50%";
element.style.left = "auto";
}
}
function updateModels() {
for (const model of models) {
model.ph = responsePH(state.dose, model.beta);
model.delta = model.ph - INITIAL_PH;
const color = colorForPH(model.ph);
model.liquidMaterial.color.copy(color);
model.liquidMaterial.emissive.copy(color).multiplyScalar(0.15);
model.surfaceMaterial.color.copy(color).lerp(whiteColor, 0.13);
model.gaugeMaterial.color.copy(color);
model.localLight.color.copy(color);
model.gaugeMarker.position.y =
1.42 + THREE.MathUtils.clamp(model.delta, -0.6, 0.6) * 1.15;
for (const ripple of model.ripples) {
ripple.material.color.copy(color);
}
}
const low = models[0];
const high = models[1];
ui.tagPhLow.textContent = low.ph.toFixed(2);
ui.tagPhHigh.textContent = high.ph.toFixed(2);
ui.tagDeltaLow.textContent = `Δ ${signed(low.delta)}`;
ui.tagDeltaHigh.textContent = `Δ ${signed(high.delta)}`;
ui.summaryPhLow.textContent = low.ph.toFixed(2);
ui.summaryPhHigh.textContent = high.ph.toFixed(2);
ui.summaryDeltaLow.textContent = `Δ ${signed(low.delta)}`;
ui.summaryDeltaHigh.textContent = `Δ ${signed(high.delta)}`;
setResponseBar(
ui.barLow,
low.delta,
colorForPH(low.ph)
);
setResponseBar(
ui.barHigh,
high.delta,
colorForPH(high.ph)
);
const separation = Math.abs(low.ph - high.ph);
ui.separation.textContent = `separation ${separation.toFixed(2)}`;
}
function updateModeAppearance() {
const isBase = state.mode === "base";
const color = isBase ? baseColor : acidColor;
const sign = isBase ? "+" : "−";
for (const model of models) {
model.plus.visible = isBase;
model.minus.visible = !isBase;
model.markerMaterial.color.copy(color);
model.markerMaterial.emissive.copy(color);
for (const token of model.tokens) {
token.material.color.copy(color);
token.material.emissive.copy(color);
}
}
ui.apply.textContent = `Apply ${sign}u to both models`;
ui.modeButtons.forEach((button) => {
button.classList.toggle("active", button.dataset.mode === state.mode);
});
}
// ------------------------------------------------------------
// Interaction
// ------------------------------------------------------------
ui.slider.addEventListener("input", () => {
state.magnitude = Number(ui.slider.value);
ui.doseValue.textContent = `${state.magnitude.toFixed(2)} u`;
});
ui.modeButtons.forEach((button) => {
button.addEventListener("click", () => {
state.mode = button.dataset.mode;
updateModeAppearance();
ui.status.textContent =
state.mode === "base"
? "Base direction selected — press apply to send the same +u to both."
: "Acid direction selected — press apply to send the same −u to both.";
});
});
ui.apply.addEventListener("click", () => {
const target =
state.mode === "base" ? state.magnitude : -state.magnitude;
state.animation = {
start: performance.now(),
from: state.dose,
to: target,
duration: reducedMotion ? 260 : 1450
};
state.animating = true;
for (const model of models) {
for (const token of model.tokens) {
token.visible = true;
token.position.set(
token.userData.offsetX,
3.05,
0
);
token.scale.setScalar(1);
}
}
ui.status.textContent =
`Applying the same ${target >= 0 ? "+" : "−"}${state.magnitude.toFixed(2)} u to both models…`;
});
ui.reset.addEventListener("click", () => {
state.dose = 0;
state.animating = false;
state.animation = null;
for (const model of models) {
for (const token of model.tokens) {
token.visible = false;
}
for (const ripple of model.ripples) {
ripple.material.opacity = 0;
ripple.scale.setScalar(0.2);
}
}
updateModels();
ui.status.textContent =
"Reset — both models again begin at pH 7.00.";
});
// ------------------------------------------------------------
// Responsive sizing
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
const mobile = width < 700;
sceneRoot.scale.setScalar(mobile ? 0.76 : 1);
if (!cameraState.userAdjusted) {
cameraState.radius = mobile ? 14.0 : 8.8;
cameraState.theta = mobile ? 0.08 : 0.14;
cameraState.phi = mobile ? 1.16 : 1.18;
}
updateCamera();
}
window.addEventListener("resize", resize);
// ------------------------------------------------------------
// Animation and projected labels
// ------------------------------------------------------------
const projected = new THREE.Vector3();
function updateProjectedTag(element, anchor) {
anchor.getWorldPosition(projected);
projected.project(camera);
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`;
element.style.opacity =
projected.z > -1 && projected.z < 1 ? "1" : "0";
}
function updateTokenAndRippleAnimation(progress, time) {
for (const model of models) {
model.tokens.forEach((token, index) => {
const start = token.userData.phase;
const local = THREE.MathUtils.clamp(
(progress - start) / Math.max(0.001, 1 - start),
0,
1
);
if (progress <= 1 && local < 1) {
token.visible = true;
token.position.y = 3.05 - local * 1.08;
token.position.x =
token.userData.offsetX +
Math.sin(local * Math.PI) * 0.06;
token.rotation.y = local * Math.PI * 2;
token.rotation.x = local * Math.PI;
token.material.opacity = 1 - local * 0.35;
token.scale.setScalar(
0.75 + Math.sin(local * Math.PI) * 0.35
);
} else {
token.visible = false;
}
});
model.ripples.forEach((ripple, index) => {
const life = THREE.MathUtils.clamp(
(progress - 0.62 - index * 0.07) / 0.38,
0,
1
);
if (life > 0 && life < 1) {
const scale = 0.4 + life * 3.8;
ripple.scale.setScalar(scale);
ripple.material.opacity =
Math.sin(life * Math.PI) * 0.65;
} else {
ripple.material.opacity = 0;
}
});
model.marker.rotation.y = time * 0.55;
const pulse = 1 + Math.sin(time * 2.1 + model.x) * 0.035;
model.marker.scale.setScalar(pulse);
}
}
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const time = now * 0.001;
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (state.animating && state.animation) {
const raw = THREE.MathUtils.clamp(
(now - state.animation.start) /
state.animation.duration,
0,
1
);
const eased = 1 - Math.pow(1 - raw, 3);
state.dose = THREE.MathUtils.lerp(
state.animation.from,
state.animation.to,
eased
);
updateModels();
updateTokenAndRippleAnimation(raw, time);
if (raw >= 1) {
state.animating = false;
const separation = Math.abs(
responsePH(state.dose, models[0].beta) -
responsePH(state.dose, models[1].beta)
);
ui.status.textContent =
`Same ${state.dose >= 0 ? "+" : "−"}${state.magnitude.toFixed(2)} u applied · ` +
`response separation ${separation.toFixed(2)} pH units.`;
}
} else {
updateTokenAndRippleAnimation(0, time);
}
// A very slight, non-quantitative surface movement.
for (const model of models) {
model.surface.position.y =
2.01 + Math.sin(time * 1.4 + model.x) * 0.006;
}
updateCamera();
scene.updateMatrixWorld();
camera.updateMatrixWorld();
updateProjectedTag(
document.querySelector("#tagLow"),
models[0].labelAnchor
);
updateProjectedTag(
document.querySelector("#tagHigh"),
models[1].labelAnchor
);
renderer.render(scene, camera);
}
updateModeAppearance();
updateModels();
resize();
requestAnimationFrame(animate);
</script>
</body>
</html>
```