Prompt specification
Build or customize the Three.js 3D scene "Juice dilution ratio classroom scene" 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: Juice dilution ratio classroom scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/juice-dilution-ratio-classroom-scene-x1995
Scene Description Prompt:
Compose fictional colored drinks with clearly synthetic concentration values and measuring markers; connect dilution to ratios without claiming color intensity always measures real concentration. Use Three.js from cdnjs in a single HTML file, with visible voxel blocks.
Working Three.js Starter (juice-dilution-ratio-classroom-scene-x1995):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Drink Lab — Synthetic Dilution Model</title>
<style>
:root {
color-scheme: dark;
--bg: #071018;
--panel: rgba(13, 25, 35, 0.88);
--panel-soft: rgba(18, 36, 48, 0.72);
--line: rgba(151, 205, 224, 0.17);
--text: #e7f5fb;
--muted: #8faebb;
--cyan: #79e7f7;
--lime: #b8f57b;
--pink: #ff8ad8;
--amber: #ffc56e;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
display: grid;
grid-template-columns: 310px minmax(420px, 1fr) 320px;
grid-template-rows: 72px minmax(0, 1fr);
width: 100vw;
height: 100vh;
}
header {
grid-column: 1 / -1;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 24px;
border-bottom: 1px solid var(--line);
background: rgba(5, 12, 18, 0.94);
z-index: 20;
}
.brand {
display: flex;
align-items: center;
gap: 14px;
min-width: 0;
}
.brand-mark {
display: grid;
grid-template-columns: repeat(3, 7px);
grid-template-rows: repeat(3, 7px);
gap: 3px;
flex: 0 0 auto;
}
.brand-mark i {
display: block;
border-radius: 1px;
background: var(--cyan);
box-shadow: 0 0 12px rgba(121, 231, 247, 0.22);
}
.brand-mark i:nth-child(3),
.brand-mark i:nth-child(7) {
background: var(--pink);
}
.brand-mark i:nth-child(5),
.brand-mark i:nth-child(9) {
background: var(--amber);
}
h1 {
margin: 0;
font-size: 17px;
line-height: 1.2;
letter-spacing: 0.02em;
}
.subtitle {
margin-top: 4px;
color: var(--muted);
font-size: 12px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.synthetic-badge {
flex: 0 0 auto;
padding: 8px 11px;
border: 1px solid rgba(184, 245, 123, 0.35);
border-radius: 999px;
color: var(--lime);
background: rgba(184, 245, 123, 0.07);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
aside {
min-height: 0;
overflow-y: auto;
padding: 20px;
background: var(--panel);
backdrop-filter: blur(14px);
scrollbar-width: thin;
scrollbar-color: #2c4d60 transparent;
z-index: 10;
}
.controls {
border-right: 1px solid var(--line);
}
.readout {
border-left: 1px solid var(--line);
}
.section {
margin-bottom: 23px;
padding-bottom: 23px;
border-bottom: 1px solid var(--line);
}
.section:last-child {
margin-bottom: 0;
border-bottom: 0;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 14px;
color: #cfe8f2;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.section-title small {
color: var(--muted);
font-size: 9px;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: none;
}
.control {
margin-bottom: 16px;
}
.control:last-child {
margin-bottom: 0;
}
.control-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
}
.control label {
color: #c9dfe8;
font-size: 12px;
}
.control output {
color: var(--text);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
font-weight: 700;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 6px 0 2px;
appearance: none;
border-radius: 99px;
outline: none;
background: linear-gradient(
90deg,
rgba(121, 231, 247, 0.78),
rgba(121, 231, 247, 0.14)
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
appearance: none;
border: 2px solid #dffaff;
border-radius: 3px;
background: #163746;
box-shadow: 0 0 0 4px rgba(121, 231, 247, 0.08);
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border: 2px solid #dffaff;
border-radius: 3px;
background: #163746;
box-shadow: 0 0 0 4px rgba(121, 231, 247, 0.08);
}
.hint {
margin: 7px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.ratio-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
}
.ratio-grid button,
.preset-grid button,
.secondary-button {
min-height: 36px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.ratio-grid button:hover,
.preset-grid button:hover,
.secondary-button:hover {
border-color: rgba(121, 231, 247, 0.48);
background: rgba(121, 231, 247, 0.09);
}
.ratio-grid button:active,
.preset-grid button:active,
.secondary-button:active {
transform: translateY(1px);
}
.ratio-grid button[aria-pressed="true"] {
border-color: var(--cyan);
background: rgba(121, 231, 247, 0.15);
color: #e8fcff;
}
.ratio-grid button span {
display: block;
font-size: 12px;
font-weight: 800;
}
.ratio-grid button small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
}
.preset-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.preset-grid button {
padding: 8px;
text-align: left;
font-size: 10px;
}
.preset-grid i {
display: inline-block;
width: 8px;
height: 8px;
margin-right: 6px;
border-radius: 2px;
vertical-align: 1px;
}
.secondary-button {
width: 100%;
padding: 8px 12px;
font-size: 11px;
font-weight: 700;
}
.swatch-card {
display: flex;
align-items: center;
gap: 12px;
margin-top: 12px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(0, 0, 0, 0.12);
}
#recipeSwatch {
width: 40px;
height: 40px;
flex: 0 0 auto;
border: 1px solid rgba(255, 255, 255, 0.25);
border-radius: 9px;
box-shadow:
inset 0 0 15px rgba(255, 255, 255, 0.09),
0 0 22px rgba(121, 231, 247, 0.08);
}
.swatch-card strong {
display: block;
font-size: 12px;
}
.swatch-card small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.warning {
padding: 12px;
border: 1px solid rgba(255, 197, 110, 0.26);
border-radius: 10px;
background: rgba(255, 197, 110, 0.065);
color: #e7d4b6;
font-size: 10px;
line-height: 1.5;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
isolation: isolate;
background:
radial-gradient(circle at 50% 40%, rgba(24, 59, 75, 0.55), transparent 48%),
linear-gradient(180deg, #08141d, #050b11);
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#viewport canvas:active {
cursor: grabbing;
}
.stage-heading {
position: absolute;
top: 18px;
left: 20px;
z-index: 4;
pointer-events: none;
}
.stage-heading strong {
display: block;
font-size: 10px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.stage-heading span {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 10px;
}
.camera-tools {
position: absolute;
top: 15px;
right: 15px;
z-index: 5;
display: flex;
gap: 7px;
}
.camera-tools button {
min-height: 32px;
padding: 0 10px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(7, 18, 27, 0.74);
color: #cfe8f2;
font-size: 10px;
cursor: pointer;
backdrop-filter: blur(8px);
}
.camera-tools button:hover {
border-color: rgba(121, 231, 247, 0.5);
}
.scene-label {
position: absolute;
z-index: 3;
min-width: 150px;
padding: 10px 12px;
border: 1px solid rgba(152, 220, 239, 0.27);
border-radius: 10px;
background: rgba(6, 15, 23, 0.78);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
text-align: center;
pointer-events: none;
transform: translate(-50%, -100%);
backdrop-filter: blur(8px);
}
.scene-label span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.scene-label strong {
display: block;
margin: 4px 0 2px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 16px;
}
.scene-label small {
display: block;
color: #adc7d2;
font-size: 9px;
}
#ratioLabel {
min-width: 138px;
padding: 7px 10px;
border-color: rgba(184, 245, 123, 0.26);
}
#ratioLabel strong {
color: var(--lime);
font-size: 12px;
}
.stage-legend {
position: absolute;
right: 18px;
bottom: 17px;
left: 18px;
z-index: 4;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(6, 15, 23, 0.68);
color: var(--muted);
font-size: 9px;
line-height: 1.45;
pointer-events: none;
backdrop-filter: blur(8px);
}
.stage-legend b {
color: #d7edf5;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
min-height: 78px;
padding: 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--panel-soft);
}
.metric span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 7px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 16px;
}
.metric small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
}
.equation {
margin-top: 10px;
padding: 11px 12px;
border-left: 2px solid var(--cyan);
background: rgba(121, 231, 247, 0.055);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
line-height: 1.65;
}
.equation + .equation {
border-left-color: var(--lime);
background: rgba(184, 245, 123, 0.045);
}
.formula-list {
display: grid;
gap: 8px;
}
.formula-list div {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.025);
}
.formula-list code {
color: #d9f3fb;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
}
.formula-list span {
color: var(--muted);
font-size: 9px;
}
.assumption {
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.assumption strong {
color: #d8edf5;
}
@media (max-width: 1120px) {
body {
overflow: auto;
}
#app {
grid-template-columns: 290px minmax(420px, 1fr);
grid-template-rows: 72px 720px auto;
}
.readout {
grid-column: 1 / -1;
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 22px;
border-top: 1px solid var(--line);
border-left: 0;
}
.readout .section {
margin: 0;
padding: 0;
border: 0;
}
}
@media (max-width: 740px) {
#app {
display: block;
height: auto;
}
header {
min-height: 72px;
padding: 0 15px;
}
.subtitle {
display: none;
}
.synthetic-badge {
font-size: 8px;
}
aside {
overflow: visible;
border: 0;
}
.controls {
border-bottom: 1px solid var(--line);
}
#stage {
height: 650px;
}
.readout {
display: block;
}
.readout .section {
margin-bottom: 22px;
padding-bottom: 22px;
border-bottom: 1px solid var(--line);
}
.stage-legend {
align-items: flex-start;
flex-direction: column;
gap: 3px;
}
.scene-label {
min-width: 125px;
padding: 8px;
}
.scene-label strong {
font-size: 13px;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i>
<i></i><i></i><i></i>
<i></i><i></i><i></i>
</div>
<div>
<h1>Voxel Drink Lab</h1>
<div class="subtitle">A fictional beverage composition and dilution model</div>
</div>
</div>
<div class="synthetic-badge">Synthetic model · not a real assay</div>
</header>
<aside class="panel controls">
<section class="section">
<div class="section-title">
Synthetic stock
<small>fictional units</small>
</div>
<div class="control">
<div class="control-row">
<label for="potency">Stock concentration C₁</label>
<output id="potencyOutput" for="potency">80 FU/mL</output>
</div>
<input
id="potency"
data-key="potency"
type="range"
min="20"
max="120"
step="5"
value="80"
>
<p class="hint">FU means fictional unit. It is not molarity, sugar percentage, ABV, or a safety measure.</p>
</div>
<div class="control">
<div class="control-row">
<label for="volume">Stock portion V₁</label>
<output id="volumeOutput" for="volume">10 mL</output>
</div>
<input
id="volume"
data-key="volume"
type="range"
min="5"
max="25"
step="1"
value="10"
>
</div>
</section>
<section class="section">
<div class="section-title">
Dilution ratio
<small>total parts R</small>
</div>
<div class="ratio-grid" role="group" aria-label="Dilution ratio">
<button type="button" data-ratio="1" aria-pressed="false">
<span>1:1</span><small>stock only</small>
</button>
<button type="button" data-ratio="2" aria-pressed="false">
<span>1:2</span><small>+ 1 water</small>
</button>
<button type="button" data-ratio="3" aria-pressed="false">
<span>1:3</span><small>+ 2 water</small>
</button>
<button type="button" data-ratio="4" aria-pressed="true">
<span>1:4</span><small>+ 3 water</small>
</button>
</div>
<p class="hint">
Here, 1:4 means one part stock plus three parts water, producing four total parts.
</p>
</section>
<section class="section">
<div class="section-title">
Display hue recipe
<small>not a concentration sensor</small>
</div>
<div class="preset-grid">
<button type="button" data-preset="cyan">
<i style="background:#18d8ef"></i>Cyan Comet
</button>
<button type="button" data-preset="violet">
<i style="background:#dc46dc"></i>Ultraviolet
</button>
<button type="button" data-preset="amber">
<i style="background:#ffad3e"></i>Solar Pop
</button>
<button type="button" data-preset="prism">
<i style="background:#a5d46f"></i>Prism Mix
</button>
</div>
<div class="control" style="margin-top:15px">
<div class="control-row">
<label for="cyan">Cyan recipe weight</label>
<output id="cyanOutput" for="cyan">70</output>
</div>
<input id="cyan" data-key="cyan" type="range" min="0" max="100" value="70">
</div>
<div class="control">
<div class="control-row">
<label for="magenta">Magenta recipe weight</label>
<output id="magentaOutput" for="magenta">25</output>
</div>
<input id="magenta" data-key="magenta" type="range" min="0" max="100" value="25">
</div>
<div class="control">
<div class="control-row">
<label for="amber">Amber recipe weight</label>
<output id="amberOutput" for="amber">10</output>
</div>
<input id="amber" data-key="amber" type="range" min="0" max="100" value="10">
</div>
<div class="swatch-card">
<div id="recipeSwatch"></div>
<div>
<strong id="recipeName">Cyan Comet</strong>
<small>
Decorative palette only. The stock and diluted drinks deliberately keep
the same hue.
</small>
</div>
</div>
<button id="randomRecipe" class="secondary-button" type="button" style="margin-top:10px">
Randomize display recipe
</button>
</section>
<section class="section">
<div class="warning">
<strong>Color is not treated as a concentration measurement.</strong>
Potency changes are communicated numerically. Dilution changes the modeled
FU/mL value and final volume without automatically changing color intensity.
</div>
</section>
</aside>
<main id="stage">
<div id="viewport"></div>
<div class="stage-heading">
<strong>Voxel mixing bench</strong>
<span>Drag to orbit · wheel to zoom · double-click to reset</span>
</div>
<div class="camera-tools">
<button id="resetCamera" type="button">Reset view</button>
</div>
<div id="stockLabel" class="scene-label">
<span>Stock vessel · 50 mL scale</span>
<strong id="stockSceneValue">80 FU/mL</strong>
<small id="stockSceneMeta">10 mL stock</small>
</div>
<div id="finalLabel" class="scene-label">
<span>Diluted vessel · 100 mL scale</span>
<strong id="finalSceneValue">20 FU/mL</strong>
<small id="finalSceneMeta">40 mL total · 30 mL water</small>
</div>
<div id="ratioLabel" class="scene-label">
<span>Dilution recipe</span>
<strong id="ratioSceneValue">1 stock + 3 water</strong>
</div>
<div class="stage-legend">
<span>
<b>Voxel fill is a schematic volume cue.</b>
Measuring rails show the fictional milliliter scales.
</span>
<span>
<b>FU/mL is synthetic.</b>
Color recipe and concentration are modeled independently.
</span>
</div>
</main>
<aside class="panel readout">
<section class="section">
<div class="section-title">
Concentration readout
<small>numeric model</small>
</div>
<div class="metric-grid">
<div class="metric">
<span>Stock C₁</span>
<strong id="c1Value">80 FU/mL</strong>
<small>before dilution</small>
</div>
<div class="metric">
<span>Diluted C₂</span>
<strong id="c2Value">20 FU/mL</strong>
<small>after dilution</small>
</div>
<div class="metric">
<span>Final volume</span>
<strong id="v2Value">40 mL</strong>
<small id="waterValue">30 mL water added</small>
</div>
<div class="metric">
<span>Total fictional units</span>
<strong id="totalValue">800 FU</strong>
<small>conserved in this model</small>
</div>
</div>
<div id="mixEquation" class="equation">
80 FU/mL × 10 mL = 800 FU
</div>
<div id="finalEquation" class="equation">
800 FU ÷ 40 mL = 20 FU/mL
</div>
</section>
<section class="section">
<div class="section-title">Ratio relationships</div>
<div class="formula-list">
<div>
<code>C₂ = C₁ ÷ R</code>
<span>final concentration</span>
</div>
<div>
<code>V₂ = V₁ × R</code>
<span>final volume</span>
</div>
<div>
<code>Vwater = V₁ × (R − 1)</code>
<span>added water</span>
</div>
</div>
<p class="hint" id="ratioDescription">
A 1:4 final mixture contains one part stock and three parts water.
</p>
</section>
<section class="section">
<div class="section-title">Model assumptions</div>
<p class="assumption">
<strong>FU</strong> is an invented unit for this fictional exercise.
The model assumes a single synthetic stock component, complete mixing,
additive volumes, and no loss of fictional units during dilution.
</p>
<p class="assumption">
The rendered colors are a decorative recipe. They do not claim that visual
brightness or saturation reliably measures real concentration.
</p>
</section>
</aside>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// State and model calculations
// -------------------------------------------------------------------------
const state = {
potency: 80,
volume: 10,
ratio: 4,
cyan: 70,
magenta: 25,
amber: 10,
recipeName: "Cyan Comet"
};
const $ = (id) => document.getElementById(id);
const clamp = THREE.MathUtils.clamp;
function formatNumber(value) {
return Number.isInteger(value) ? String(value) : value.toFixed(1);
}
function calculateModel() {
const c1 = state.potency;
const v1 = state.volume;
const r = state.ratio;
const v2 = v1 * r;
const water = v2 - v1;
const totalUnits = c1 * v1;
const c2 = totalUnits / v2;
return { c1, v1, r, v2, water, totalUnits, c2 };
}
function getRecipeRGB() {
const c = state.cyan / 100;
const m = state.magenta / 100;
const a = state.amber / 100;
const total = c + m + a;
if (total === 0) {
return { r: 150, g: 160, b: 165 };
}
// Normalize by total so overall recipe weight changes hue rather than
// pretending that "more recipe weight" means greater real concentration.
const r = (c * 0.04 + m * 0.88 + a * 1.00) / total;
const g = (c * 0.78 + m * 0.08 + a * 0.48) / total;
const b = (c * 0.92 + m * 0.62 + a * 0.08) / total;
return {
r: Math.round(clamp(r, 0, 1) * 255),
g: Math.round(clamp(g, 0, 1) * 255),
b: Math.round(clamp(b, 0, 1) * 255)
};
}
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const stage = $("stage");
const viewport = $("viewport");
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x071018, 0.028);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setClearColor(0x071018, 0);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D voxel mixing bench. Drag to orbit, use the mouse wheel to zoom."
);
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0x9ddfff, 0x081018, 1.75);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xe8f8ff, 3.2);
keyLight.position.set(4.5, 7, 5.5);
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 = -7;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x39dfff, 22, 9, 2);
cyanLight.position.set(3.2, 2.5, 2.4);
scene.add(cyanLight);
const pinkLight = new THREE.PointLight(0xff4fc8, 17, 8, 2);
pinkLight.position.set(-3.5, 2.4, -1.8);
scene.add(pinkLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0x071018,
roughness: 0.94,
metalness: 0.04
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.075;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 48, 0x315269, 0x122b39);
grid.position.y = -0.065;
grid.material.transparent = true;
grid.material.opacity = 0.48;
scene.add(grid);
const platform = new THREE.Mesh(
new THREE.BoxGeometry(5.7, 0.18, 2.65),
new THREE.MeshStandardMaterial({
color: 0x10222d,
roughness: 0.62,
metalness: 0.18
})
);
platform.position.set(0, 0.025, 0);
platform.castShadow = true;
platform.receiveShadow = true;
scene.add(platform);
const platformEdge = new THREE.LineSegments(
new THREE.EdgesGeometry(platform.geometry),
new THREE.LineBasicMaterial({
color: 0x31586c,
transparent: true,
opacity: 0.65
})
);
platformEdge.position.copy(platform.position);
scene.add(platformEdge);
function createTextSprite(text, color = "#9bc2d2", scale = 1) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 80;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "700 36px system-ui, sans-serif";
context.shadowColor = "rgba(0, 0, 0, 0.75)";
context.shadowBlur = 8;
context.fillStyle = color;
context.fillText(text, 128, 40);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
fog: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.25 * scale, 0.39 * scale, 1);
sprite.renderOrder = 5;
return sprite;
}
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xbceeff,
transparent: true,
opacity: 0.11,
roughness: 0.08,
metalness: 0,
transmission: 0.08,
thickness: 0.05,
side: THREE.DoubleSide,
depthWrite: false
});
const frameMaterial = new THREE.LineBasicMaterial({
color: 0x8bcddd,
transparent: true,
opacity: 0.48
});
const voxelGeometry = new THREE.BoxGeometry(0.205, 0.125, 0.205);
const voxelMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.28,
metalness: 0.04,
flatShading: true
});
const VOXEL_GRID = 5;
const VOXEL_LAYERS = 10;
const VOXEL_SPACING_XZ = 0.235;
const VOXEL_SPACING_Y = 0.145;
function createVessel({
x,
capacity,
markerStep,
markerSide,
label
}) {
const group = new THREE.Group();
group.position.set(x, 0.16, 0);
const width = 1.26;
const depth = 1.26;
const height = 1.86;
const baseY = 0.02;
const panelDefinitions = [
[width, height, 0.025, 0, baseY + height / 2, depth / 2],
[width, height, 0.025, 0, baseY + height / 2, -depth / 2],
[0.025, height, depth, width / 2, baseY + height / 2, 0],
[0.025, height, depth, -width / 2, baseY + height / 2, 0],
[width, 0.035, depth, 0, baseY, 0]
];
for (const [w, h, d, px, py, pz] of panelDefinitions) {
const panel = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
glassMaterial
);
panel.position.set(px, py, pz);
panel.renderOrder = 2;
group.add(panel);
}
const frame = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(width, height, depth)),
frameMaterial
);
frame.position.y = baseY + height / 2;
group.add(frame);
const voxelMesh = new THREE.InstancedMesh(
voxelGeometry,
voxelMaterial,
VOXEL_GRID * VOXEL_GRID * VOXEL_LAYERS
);
voxelMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
voxelMesh.castShadow = true;
voxelMesh.receiveShadow = true;
voxelMesh.frustumCulled = false;
group.add(voxelMesh);
const outerX = markerSide * (width / 2 + 0.13);
const markerZ = depth / 2 + 0.07;
const tickPositions = [
outerX,
baseY,
markerZ,
outerX,
baseY + height,
markerZ
];
for (let value = 0; value <= capacity; value += markerStep) {
const y = baseY + (value / capacity) * height;
const tickEnd = outerX + markerSide * 0.17;
tickPositions.push(
outerX, y, markerZ,
tickEnd, y, markerZ
);
const numberSprite = createTextSprite(
String(value),
value === 0 ? "#7f9eac" : "#b7d5df",
0.56
);
numberSprite.position.set(
outerX + markerSide * 0.31,
y,
markerZ
);
group.add(numberSprite);
}
const tickGeometry = new THREE.BufferGeometry();
tickGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(tickPositions, 3)
);
const ticks = new THREE.LineSegments(
tickGeometry,
new THREE.LineBasicMaterial({
color: 0x8fc5d4,
transparent: true,
opacity: 0.72
})
);
group.add(ticks);
const unitsSprite = createTextSprite("mL", "#8eb6c5", 0.62);
unitsSprite.position.set(
outerX + markerSide * 0.28,
baseY + height + 0.18,
markerZ
);
group.add(unitsSprite);
const capacitySprite = createTextSprite(
`${capacity} mL vessel`,
"#7899a7",
0.58
);
capacitySprite.position.set(0, baseY + height + 0.17, -depth / 2);
group.add(capacitySprite);
scene.add(group);
return {
group,
voxelMesh,
capacity,
baseY,
label
};
}
const stockVessel = createVessel({
x: -1.65,
capacity: 50,
markerStep: 10,
markerSide: -1,
label: "stock"
});
const finalVessel = createVessel({
x: 1.65,
capacity: 100,
markerStep: 20,
markerSide: 1,
label: "final"
});
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-0.82, 1.43, 0.68),
1.64,
0x8beaf3,
0.17,
0.11
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.72;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.85;
scene.add(arrow);
const matrix = new THREE.Matrix4();
const position = new THREE.Vector3();
const quaternion = new THREE.Quaternion();
const scale = new THREE.Vector3();
const instanceColor = new THREE.Color();
function updateVoxelMesh(vessel, volume, rgb) {
const normalized = clamp(volume / vessel.capacity, 0, 1);
const targetLayers = Math.max(0.05, normalized * VOXEL_LAYERS);
const fullLayers = Math.floor(targetLayers);
const partialLayer = targetLayers - fullLayers;
const layerCount = Math.max(1, Math.ceil(targetLayers));
let instance = 0;
for (let layer = 0; layer < layerCount; layer++) {
const isPartial = layer === fullLayers && partialLayer > 0;
const heightScale = isPartial ? partialLayer : 1;
const cubeHeight = voxelGeometry.parameters.height * heightScale;
for (let ix = 0; ix < VOXEL_GRID; ix++) {
for (let iz = 0; iz < VOXEL_GRID; iz++) {
position.set(
(ix - (VOXEL_GRID - 1) / 2) * VOXEL_SPACING_XZ,
vessel.baseY +
0.075 +
layer * VOXEL_SPACING_Y +
cubeHeight / 2,
(iz - (VOXEL_GRID - 1) / 2) * VOXEL_SPACING_XZ
);
scale.set(1, heightScale, 1);
matrix.compose(position, quaternion, scale);
vessel.voxelMesh.setMatrixAt(instance, matrix);
const variation = 0.87 + ((instance * 13) % 11) * 0.018;
instanceColor.setRGB(
(rgb.r / 255) * variation,
(rgb.g / 255) * variation,
(rgb.b / 255) * variation
);
vessel.voxelMesh.setColorAt(instance, instanceColor);
instance++;
}
}
}
vessel.voxelMesh.count = instance;
vessel.voxelMesh.instanceMatrix.needsUpdate = true;
if (vessel.voxelMesh.instanceColor) {
vessel.voxelMesh.instanceColor.needsUpdate = true;
}
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, keyboard, and reset
// -------------------------------------------------------------------------
const cameraState = {
yaw: 0.58,
pitch: 0.47,
radius: 8.25,
goalYaw: 0.58,
goalPitch: 0.47,
goalRadius: 8.25
};
const cameraTarget = new THREE.Vector3(0, 1.05, 0);
let dragging = false;
let previousX = 0;
let previousY = 0;
function resetCamera() {
cameraState.goalYaw = 0.58;
cameraState.goalPitch = 0.47;
cameraState.goalRadius = 8.25;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.goalYaw -= deltaX * 0.006;
cameraState.goalPitch = clamp(
cameraState.goalPitch + deltaY * 0.005,
0.15,
1.38
);
});
function endDrag(event) {
dragging = 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.goalRadius = clamp(
cameraState.goalRadius * Math.exp(event.deltaY * 0.001),
4.8,
13.5
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") {
cameraState.goalYaw += step;
} else if (event.key === "ArrowRight") {
cameraState.goalYaw -= step;
} else if (event.key === "ArrowUp") {
cameraState.goalPitch = clamp(cameraState.goalPitch - step, 0.15, 1.38);
} else if (event.key === "ArrowDown") {
cameraState.goalPitch = clamp(cameraState.goalPitch + step, 0.15, 1.38);
} else if (event.key === "+" || event.key === "=") {
cameraState.goalRadius = clamp(cameraState.goalRadius - 0.4, 4.8, 13.5);
} else if (event.key === "-" || event.key === "_") {
cameraState.goalRadius = clamp(cameraState.goalRadius + 0.4, 4.8, 13.5);
} else {
return;
}
event.preventDefault();
});
$("resetCamera").addEventListener("click", resetCamera);
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
resize();
// -------------------------------------------------------------------------
// Interface controls and readout
// -------------------------------------------------------------------------
const rangeInputs = [
...document.querySelectorAll('input[type="range"][data-key]')
];
rangeInputs.forEach((input) => {
input.addEventListener("input", () => {
state[input.dataset.key] = Number(input.value);
if (["cyan", "magenta", "amber"].includes(input.dataset.key)) {
state.recipeName = "Custom Blend";
}
updateInterface();
});
});
document.querySelectorAll("[data-ratio]").forEach((button) => {
button.addEventListener("click", () => {
state.ratio = Number(button.dataset.ratio);
updateInterface();
});
});
const presets = {
cyan: { cyan: 70, magenta: 25, amber: 10, name: "Cyan Comet" },
violet: { cyan: 14, magenta: 90, amber: 12, name: "Ultraviolet" },
amber: { cyan: 8, magenta: 13, amber: 92, name: "Solar Pop" },
prism: { cyan: 56, magenta: 48, amber: 52, name: "Prism Mix" }
};
document.querySelectorAll("[data-preset]").forEach((button) => {
button.addEventListener("click", () => {
const preset = presets[button.dataset.preset];
state.cyan = preset.cyan;
state.magenta = preset.magenta;
state.amber = preset.amber;
state.recipeName = preset.name;
updateInterface();
});
});
$("randomRecipe").addEventListener("click", () => {
state.cyan = Math.floor(10 + Math.random() * 80);
state.magenta = Math.floor(10 + Math.random() * 80);
state.amber = Math.floor(10 + Math.random() * 80);
state.recipeName = "Random Prism";
updateInterface();
});
function updateInterface() {
const model = calculateModel();
const rgb = getRecipeRGB();
$("potency").value = state.potency;
$("volume").value = state.volume;
$("cyan").value = state.cyan;
$("magenta").value = state.magenta;
$("amber").value = state.amber;
$("potencyOutput").textContent = `${state.potency} FU/mL`;
$("volumeOutput").textContent = `${state.volume} mL`;
$("cyanOutput").textContent = String(state.cyan);
$("magentaOutput").textContent = String(state.magenta);
$("amberOutput").textContent = String(state.amber);
document.querySelectorAll("[data-ratio]").forEach((button) => {
button.setAttribute(
"aria-pressed",
String(Number(button.dataset.ratio) === state.ratio)
);
});
$("recipeName").textContent = state.recipeName;
$("recipeSwatch").style.background =
`rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`;
$("c1Value").textContent = `${formatNumber(model.c1)} FU/mL`;
$("c2Value").textContent = `${formatNumber(model.c2)} FU/mL`;
$("v2Value").textContent = `${formatNumber(model.v2)} mL`;
$("waterValue").textContent = `${formatNumber(model.water)} mL water added`;
$("totalValue").textContent = `${formatNumber(model.totalUnits)} FU`;
$("mixEquation").textContent =
`${formatNumber(model.c1)} FU/mL × ${formatNumber(model.v1)} mL = ` +
`${formatNumber(model.totalUnits)} FU`;
$("finalEquation").textContent =
`${formatNumber(model.totalUnits)} FU ÷ ${formatNumber(model.v2)} mL = ` +
`${formatNumber(model.c2)} FU/mL`;
$("ratioDescription").textContent = model.r === 1
? "A 1:1 mixture uses the stock portion without adding water."
: `A 1:${model.r} final mixture contains one part stock and ` +
`${model.r - 1} parts water.`;
$("stockSceneValue").textContent = `${formatNumber(model.c1)} FU/mL`;
$("stockSceneMeta").textContent = `${formatNumber(model.v1)} mL stock`;
$("finalSceneValue").textContent = `${formatNumber(model.c2)} FU/mL`;
$("finalSceneMeta").textContent =
`${formatNumber(model.v2)} mL total · ${formatNumber(model.water)} mL water`;
$("ratioSceneValue").textContent = model.r === 1
? "1 stock + 0 water"
: `1 stock + ${model.r - 1} water`;
updateVoxelMesh(stockVessel, model.v1, rgb);
updateVoxelMesh(finalVessel, model.v2, rgb);
}
updateInterface();
// -------------------------------------------------------------------------
// Projected HTML labels and render loop
// -------------------------------------------------------------------------
const stockAnchor = new THREE.Vector3(
stockVessel.group.position.x,
2.28,
stockVessel.group.position.z
);
const finalAnchor = new THREE.Vector3(
finalVessel.group.position.x,
2.28,
finalVessel.group.position.z
);
const ratioAnchor = new THREE.Vector3(0, 1.92, 0.68);
function placeProjectedLabel(element, anchor) {
const projected = anchor.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
const x = (projected.x * 0.5 + 0.5) * viewport.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * viewport.clientHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
cameraState.yaw +=
(cameraState.goalYaw - cameraState.yaw) * 0.12;
cameraState.pitch +=
(cameraState.goalPitch - cameraState.pitch) * 0.12;
cameraState.radius +=
(cameraState.goalRadius - cameraState.radius) * 0.12;
const sinPitch = Math.sin(cameraState.pitch);
camera.position.set(
cameraTarget.x +
cameraState.radius * sinPitch * Math.sin(cameraState.yaw),
cameraTarget.y + cameraState.radius * Math.cos(cameraState.pitch),
cameraTarget.z +
cameraState.radius * sinPitch * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraTarget);
const pulse = 0.68 + Math.sin(elapsed * 2.2) * 0.14;
arrow.line.material.opacity = pulse;
arrow.cone.material.opacity = 0.78 + Math.sin(elapsed * 2.2) * 0.1;
placeProjectedLabel($("stockLabel"), stockAnchor);
placeProjectedLabel($("finalLabel"), finalAnchor);
placeProjectedLabel($("ratioLabel"), ratioAnchor);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```