Prompt specification
Build or customize the Three.js 3D scene "Coastal Tide Teaching Harbor" 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: Coastal Tide Teaching Harbor
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/coastal-tide-teaching-harbor-x3839
Scene Description Prompt:
Build an original harbor linked to a conceptual tidal-forcing display. Use a declared illustrative water-level cycle and distinguish it from a forecast for any real coast. Use Three.js from cdnjs in a single HTML file, with visible voxel blocks.
Working Three.js Starter (coastal-tide-teaching-harbor-x3839):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Tideglass Harbor — Synthetic Tidal-Forcing Study</title>
<style>
:root {
--ink: #07131d;
--panel: rgba(8, 24, 34, 0.88);
--line: rgba(135, 218, 231, 0.22);
--cyan: #68e8ef;
--cyan-soft: #a7f5f5;
--amber: #ffb45c;
--white: #e9f5f3;
--muted: #91a9ad;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--ink);
color: var(--white);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, select, input { font: inherit; }
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background:
linear-gradient(145deg, rgba(18, 47, 59, 0.88), rgba(6, 19, 28, 0.93));
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(15px);
}
header {
top: 18px;
left: 18px;
width: min(470px, calc(100vw - 36px));
padding: 17px 18px 16px;
border-radius: 5px 18px 5px 5px;
}
.brand-row {
display: flex;
align-items: center;
gap: 12px;
}
.mark {
width: 39px;
height: 39px;
position: relative;
flex: 0 0 auto;
}
.mark i {
position: absolute;
display: block;
width: 16px;
height: 16px;
background: var(--cyan);
box-shadow: 0 0 18px rgba(104, 232, 239, 0.42);
}
.mark i:nth-child(1) { left: 0; top: 0; opacity: 0.45; }
.mark i:nth-child(2) { right: 0; top: 0; }
.mark i:nth-child(3) { left: 0; bottom: 0; }
.mark i:nth-child(4) {
right: 0;
bottom: 0;
background: var(--amber);
}
h1 {
margin: 0;
font-size: 18px;
line-height: 1;
letter-spacing: 0.18em;
font-weight: 780;
}
.subtitle {
margin: 7px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.disclaimer {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 15px;
padding: 7px 9px;
border: 1px solid rgba(255, 180, 92, 0.38);
border-radius: 3px;
color: #ffd4a4;
background: rgba(255, 180, 92, 0.075);
font-size: 10px;
line-height: 1.25;
font-weight: 760;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.disclaimer::before {
content: "";
width: 6px;
height: 6px;
flex: 0 0 auto;
background: var(--amber);
box-shadow: 0 0 10px rgba(255, 180, 92, 0.7);
}
.telemetry {
top: 18px;
right: 18px;
width: 318px;
padding: 16px;
border-radius: 18px 5px 5px 5px;
}
.panel-label {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.telemetry h2 {
margin: 6px 0 13px;
font-size: 15px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.readouts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.readout {
min-height: 70px;
padding: 10px;
border: 1px solid rgba(145, 203, 210, 0.14);
background: rgba(2, 13, 20, 0.38);
}
.readout span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.readout strong {
display: block;
margin-top: 6px;
font-size: 23px;
line-height: 1;
font-variant-numeric: tabular-nums;
font-weight: 670;
}
#forcingValue { color: var(--cyan); }
#levelValue { color: var(--amber); }
.state-row {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 9px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.state-row b {
color: var(--white);
font-weight: 700;
text-align: right;
}
#chart {
display: block;
width: 100%;
height: 126px;
margin-top: 12px;
border: 1px solid rgba(145, 203, 210, 0.13);
background: rgba(1, 10, 16, 0.42);
}
.chart-key {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.chart-key span:first-child { color: var(--cyan); }
.chart-key span:last-child { color: var(--amber); }
.equation {
margin-top: 11px;
padding: 9px 10px;
border-left: 2px solid var(--cyan);
background: rgba(104, 232, 239, 0.055);
color: #b8cdd0;
font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.cycle-note {
margin-top: 8px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.timeline {
left: 50%;
bottom: 18px;
width: min(720px, calc(100vw - 36px));
transform: translateX(-50%);
padding: 13px 15px 12px;
border-radius: 5px 5px 18px 5px;
}
.transport {
display: grid;
grid-template-columns: auto auto minmax(160px, 1fr) auto auto;
align-items: center;
gap: 10px;
}
button, select {
height: 35px;
border: 1px solid rgba(133, 209, 217, 0.25);
border-radius: 3px;
color: var(--white);
background: rgba(16, 42, 53, 0.85);
cursor: pointer;
}
button {
padding: 0 13px;
font-size: 11px;
font-weight: 760;
letter-spacing: 0.08em;
text-transform: uppercase;
}
button:hover, select:hover {
border-color: rgba(104, 232, 239, 0.65);
color: var(--cyan-soft);
}
button:focus-visible, select:focus-visible, input:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
#playButton {
min-width: 74px;
color: var(--ink);
border-color: var(--cyan);
background: var(--cyan);
}
#phaseSlider {
width: 100%;
accent-color: var(--cyan);
cursor: pointer;
}
select {
padding: 0 27px 0 9px;
font-size: 11px;
}
.clock {
min-width: 86px;
color: var(--cyan-soft);
font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: right;
font-variant-numeric: tabular-nums;
}
.timeline-labels {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 12px;
margin-top: 8px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.timeline-labels span:nth-child(2) {
color: #b8cdd0;
text-align: center;
}
.timeline-labels span:last-child { text-align: right; }
.corner-note {
position: fixed;
z-index: 8;
left: 19px;
bottom: 20px;
color: rgba(185, 211, 213, 0.62);
font-size: 9px;
line-height: 1.6;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
color: var(--cyan);
background: var(--ink);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 0.35s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 820px) {
header {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px;
}
h1 { font-size: 15px; }
.subtitle { display: none; }
.disclaimer { margin-top: 10px; font-size: 9px; }
.telemetry {
top: 115px;
right: 10px;
width: 238px;
padding: 11px;
}
.telemetry h2 { font-size: 12px; }
.readout { min-height: 58px; padding: 8px; }
.readout strong { font-size: 18px; }
#chart { height: 90px; }
.equation, .cycle-note { display: none; }
.timeline {
bottom: 10px;
width: calc(100vw - 20px);
padding: 10px;
}
.transport {
grid-template-columns: auto auto 1fr auto;
gap: 6px;
}
.clock { display: none; }
#resetButton { display: none; }
.corner-note { display: none; }
}
@media (max-width: 480px) {
.telemetry {
top: 104px;
width: 208px;
}
.readouts { gap: 5px; }
.readout span { font-size: 8px; }
.readout strong { font-size: 16px; }
.state-row { font-size: 8px; }
.chart-key { font-size: 8px; }
.transport {
grid-template-columns: auto 1fr auto;
}
#resetPhaseButton { display: none; }
button { padding: 0 9px; }
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="panel">
<div class="brand-row">
<div class="mark" aria-hidden="true">
<i></i><i></i><i></i><i></i>
</div>
<div>
<h1>TIDEGLASS HARBOR</h1>
<p class="subtitle">Fictional voxel port / linked forcing study</p>
</div>
</div>
<div class="disclaimer">
Synthetic cycle only — not a forecast for any real coast
</div>
</header>
<aside class="panel telemetry" aria-label="Tidal telemetry">
<div class="panel-label">Concept array 07</div>
<h2>Forcing / response</h2>
<div class="readouts">
<div class="readout">
<span>Normalized forcing</span>
<strong id="forcingValue">+0.00</strong>
</div>
<div class="readout">
<span>Illustrative level</span>
<strong id="levelValue">+0.00 m</strong>
</div>
</div>
<div class="state-row">
<span>Phase</span><b id="phaseValue">18.0%</b>
</div>
<div class="state-row">
<span>Response</span><b id="stateValue">Rising</b>
</div>
<canvas id="chart" width="560" height="220"
aria-label="Graph of synthetic forcing and illustrative water level"></canvas>
<div class="chart-key">
<span>— forcing F</span>
<span>— level L</span>
</div>
<div class="equation">
θ = 2πp<br />
F = cos(θ)<br />
L = 0.95F + 0.18cos(2θ + 0.35) m
</div>
<div class="cycle-note">
Declared illustrative cycle: 12:25:00, compressed to 180 seconds.
Geometry, coefficients, and harbor are fictional.
</div>
</aside>
<footer class="panel timeline" aria-label="Cycle controls">
<div class="transport">
<button id="playButton" type="button">Pause</button>
<button id="resetPhaseButton" type="button" title="Reset the synthetic cycle">
Reset
</button>
<input
id="phaseSlider"
type="range"
min="0"
max="1000"
value="180"
aria-label="Synthetic cycle phase"
/>
<select id="speedSelect" aria-label="Playback speed">
<option value="0.5">0.5×</option>
<option value="1" selected>1×</option>
<option value="2">2×</option>
<option value="4">4×</option>
</select>
<div id="clock" class="clock">02:14:30</div>
<button id="resetViewButton" type="button" title="Reset camera">
View
</button>
</div>
<div class="timeline-labels">
<span>Low water</span>
<span>Declared synthetic cycle · 12 h 25 min</span>
<span>High water</span>
</div>
</footer>
<div class="corner-note">
Drag to orbit · wheel / pinch to zoom · arrow keys to rotate<br />
Port 07 · conceptual mechanics visualization
</div>
<div id="loading">Constructing tideglass harbor…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = id => document.getElementById(id);
const CYCLE_SECONDS = 180;
const CYCLE_DISPLAY_SECONDS = 12 * 3600 + 25 * 60;
const MAX_LEVEL = 1.2;
let phase = 0.18;
let playing = true;
let speed = 1;
const forcingAt = p => Math.cos(p * Math.PI * 2);
const levelAt = p =>
0.95 * Math.cos(p * Math.PI * 2) +
0.18 * Math.cos(p * Math.PI * 4 + 0.35);
const derivativeAt = p =>
-0.95 * Math.sin(p * Math.PI * 2) -
0.36 * Math.sin(p * Math.PI * 4 + 0.35);
const stage = $("stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131d);
scene.fog = new THREE.Fog(0x07131d, 72, 155);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional voxel harbor. Drag to orbit and use the wheel to zoom."
);
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
window.innerWidth < 700 ? 50 : 38,
window.innerWidth / window.innerHeight,
0.1,
260
);
const controls = {
azimuth: 0.70,
polar: 0.92,
radius: window.innerWidth < 700 ? 115 : 82,
target: new THREE.Vector3(0, 1.5, -2)
};
function updateCamera() {
const sinPolar = Math.sin(controls.polar);
camera.position.set(
controls.target.x +
controls.radius * sinPolar * Math.sin(controls.azimuth),
controls.target.y +
controls.radius * Math.cos(controls.polar),
controls.target.z +
controls.radius * sinPolar * Math.cos(controls.azimuth)
);
camera.lookAt(controls.target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xa9e9f4, 0x14232b, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe2b5, 3.4);
sun.position.set(-24, 48, 30);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -44;
sun.shadow.camera.right = 44;
sun.shadow.camera.top = 44;
sun.shadow.camera.bottom = -44;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 115;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x4fdce8, 1.7);
rim.position.set(30, 18, -35);
scene.add(rim);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
const tempColor = new THREE.Color();
const staticBlocks = [];
const glowBlocks = [];
function addBlock(
x, y, z, sx, sy, sz, color,
rotation = 0, glow = false
) {
(glow ? glowBlocks : staticBlocks).push({
x, y, z, sx, sy, sz, color, rotation
});
}
function hash(i, j = 0) {
const n = Math.sin(i * 127.1 + j * 311.7) * 43758.5453123;
return n - Math.floor(n);
}
function tint(color, amount = 0) {
const c = new THREE.Color(color);
c.offsetHSL(0, 0, amount);
return c;
}
// Foundation below the voxel water field.
addBlock(0, -2.05, 0, 64, 0.45, 54, 0x06151d);
// Rear quay and side lands, all built from separated blocks.
for (let x = -28; x <= 28; x += 2) {
for (let z = -26; z <= -18; z += 2) {
const h = 1.72 + hash(x, z) * 0.24;
addBlock(x, -0.84 + h / 2, z, 1.86, h, 1.86, 0x43535a);
}
}
for (let z = -16; z <= 16; z += 2) {
for (const side of [-1, 1]) {
for (let lane = 0; lane < 3; lane++) {
const x = side * (25 + lane * 2);
const h = 1.66 + hash(x, z) * 0.28;
addBlock(x, -0.84 + h / 2, z, 1.86, h, 1.86, 0x3a4c53);
}
}
}
// Stepped entrance breakwaters.
for (let x = -24; x <= -12; x += 2) {
addBlock(x, 0, 15, 1.87, 1.8, 1.87, 0x4d5d60);
addBlock(x, 1.2, 15, 1.4, 0.6, 1.4, 0x607075);
}
for (let x = 12; x <= 24; x += 2) {
addBlock(x, 0, 15, 1.87, 1.8, 1.87, 0x4d5d60);
addBlock(x, 1.2, 15, 1.4, 0.6, 1.4, 0x607075);
}
const buildingPalette = [
0x31515b, 0x3e6670, 0x6d7773, 0x997054,
0xb5a47e, 0x496c73, 0x315a63, 0x7d5d50
];
function addBuilding(cx, cz, cols, rows, floors, palette = buildingPalette) {
for (let floor = 0; floor < floors; floor++) {
for (let ix = 0; ix < cols; ix++) {
for (let iz = 0; iz < rows; iz++) {
const x = cx + (ix - (cols - 1) / 2) * 1.52;
const z = cz + (iz - (rows - 1) / 2) * 1.52;
const y = 1.03 + (floor + 0.5) * 1.43;
const index = (ix + iz * 2 + floor * 3) % palette.length;
const color = tint(palette[index], (hash(ix, iz + floor) - 0.5) * 0.08);
addBlock(x, y, z, 1.37, 1.37, 1.37, color);
if (iz === rows - 1 && (ix + floor) % 2 === 0) {
addBlock(
x, y + 0.10, z + 0.71,
0.38, 0.33, 0.08,
floor % 3 === 0 ? 0x79edf0 : 0xffc06b,
0, true
);
}
}
}
}
addBlock(
cx, 1.03 + floors * 1.43 + 0.28, cz,
0.85, 0.55, 0.85, 0x33464d
);
}
// A deliberately irregular but coherent skyline.
addBuilding(-22, -23.5, 4, 2, 3);
addBuilding(-15.5, -23.2, 3, 2, 5);
addBuilding(-8.5, -23.8, 3, 2, 2);
addBuilding(8, -23.3, 4, 2, 4);
addBuilding(16, -23.2, 3, 2, 3);
addBuilding(23, -22.8, 3, 2, 6);
addBuilding(-27, -11, 2, 4, 2);
addBuilding(-27, -3, 2, 3, 4);
addBuilding(27, -10, 2, 4, 4);
addBuilding(27, -1.5, 2, 3, 2);
// Container yards.
const cargoColors = [0xa75842, 0xb58b48, 0x3d7980, 0x657d73, 0x496270];
for (let i = 0; i < 18; i++) {
const x = 25 + (i % 3) * 2;
const z = -14 + Math.floor(i / 3) * 2;
const levels = 1 + (i % 2);
for (let level = 0; level < levels; level++) {
addBlock(
x, 1.7 + level * 1.55, z,
1.65, 1.45, 1.65,
cargoColors[i % cargoColors.length]
);
}
}
// Segmented piers and pilings.
function addPier(cx, endZ) {
for (let z = -17; z >= endZ; z -= 0.92) {
addBlock(cx - 0.61, 1.12, z, 1.12, 0.35, 0.76, 0x8b775b);
addBlock(cx + 0.61, 1.12, z, 1.12, 0.35, 0.76, 0x9a8260);
}
for (let z = -16; z >= endZ; z -= 3.6) {
addBlock(cx - 1.35, 0.05, z, 0.38, 2.7, 0.38, 0x343f43);
addBlock(cx + 1.35, 0.05, z, 0.38, 2.7, 0.38, 0x343f43);
}
}
addPier(-12, -2.5);
addPier(10, -3.5);
// Voxel lighthouse at the western breakwater.
for (let i = 0; i < 8; i++) {
const color = i % 2 === 0 ? 0xe1e2cf : 0xb55e48;
addBlock(-21, 1.72 + i * 1.48, 15, 1.43, 1.43, 1.43, color);
}
addBlock(-21, 12.98, 15, 1.62, 0.9, 1.62, 0x233d46);
addBlock(-21, 13.72, 15, 0.72, 0.58, 0.72, 0xffe0a0, 0, true);
addBlock(-21, 14.23, 15, 1.48, 0.42, 1.48, 0x354d55);
const lighthouseLight = new THREE.PointLight(0xffc76c, 18, 16, 2);
lighthouseLight.position.set(-21, 13.75, 15);
scene.add(lighthouseLight);
// Eastern signal beacon.
for (let i = 0; i < 4; i++) {
addBlock(19, 1.72 + i * 1.25, 15, 1.05, 1.2, 1.05, 0x547079);
}
addBlock(19, 6.48, 15, 0.65, 0.62, 0.65, 0x68e8ef, 0, true);
// Right-side cargo gantry, assembled from cubic segments.
for (const z of [-10, -2]) {
for (const x of [23.5, 27.5]) {
for (let y = 1.4; y <= 8.4; y += 1.35) {
addBlock(x, y, z, 0.78, 1.28, 0.78, 0xb17b3f);
}
}
addBlock(25.5, 9.25, z, 5.2, 0.8, 1.05, 0xd49a4d);
addBlock(25.5, 8.25, z, 0.55, 1.4, 0.55, 0x58483b);
}
addBlock(25.5, 9.35, -6, 0.75, 0.85, 9.4, 0xc38d45);
addBlock(25.5, 7.2, -7.5, 1.8, 1.5, 2.1, 0x3d7d83);
// Rear crane.
for (let y = 1.4; y <= 8.2; y += 1.3) {
addBlock(17, y, -17.4, 0.8, 1.25, 0.8, 0xbb8143);
}
addBlock(13.5, 8.8, -17.4, 8.5, 0.8, 0.8, 0xd49a4d);
addBlock(10, 7.2, -17.4, 0.45, 3.2, 0.45, 0x3d4447);
addBlock(10, 5.45, -17.4, 1.3, 1.3, 1.3, 0x385d65);
// Build the static instanced voxel meshes.
const staticMesh = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.84,
metalness: 0.05
}),
staticBlocks.length
);
staticBlocks.forEach((b, i) => {
dummy.position.set(b.x, b.y, b.z);
dummy.rotation.set(0, b.rotation, 0);
dummy.scale.set(b.sx, b.sy, b.sz);
dummy.updateMatrix();
staticMesh.setMatrixAt(i, dummy.matrix);
staticMesh.setColorAt(i, tempColor.set(b.color));
});
staticMesh.instanceMatrix.needsUpdate = true;
staticMesh.instanceColor.needsUpdate = true;
staticMesh.castShadow = true;
staticMesh.receiveShadow = true;
scene.add(staticMesh);
const glowMesh = new THREE.InstancedMesh(
unitBox,
new THREE.MeshBasicMaterial({ color: 0xffffff }),
Math.max(1, glowBlocks.length)
);
glowBlocks.forEach((b, i) => {
dummy.position.set(b.x, b.y, b.z);
dummy.rotation.set(0, b.rotation, 0);
dummy.scale.set(b.sx, b.sy, b.sz);
dummy.updateMatrix();
glowMesh.setMatrixAt(i, dummy.matrix);
glowMesh.setColorAt(i, tempColor.set(b.color));
});
glowMesh.instanceMatrix.needsUpdate = true;
glowMesh.instanceColor.needsUpdate = true;
scene.add(glowMesh);
// Water is a grid of visibly separate voxel columns.
const WATER_COLS = 25;
const WATER_ROWS = 17;
const waterCells = [];
const waterMesh = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.42,
metalness: 0.08,
transparent: true,
opacity: 0.94
}),
WATER_COLS * WATER_ROWS
);
waterMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
waterMesh.receiveShadow = true;
waterMesh.frustumCulled = false;
scene.add(waterMesh);
let cellIndex = 0;
for (let ix = 0; ix < WATER_COLS; ix++) {
for (let iz = 0; iz < WATER_ROWS; iz++) {
waterCells.push({
x: (ix - (WATER_COLS - 1) / 2) * 2,
z: (iz - (WATER_ROWS - 1) / 2) * 2,
seed: hash(ix + 11, iz + 31)
});
cellIndex++;
}
}
// Small luminous surface voxels.
const glintCount = 44;
const glintMesh = new THREE.InstancedMesh(
unitBox,
new THREE.MeshBasicMaterial({ color: 0x8ff6ef }),
glintCount
);
glintMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
glintMesh.frustumCulled = false;
scene.add(glintMesh);
const glints = [];
for (let i = 0; i < glintCount; i++) {
glints.push({
x: -23 + hash(i, 4) * 46,
z: -15 + hash(i, 8) * 30,
phase: hash(i, 12) * Math.PI * 2
});
}
// Voxel barges.
const bargeGroups = [];
function makeBarge(x, z, s, hullColor, angle) {
const group = new THREE.Group();
const hullMaterial = new THREE.MeshStandardMaterial({
color: hullColor,
roughness: 0.7
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x263d46,
roughness: 0.65
});
const cabinMaterial = new THREE.MeshStandardMaterial({
color: 0xc6c9b5,
roughness: 0.75
});
for (let ix = -1; ix <= 1; ix++) {
for (let iz = -1; iz <= 0; iz++) {
const mesh = new THREE.Mesh(unitBox, hullMaterial);
mesh.position.set(ix * 1.22, -0.35, iz * 1.22);
mesh.scale.set(1.16, 0.82, 1.16);
mesh.castShadow = true;
group.add(mesh);
}
}
const cabin = new THREE.Mesh(unitBox, cabinMaterial);
cabin.position.set(0.65, 0.52, -0.65);
cabin.scale.set(0.85, 0.95, 0.9);
cabin.castShadow = true;
group.add(cabin);
const stack = new THREE.Mesh(unitBox, darkMaterial);
stack.position.set(0.65, 1.18, -0.65);
stack.scale.set(0.38, 0.42, 0.38);
group.add(stack);
group.position.set(x, 0, z);
group.rotation.y = angle;
group.scale.setScalar(s);
scene.add(group);
bargeGroups.push({ group, baseY: 0, phase: hash(x, z) * 6.28 });
}
makeBarge(-6, 5, 1.05, 0x9b5c43, 0.08);
makeBarge(15.5, -4.5, 0.82, 0x3e747b, -0.12);
// Tide gauge: a stack of blocks and a bright marker that follows level.
for (let i = -6; i <= 6; i++) {
addBlock(
-17, i * 0.22, -17.15,
0.14, 0.12, 0.14,
i % 3 === 0 ? 0xffc16d : 0x4b747b
);
}
const gaugeMarker = new THREE.Mesh(
unitBox,
new THREE.MeshBasicMaterial({ color: 0xffb45c })
);
gaugeMarker.scale.set(0.66, 0.42, 0.66);
gaugeMarker.position.set(-17, 0, -17.1);
scene.add(gaugeMarker);
// Abstract forcing core: a hovering cubic halo.
const coreGroup = new THREE.Group();
coreGroup.position.set(0, 9.2, -14.5);
scene.add(coreGroup);
const ringMaterial = new THREE.MeshStandardMaterial({
color: 0x2d6b75,
emissive: 0x0b3137,
emissiveIntensity: 0.6,
roughness: 0.42,
metalness: 0.18
});
const ringBlocks = [];
for (let i = 0; i < 16; i++) {
const angle = i / 16 * Math.PI * 2;
const mesh = new THREE.Mesh(unitBox, ringMaterial);
mesh.position.set(
Math.cos(angle) * 2.65,
Math.sin(angle) * 2.65,
Math.sin(angle * 2) * 0.38
);
mesh.scale.setScalar(i % 2 === 0 ? 0.48 : 0.34);
mesh.rotation.z = angle;
mesh.castShadow = true;
coreGroup.add(mesh);
ringBlocks.push(mesh);
}
const coreMaterial = new THREE.MeshBasicMaterial({ color: 0x68e8ef });
const coreCube = new THREE.Mesh(unitBox, coreMaterial);
coreCube.scale.setScalar(1.05);
coreGroup.add(coreCube);
const coreLight = new THREE.PointLight(0x54e9ee, 12, 18, 2);
coreGroup.add(coreLight);
// Nine pylons visualize the signed forcing oscillator.
const forcingPylons = [];
for (let i = 0; i < 9; i++) {
const x = (i - 4) * 0.75;
const mesh = new THREE.Mesh(
unitBox,
new THREE.MeshBasicMaterial({
color: i === 4 ? 0xffb45c : 0x68e8ef
})
);
mesh.position.set(x, 1.4, -17.5);
mesh.scale.set(0.27, 0.45, 0.27);
scene.add(mesh);
forcingPylons.push(mesh);
}
// A chain of signal cubes links the abstract core to the harbor basin.
const signalCount = 15;
const signalMesh = new THREE.InstancedMesh(
unitBox,
new THREE.MeshBasicMaterial({ color: 0x8ef9f3 }),
signalCount
);
signalMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
signalMesh.frustumCulled = false;
scene.add(signalMesh);
// Sparse background points.
const starPositions = [];
for (let i = 0; i < 150; i++) {
starPositions.push(
(hash(i, 1) - 0.5) * 150,
10 + hash(i, 2) * 55,
-45 - hash(i, 3) * 75
);
}
const starsGeometry = new THREE.BufferGeometry();
starsGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(starPositions, 3)
);
const stars = new THREE.Points(
starsGeometry,
new THREE.PointsMaterial({
color: 0x9bdbe0,
size: 0.13,
transparent: true,
opacity: 0.55,
sizeAttenuation: true
})
);
scene.add(stars);
// Chart drawing.
const chart = $("chart");
const chartContext = chart.getContext("2d");
const chartWidth = chart.width;
const chartHeight = chart.height;
function drawChart() {
const c = chartContext;
const padL = 27;
const padR = 12;
const padT = 14;
const padB = 22;
const plotW = chartWidth - padL - padR;
const plotH = chartHeight - padT - padB;
const mapX = p => padL + p * plotW;
const mapY = v => padT + plotH * (0.5 - v / (MAX_LEVEL * 1.08));
c.clearRect(0, 0, chartWidth, chartHeight);
c.strokeStyle = "rgba(145,203,210,0.10)";
c.lineWidth = 1;
for (let i = 0; i <= 4; i++) {
const x = padL + i / 4 * plotW;
c.beginPath();
c.moveTo(x, padT);
c.lineTo(x, padT + plotH);
c.stroke();
}
for (const value of [-1, 0, 1]) {
const y = mapY(value);
c.beginPath();
c.moveTo(padL, y);
c.lineTo(padL + plotW, y);
c.strokeStyle = value === 0
? "rgba(225,245,243,0.24)"
: "rgba(145,203,210,0.10)";
c.stroke();
}
c.font = "18px ui-monospace, monospace";
c.fillStyle = "rgba(165,196,199,0.72)";
c.textAlign = "right";
c.fillText("+1", padL - 7, mapY(1) + 5);
c.fillText(" 0", padL - 7, mapY(0) + 5);
c.fillText("−1", padL - 7, mapY(-1) + 5);
c.save();
c.beginPath();
c.rect(padL, padT, plotW, plotH);
c.clip();
c.setLineDash([9, 7]);
c.strokeStyle = "#68e8ef";
c.lineWidth = 2.5;
c.beginPath();
for (let i = 0; i <= 300; i++) {
const p = i / 300;
const x = mapX(p);
const y = mapY(forcingAt(p));
if (i === 0) c.moveTo(x, y);
else c.lineTo(x, y);
}
c.stroke();
c.setLineDash([]);
c.strokeStyle = "#ffb45c";
c.lineWidth = 3;
c.beginPath();
for (let i = 0; i <= 300; i++) {
const p = i / 300;
const x = mapX(p);
const y = mapY(levelAt(p));
if (i === 0) c.moveTo(x, y);
else c.lineTo(x, y);
}
c.stroke();
const currentX = mapX(phase);
c.strokeStyle = "rgba(233,245,243,0.48)";
c.lineWidth = 1.5;
c.beginPath();
c.moveTo(currentX, padT);
c.lineTo(currentX, padT + plotH);
c.stroke();
c.fillStyle = "#68e8ef";
c.beginPath();
c.arc(currentX, mapY(forcingAt(phase)), 5, 0, Math.PI * 2);
c.fill();
c.fillStyle = "#ffb45c";
c.beginPath();
c.arc(currentX, mapY(levelAt(phase)), 5, 0, Math.PI * 2);
c.fill();
c.restore();
c.fillStyle = "rgba(165,196,199,0.65)";
c.font = "17px ui-monospace, monospace";
c.textAlign = "left";
c.fillText("0", padL, chartHeight - 5);
c.textAlign = "center";
c.fillText("½", padL + plotW / 2, chartHeight - 5);
c.textAlign = "right";
c.fillText("1", padL + plotW, chartHeight - 5);
}
function formatClock(seconds) {
const h = Math.floor(seconds / 3600);
const m = Math.floor((seconds % 3600) / 60);
const s = Math.floor(seconds % 60);
return [h, m, s].map(v => String(v).padStart(2, "0")).join(":");
}
function signed(value, digits = 2) {
const rounded = Math.abs(value) < 0.0001 ? 0 : value;
return `${rounded >= 0 ? "+" : "−"}${Math.abs(rounded).toFixed(digits)}`;
}
function updateTelemetry() {
const forcing = forcingAt(phase);
const level = levelAt(phase);
const derivative = derivativeAt(phase);
$("forcingValue").textContent = signed(forcing);
$("levelValue").textContent = `${signed(level)} m`;
$("phaseValue").textContent = `${(phase * 100).toFixed(1)}%`;
$("stateValue").textContent =
derivative > 0.015 ? "Rising" :
derivative < -0.015 ? "Falling" : "Turning";
$("clock").textContent = formatClock(phase * CYCLE_DISPLAY_SECONDS);
$("phaseSlider").value = String(Math.round(phase * 1000));
}
function setPlaying(value) {
playing = value;
$("playButton").textContent = playing ? "Pause" : "Play";
$("playButton").setAttribute("aria-pressed", String(!playing));
}
$("playButton").addEventListener("click", () => setPlaying(!playing));
$("resetPhaseButton").addEventListener("click", () => {
phase = 0.18;
setPlaying(true);
updateTelemetry();
});
$("phaseSlider").addEventListener("input", event => {
phase = Number(event.target.value) / 1000;
setPlaying(false);
updateTelemetry();
});
$("speedSelect").addEventListener("change", event => {
speed = Number(event.target.value);
});
$("resetViewButton").addEventListener("click", () => {
controls.azimuth = 0.70;
controls.polar = 0.92;
controls.radius = window.innerWidth < 700 ? 115 : 82;
controls.target.set(0, 1.5, -2);
updateCamera();
});
// Direct camera controls: pointer drag, wheel zoom, and two-pointer pinch.
const pointers = new Map();
let previousPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
renderer.domElement.focus({ preventScroll: true });
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
if (pointers.size === 1) {
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
controls.azimuth -= dx * 0.005;
controls.polar = THREE.MathUtils.clamp(
controls.polar + dy * 0.004,
0.43,
1.32
);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
} else if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (previousPinchDistance > 0) {
controls.radius = THREE.MathUtils.clamp(
controls.radius * previousPinchDistance / distance,
40,
145
);
}
previousPinchDistance = distance;
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
40,
145
);
updateCamera();
}, { passive: false });
window.addEventListener("keydown", event => {
const tag = document.activeElement?.tagName;
if (["INPUT", "SELECT", "BUTTON"].includes(tag)) return;
if (event.key === "ArrowLeft") {
controls.azimuth += 0.08;
} else if (event.key === "ArrowRight") {
controls.azimuth -= 0.08;
} else if (event.key === "ArrowUp") {
controls.polar = Math.max(0.43, controls.polar - 0.06);
} else if (event.key === "ArrowDown") {
controls.polar = Math.min(1.32, controls.polar + 0.06);
} else if (event.key === "+" || event.key === "=") {
controls.radius = Math.max(40, controls.radius - 3);
} else if (event.key === "-") {
controls.radius = Math.min(145, controls.radius + 3);
} else {
return;
}
event.preventDefault();
updateCamera();
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = window.innerWidth < 700 ? 50 : 38;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
if (playing) {
phase = (phase + dt * speed / CYCLE_SECONDS) % 1;
}
const forcing = forcingAt(phase);
const level = levelAt(phase);
// Animate every water voxel column independently at its surface.
waterCells.forEach((cell, i) => {
const surface = level +
0.035 * Math.sin(elapsed * 1.7 + cell.x * 0.32 + cell.z * 0.21);
const bottom = -1.85;
const height = Math.max(0.18, surface - bottom);
dummy.position.set(cell.x, bottom + height / 2, cell.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1.82, height, 1.82);
dummy.updateMatrix();
waterMesh.setMatrixAt(i, dummy.matrix);
const hue = 0.515 + cell.seed * 0.025;
const lightness = 0.31 + (surface + 1.2) * 0.035 + cell.seed * 0.035;
tempColor.setHSL(hue, 0.53, lightness);
waterMesh.setColorAt(i, tempColor);
});
waterMesh.instanceMatrix.needsUpdate = true;
waterMesh.instanceColor.needsUpdate = true;
// Surface glints.
glints.forEach((g, i) => {
const surface = level +
0.035 * Math.sin(elapsed * 1.7 + g.x * 0.32 + g.z * 0.21);
const pulse = 0.45 + 0.55 * Math.pow(
Math.max(0, Math.sin(elapsed * 1.6 + g.phase)),
5
);
dummy.position.set(g.x, surface + 0.09, g.z);
dummy.rotation.set(0, elapsed * 0.4 + g.phase, 0);
dummy.scale.set(0.12, 0.08, 0.12).multiplyScalar(0.7 + pulse * 0.8);
dummy.updateMatrix();
glintMesh.setMatrixAt(i, dummy.matrix);
});
glintMesh.instanceMatrix.needsUpdate = true;
// Barges rise with the water and add a restrained independent bob.
bargeGroups.forEach((barge, i) => {
const bob = Math.sin(elapsed * 1.15 + barge.phase) * 0.075;
const roll = Math.sin(elapsed * 0.8 + barge.phase) * 0.015;
barge.group.position.y = level + 0.13 + bob;
barge.group.rotation.z = roll;
barge.group.rotation.x = Math.cos(elapsed * 0.72 + barge.phase) * 0.009;
});
// Gauge marker.
gaugeMarker.position.y = level;
// The cubic forcing core expands and brightens with positive forcing.
const coreEnergy = 0.5 + 0.5 * forcing;
coreCube.scale.setScalar(0.82 + coreEnergy * 0.55);
coreCube.rotation.set(elapsed * 0.22, elapsed * 0.31, 0);
coreGroup.rotation.z = elapsed * 0.085;
coreGroup.position.y = 9.2 + Math.sin(elapsed * 0.7) * 0.35;
coreMaterial.color.setRGB(
0.25 + coreEnergy * 0.15,
0.76 + coreEnergy * 0.22,
0.82 + coreEnergy * 0.18
);
coreLight.intensity = 7 + coreEnergy * 13;
ringBlocks.forEach((block, i) => {
const localScale = 0.30 + (i % 2 === 0 ? 0.19 : 0.08) + coreEnergy * 0.11;
block.scale.setScalar(localScale);
});
// Pylons rise above or fall below their neutral baseline.
forcingPylons.forEach((pylon, i) => {
const localF = THREE.MathUtils.clamp(
forcing + Math.sin(i * 0.8) * 0.05,
-1,
1
);
const height = 0.32 + Math.abs(localF) * 1.45;
pylon.scale.set(0.28, height, 0.28);
pylon.position.y = 1.15 + Math.sign(localF || 1) * height / 2;
});
// Signal packets travel from the abstract core toward the basin.
for (let i = 0; i < signalCount; i++) {
const t = (i / signalCount + elapsed * 0.095 * (forcing >= 0 ? 1 : -1)) % 1;
const normalizedT = (t + 1) % 1;
const pulse = Math.sin(normalizedT * Math.PI);
dummy.position.set(
Math.sin(normalizedT * Math.PI * 2) * 1.3 * (1 - normalizedT),
9.0 * (1 - normalizedT) + level * normalizedT,
-14.5 + normalizedT * 10.5
);
dummy.rotation.set(0, elapsed + i, 0);
dummy.scale.setScalar(0.12 + pulse * (0.13 + coreEnergy * 0.13));
dummy.updateMatrix();
signalMesh.setMatrixAt(i, dummy.matrix);
}
signalMesh.instanceMatrix.needsUpdate = true;
lighthouseLight.intensity =
13 + Math.pow(Math.max(0, Math.sin(elapsed * 1.4)), 8) * 16;
stars.rotation.y = elapsed * 0.002;
updateTelemetry();
drawChart();
renderer.render(scene, camera);
}
drawChart();
updateTelemetry();
animate();
requestAnimationFrame(() => {
$("loading").classList.add("hidden");
});
</script>
</body>
</html>
```