Prompt specification
Build or customize the Three.js 3D scene "Compare synchronized and staggered rowing" 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: Compare synchronized and staggered rowing
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/compare-synchronized-and-staggered-rowing-x2264
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Athenian triremes and coordinated rowing crews. Let users change the phase relationship between schematic rowers. Visualize combined thrust under an explicitly simplified model and show why coordination affects the resulting force pattern. Low-poly.
Working Three.js Starter (compare-synchronized-and-staggered-rowing-x2264):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Trireme Phase Lab</title>
<style>
:root {
--ink: #07151d;
--panel: rgba(8, 23, 31, 0.91);
--panel-edge: rgba(224, 189, 111, 0.22);
--gold: #e6b65d;
--gold-bright: #ffd98a;
--cream: #f4eedf;
--muted: #9eb0b4;
--teal: #50dfcf;
--amber: #ffb454;
--danger: #ff776b;
--phase-progress: 50%;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--ink);
color: var(--cream);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body::after {
content: "";
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
background:
radial-gradient(circle at 52% 42%, transparent 25%, rgba(1, 10, 15, 0.13) 72%),
linear-gradient(180deg, rgba(2, 13, 20, 0.08), rgba(2, 10, 15, 0.2));
}
#stage {
position: fixed;
inset: 0;
z-index: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 5;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.5);
}
.brand-mark {
display: grid;
place-items: center;
width: 44px;
height: 44px;
border: 1px solid rgba(230, 182, 93, 0.62);
border-radius: 50%;
color: var(--gold-bright);
font: 25px/1 Georgia, serif;
background: rgba(7, 21, 29, 0.56);
box-shadow: inset 0 0 20px rgba(230, 182, 93, 0.08);
}
.eyebrow {
margin-bottom: 4px;
color: var(--gold);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font: 400 clamp(22px, 2.3vw, 34px)/1.05 Georgia, "Times New Roman", serif;
letter-spacing: 0.015em;
}
.top-actions {
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
}
.ship-tag {
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 999px;
color: #dbe4e3;
background: rgba(7, 21, 29, 0.62);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.ship-tag::before {
content: "";
display: inline-block;
width: 7px;
height: 7px;
margin-right: 7px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 10px var(--gold);
}
.icon-button {
min-height: 36px;
padding: 0 13px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 9px;
color: var(--cream);
background: rgba(7, 21, 29, 0.72);
font: inherit;
font-size: 11px;
cursor: pointer;
transition: border-color 160ms ease, background 160ms ease;
}
.icon-button:hover {
border-color: rgba(230, 182, 93, 0.7);
background: rgba(22, 40, 48, 0.9);
}
.panel {
position: fixed;
z-index: 4;
border: 1px solid var(--panel-edge);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.3),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.controls {
top: 96px;
left: 24px;
width: 340px;
max-height: calc(100vh - 120px);
padding: 19px;
overflow: auto;
scrollbar-width: thin;
scrollbar-color: rgba(230, 182, 93, 0.35) transparent;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 18px;
}
.panel-heading h2,
.force-heading h2 {
margin: 0 0 5px;
font: 400 20px/1.1 Georgia, "Times New Roman", serif;
}
.panel-heading p,
.force-heading p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.phase-readout {
min-width: 64px;
padding: 7px 9px;
border: 1px solid rgba(230, 182, 93, 0.32);
border-radius: 9px;
color: var(--gold-bright);
background: rgba(230, 182, 93, 0.07);
font-variant-numeric: tabular-nums;
font-size: 19px;
font-weight: 750;
text-align: center;
}
.status-pill {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 13px;
color: #dce8e6;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 12px rgba(80, 223, 207, 0.75);
}
.status-pill[data-tone="warning"] .status-dot {
background: var(--amber);
box-shadow: 0 0 12px rgba(255, 180, 84, 0.75);
}
.status-pill[data-tone="danger"] .status-dot {
background: var(--danger);
box-shadow: 0 0 12px rgba(255, 119, 107, 0.75);
}
.range-wrap {
margin: 0 0 15px;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 8px 0 7px;
border-radius: 99px;
outline: none;
appearance: none;
-webkit-appearance: none;
cursor: pointer;
background: linear-gradient(
90deg,
var(--gold) 0%,
var(--gold) var(--phase-progress),
rgba(255, 255, 255, 0.13) var(--phase-progress),
rgba(255, 255, 255, 0.13) 100%
);
}
input[type="range"]::-webkit-slider-thumb {
width: 20px;
height: 20px;
border: 3px solid #102b34;
border-radius: 50%;
appearance: none;
-webkit-appearance: none;
background: var(--gold-bright);
box-shadow: 0 0 0 1px rgba(255, 217, 138, 0.72),
0 0 18px rgba(230, 182, 93, 0.35);
}
input[type="range"]::-moz-range-thumb {
width: 16px;
height: 16px;
border: 3px solid #102b34;
border-radius: 50%;
background: var(--gold-bright);
box-shadow: 0 0 0 1px rgba(255, 217, 138, 0.72),
0 0 18px rgba(230, 182, 93, 0.35);
}
.range-labels {
display: flex;
justify-content: space-between;
color: #758b90;
font-size: 9px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.presets {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin-bottom: 18px;
}
.preset {
min-height: 38px;
padding: 6px 4px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 9px;
color: #c9d5d4;
background: rgba(255, 255, 255, 0.035);
font: inherit;
font-size: 9px;
font-weight: 700;
line-height: 1.25;
cursor: pointer;
transition: 150ms ease;
}
.preset span {
display: block;
margin-top: 2px;
color: #71878c;
font-size: 8px;
font-weight: 600;
}
.preset:hover,
.preset[aria-pressed="true"] {
border-color: rgba(230, 182, 93, 0.72);
color: var(--gold-bright);
background: rgba(230, 182, 93, 0.09);
}
.section-rule {
height: 1px;
margin: 17px 0;
background: linear-gradient(90deg, rgba(230, 182, 93, 0.35), transparent);
}
.metrics {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 8px;
}
.metric {
min-height: 68px;
padding: 10px 11px;
border: 1px solid rgba(255, 255, 255, 0.075);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.metric-label {
display: block;
margin-bottom: 6px;
color: #82979b;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.metric-value {
display: block;
font-size: 18px;
font-weight: 720;
font-variant-numeric: tabular-nums;
letter-spacing: -0.02em;
}
.metric-value.resultant {
color: var(--gold-bright);
}
.metric-value.forward {
color: var(--teal);
}
.metric-value.transverse {
color: var(--amber);
}
.formula {
margin-top: 16px;
padding: 11px 12px;
border-left: 2px solid var(--gold);
border-radius: 0 8px 8px 0;
color: #c2cecc;
background: rgba(230, 182, 93, 0.055);
font: 11px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.formula strong {
color: var(--gold-bright);
font-weight: 700;
}
.force-card {
top: 96px;
right: 24px;
width: 300px;
padding: 18px;
}
.force-heading {
margin-bottom: 10px;
}
#forcePlot {
display: block;
width: 100%;
height: auto;
margin: 3px 0 4px;
overflow: visible;
}
.plot-axis {
stroke: rgba(255, 255, 255, 0.13);
stroke-width: 1;
}
.plot-grid {
fill: none;
stroke: rgba(255, 255, 255, 0.08);
stroke-width: 1;
stroke-dasharray: 3 4;
}
.plot-label {
fill: #81969a;
font: 9px ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.08em;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 9px 15px;
margin: 4px 0 15px;
color: #a8b8b8;
font-size: 9px;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 17px;
height: 3px;
border-radius: 99px;
background: currentColor;
}
.legend .a {
color: var(--teal);
}
.legend .b {
color: var(--amber);
}
.legend .r {
color: var(--cream);
}
.force-note {
padding-top: 13px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: #92a6a8;
font-size: 10px;
line-height: 1.6;
}
.force-note strong {
color: #d6dfdc;
}
.model-note {
position: fixed;
z-index: 3;
right: 24px;
bottom: 22px;
width: min(470px, calc(100vw - 48px));
padding: 12px 14px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 11px;
color: #9badae;
background: rgba(6, 18, 25, 0.68);
font-size: 10px;
line-height: 1.55;
backdrop-filter: blur(10px);
}
.model-note strong {
color: var(--gold);
}
.view-hint {
position: fixed;
z-index: 3;
left: 50%;
bottom: 23px;
transform: translateX(-50%);
padding: 8px 12px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 999px;
color: #91a4a6;
background: rgba(6, 18, 25, 0.6);
font-size: 9px;
letter-spacing: 0.04em;
white-space: nowrap;
pointer-events: none;
}
@media (max-width: 1120px) {
.force-card {
display: none;
}
}
@media (max-width: 720px) {
.topbar {
top: 12px;
left: 12px;
right: 12px;
}
.brand-mark {
width: 37px;
height: 37px;
font-size: 21px;
}
.brand {
gap: 9px;
}
.eyebrow {
font-size: 8px;
}
h1 {
font-size: 21px;
}
.ship-tag {
display: none;
}
.icon-button {
padding: 0 10px;
}
.controls {
top: 73px;
left: 12px;
width: min(330px, calc(100vw - 24px));
max-height: calc(100vh - 91px);
padding: 15px;
}
.model-note,
.view-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">Δ</div>
<div>
<div class="eyebrow">Athenian Fleet · Rowing Dynamics</div>
<h1>Trireme Phase Lab</h1>
</div>
</div>
<div class="top-actions">
<div class="ship-tag">Gold hull · active test crew</div>
<button class="icon-button" id="resetView" type="button">Reset view</button>
</div>
</header>
<section class="panel controls" aria-label="Phase controls and thrust measurements">
<div class="panel-heading">
<div>
<h2>Crew phase offset</h2>
<p>Rotate bank B relative to reference bank A.</p>
</div>
<output class="phase-readout" id="phaseValue" for="phase">0°</output>
</div>
<div class="status-pill" id="statusPill" data-tone="good" aria-live="polite">
<span class="status-dot"></span>
<span id="statusText">Full coherence</span>
</div>
<div class="range-wrap">
<input
id="phase"
type="range"
min="-180"
max="180"
step="1"
value="0"
aria-label="Phase difference between rowing banks"
>
<div class="range-labels">
<span>−180°</span>
<span>Reference</span>
<span>+180°</span>
</div>
</div>
<div class="presets" aria-label="Phase presets">
<button class="preset" data-phase="0" aria-pressed="true" type="button">
Sync<span>0°</span>
</button>
<button class="preset" data-phase="90" aria-pressed="false" type="button">
Quarter<span>90°</span>
</button>
<button class="preset" data-phase="120" aria-pressed="false" type="button">
Three-beat<span>120°</span>
</button>
<button class="preset" data-phase="180" aria-pressed="false" type="button">
Opposed<span>180°</span>
</button>
</div>
<div class="section-rule"></div>
<div class="metrics">
<div class="metric">
<span class="metric-label">Resultant magnitude</span>
<span class="metric-value resultant" id="resultantValue">18.00 kN</span>
</div>
<div class="metric">
<span class="metric-label">Forward component</span>
<span class="metric-value forward" id="forwardValue">18.00 kN</span>
</div>
<div class="metric">
<span class="metric-label">Transverse component</span>
<span class="metric-value transverse" id="transverseValue">0.00 kN</span>
</div>
<div class="metric">
<span class="metric-label">Force lost to phase</span>
<span class="metric-value" id="lossValue">0.0%</span>
</div>
</div>
<div class="formula" aria-label="Simplified model">
<strong>Fnet</strong> = nF₀([1, 0] + [cos Δ, sin Δ])<br>
n = 18 visible rowers/bank<br>
F₀ = 500 N per schematic rower
</div>
</section>
<aside class="panel force-card" aria-label="Force vector diagram">
<div class="force-heading">
<h2>Effective force pattern</h2>
<p>Horizontal-plane view at the representative drive instant.</p>
</div>
<svg id="forcePlot" viewBox="-102 -88 204 176" role="img"
aria-label="Force vectors for bank A, bank B, and their resultant">
<defs>
<marker id="arrowTeal" markerWidth="6" markerHeight="6"
refX="5" refY="3" orient="auto" markerUnits="strokeWidth">
<path d="M0,0 L0,6 L6,3 z" fill="#50dfcf"></path>
</marker>
<marker id="arrowAmber" markerWidth="6" markerHeight="6"
refX="5" refY="3" orient="auto" markerUnits="strokeWidth">
<path d="M0,0 L0,6 L6,3 z" fill="#ffb454"></path>
</marker>
<marker id="arrowWhite" markerWidth="6" markerHeight="6"
refX="5" refY="3" orient="auto" markerUnits="strokeWidth">
<path d="M0,0 L0,6 L6,3 z" fill="#f4eedf"></path>
</marker>
</defs>
<circle class="plot-grid" cx="0" cy="0" r="42"></circle>
<circle class="plot-grid" cx="0" cy="0" r="84"></circle>
<line class="plot-axis" x1="-91" y1="0" x2="96" y2="0"></line>
<line class="plot-axis" x1="0" y1="-74" x2="0" y2="74"></line>
<text class="plot-label" x="79" y="-10">FORWARD</text>
<text class="plot-label" x="-85" y="-10">AFT</text>
<text class="plot-label" x="7" y="-67">TRANSVERSE</text>
<line id="bankALine" x1="0" y1="0" x2="42" y2="0"
stroke="#50dfcf" stroke-width="3" marker-end="url(#arrowTeal)"></line>
<line id="bankBLine" x1="0" y1="0" x2="42" y2="0"
stroke="#ffb454" stroke-width="3" marker-end="url(#arrowAmber)"></line>
<line id="resultLine" x1="0" y1="0" x2="84" y2="0"
stroke="#f4eedf" stroke-width="3.5" marker-end="url(#arrowWhite)"></line>
<circle cx="0" cy="0" r="3.5" fill="#07151d" stroke="#f4eedf"
stroke-width="1.5"></circle>
</svg>
<div class="legend">
<span class="a"><i></i>Bank A</span>
<span class="b"><i></i>Bank B</span>
<span class="r"><i></i>Resultant</span>
</div>
<div class="force-note">
<strong>Why phase matters:</strong>
aligned drive vectors add toward the bow. Rotating one bank spreads
its force across forward and transverse directions; at 180°, the
two model vectors cancel completely.
</div>
</aside>
<div class="model-note">
<strong>Explicitly simplified model.</strong>
Each bank contributes a fixed polar drive vector at the shown instant.
The model omits hull resistance, oar hydrodynamics, stroke duration,
and real port/starboard force mirroring. It is a phase-coherence
demonstration rather than a fluid simulation.
</div>
<div class="view-hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const phaseInput = document.getElementById("phase");
const phaseValue = document.getElementById("phaseValue");
const statusPill = document.getElementById("statusPill");
const statusText = document.getElementById("statusText");
const resultantValue = document.getElementById("resultantValue");
const forwardValue = document.getElementById("forwardValue");
const transverseValue = document.getElementById("transverseValue");
const lossValue = document.getElementById("lossValue");
const bankALine = document.getElementById("bankALine");
const bankBLine = document.getElementById("bankBLine");
const resultLine = document.getElementById("resultLine");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
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.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly scene of Athenian triremes and coordinated rowing crews"
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b2632);
scene.fog = new THREE.Fog(0x0b2632, 25, 72);
const camera = new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
0.1,
120
);
const cameraState = {
target: new THREE.Vector3(0, 0.45, 0),
desiredTarget: new THREE.Vector3(0, 0.45, 0),
theta: 0.64,
desiredTheta: 0.64,
phi: 1.03,
desiredPhi: 1.03,
radius: 18.5,
desiredRadius: 18.5
};
function updateCamera(dt) {
const smoothing = 1 - Math.exp(-dt * 9);
cameraState.theta +=
(cameraState.desiredTheta - cameraState.theta) * smoothing;
cameraState.phi +=
(cameraState.desiredPhi - cameraState.phi) * smoothing;
cameraState.radius +=
(cameraState.desiredRadius - cameraState.radius) * smoothing;
cameraState.target.lerp(
cameraState.desiredTarget,
smoothing
);
const { radius, phi, theta, target } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
const hemisphere = new THREE.HemisphereLight(0x9ed7e5, 0x17222a, 2.05);
scene.add(hemisphere);
const sunLight = new THREE.DirectionalLight(0xffe0a1, 3.1);
sunLight.position.set(10, 16, 8);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(1024, 1024);
sunLight.shadow.camera.left = -18;
sunLight.shadow.camera.right = 18;
sunLight.shadow.camera.top = 18;
sunLight.shadow.camera.bottom = -18;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 48;
sunLight.shadow.bias = -0.0008;
scene.add(sunLight);
const rimLight = new THREE.DirectionalLight(0x58b9d1, 1.0);
rimLight.position.set(-10, 8, -12);
scene.add(rimLight);
const materials = {
hull: new THREE.MeshStandardMaterial({
color: 0x282a28,
roughness: 0.86,
metalness: 0.08,
flatShading: true,
side: THREE.DoubleSide
}),
hullStripe: new THREE.MeshStandardMaterial({
color: 0x873d31,
roughness: 0.8,
flatShading: true
}),
deck: new THREE.MeshStandardMaterial({
color: 0xa97943,
roughness: 0.92,
flatShading: true,
side: THREE.DoubleSide
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x513523,
roughness: 0.9,
flatShading: true
}),
oar: new THREE.MeshStandardMaterial({
color: 0xc69a5c,
roughness: 0.85,
flatShading: true
}),
blade: new THREE.MeshStandardMaterial({
color: 0x6d4930,
roughness: 0.94,
flatShading: true
}),
gold: new THREE.MeshStandardMaterial({
color: 0xe6b65d,
roughness: 0.43,
metalness: 0.48,
flatShading: true
}),
skin: new THREE.MeshStandardMaterial({
color: 0xc9946b,
roughness: 0.88,
flatShading: true
}),
tunic: new THREE.MeshStandardMaterial({
color: 0xe8ddc4,
roughness: 0.93,
flatShading: true
}),
cohortA: new THREE.MeshStandardMaterial({
color: 0x50dfcf,
roughness: 0.66,
flatShading: true
}),
cohortB: new THREE.MeshStandardMaterial({
color: 0xffb454,
roughness: 0.66,
flatShading: true
}),
sail: new THREE.MeshStandardMaterial({
color: 0xe9dfc2,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
})
};
const torsoGeometry = new THREE.BoxGeometry(0.24, 0.34, 0.17);
const headGeometry = new THREE.DodecahedronGeometry(0.125, 0);
const shoulderGeometry = new THREE.BoxGeometry(0.26, 0.075, 0.19);
const legGeometry = new THREE.BoxGeometry(0.075, 0.19, 0.075);
const oarShaftGeometry = new THREE.CylinderGeometry(
0.025, 0.035, 2.05, 6, 1, false
);
oarShaftGeometry.rotateX(Math.PI / 2);
const bladeGeometry = new THREE.BoxGeometry(0.13, 0.3, 0.42);
const stations = [
{ x: -6.6, w: 0.10, top: 0.92, keel: -0.74 },
{ x: -5.5, w: 0.72, top: 0.70, keel: -0.82 },
{ x: -3.8, w: 1.20, top: 0.49, keel: -0.86 },
{ x: -1.5, w: 1.42, top: 0.42, keel: -0.84 },
{ x: 1.8, w: 1.36, top: 0.48, keel: -0.78 },
{ x: 3.8, w: 1.13, top: 0.64, keel: -0.69 },
{ x: 5.35, w: 0.61, top: 0.86, keel: -0.59 },
{ x: 6.6, w: 0.07, top: 1.04, keel: -0.47 }
];
function makeHullGeometry() {
const positions = [];
const indices = [];
const ringSize = 7;
for (const station of stations) {
const { x, w, top, keel } = station;
const span = top - keel;
const ring = [
[0, keel],
[w * 0.55, keel + span * 0.25],
[w, keel + span * 0.62],
[w * 0.9, top],
[-w * 0.9, top],
[-w, keel + span * 0.62],
[-w * 0.55, keel + span * 0.25]
];
for (const [z, y] of ring) {
positions.push(x, y, z);
}
}
for (let i = 0; i < stations.length - 1; i++) {
for (const j of [0, 1, 2, 4, 5, 6]) {
const next = (j + 1) % ringSize;
const a = i * ringSize + j;
const b = (i + 1) * ringSize + j;
const c = (i + 1) * ringSize + next;
const d = i * ringSize + next;
indices.push(a, b, d, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function makeDeckGeometry() {
const positions = [];
const indices = [];
for (const station of stations) {
positions.push(
station.x, station.top + 0.015, station.w * 0.9,
station.x, station.top + 0.015, -station.w * 0.9
);
}
for (let i = 0; i < stations.length - 1; i++) {
const a = i * 2;
const b = i * 2 + 1;
const c = (i + 1) * 2;
const d = (i + 1) * 2 + 1;
indices.push(a, c, b, b, c, d);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const hullGeometry = makeHullGeometry();
const deckGeometry = makeDeckGeometry();
function addBeam(
parent,
start,
end,
radius,
material,
radialSegments = 6
) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius, radius, length, radialSegments, 1, false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addWake(ship) {
const wakeMaterial = new THREE.LineBasicMaterial({
color: 0xbbe4df,
transparent: true,
opacity: 0.28
});
for (const side of [-1, 1]) {
for (const spread of [0.6, 1.25, 1.9]) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-6.1, -0.1, side * 0.45),
new THREE.Vector3(-8.4, -0.1, side * spread),
new THREE.Vector3(-10.7, -0.1, side * (spread + 0.75))
]);
const line = new THREE.Line(geometry, wakeMaterial);
ship.add(line);
}
}
}
function addOar(parent, side, x, y, z) {
const pivot = new THREE.Group();
pivot.position.set(x, y, z);
parent.add(pivot);
const shaft = new THREE.Mesh(oarShaftGeometry, materials.oar);
shaft.position.z = side * 1.025;
shaft.castShadow = true;
pivot.add(shaft);
const blade = new THREE.Mesh(bladeGeometry, materials.blade);
blade.position.z = side * 2.08;
blade.castShadow = true;
pivot.add(blade);
return pivot;
}
function addRower(parent, side, x, y, z, cohort, rowers) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
const body = new THREE.Group();
group.add(body);
const torso = new THREE.Mesh(torsoGeometry, materials.tunic);
torso.position.y = 0.27;
torso.castShadow = true;
body.add(torso);
const head = new THREE.Mesh(headGeometry, materials.skin);
head.position.set(0.015, 0.54, 0);
head.castShadow = true;
body.add(head);
const shoulder = new THREE.Mesh(
shoulderGeometry,
cohort === 0 ? materials.cohortA : materials.cohortB
);
shoulder.position.y = 0.42;
shoulder.castShadow = true;
body.add(shoulder);
const legA = new THREE.Mesh(legGeometry, materials.skin);
legA.position.set(-0.07, 0.08, -0.065);
body.add(legA);
const legB = new THREE.Mesh(legGeometry, materials.skin);
legB.position.set(-0.07, 0.08, 0.065);
body.add(legB);
const pivot = addOar(group, side, 0, 0.24, 0);
rowers.push({
pivot,
body,
side,
cohort,
baseX: x
});
}
function addSail(ship) {
const x = -0.65;
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
x, 3.05, 0,
x, 0.92, 1.85,
x, 0.92, -1.85
], 3)
);
geometry.computeVertexNormals();
const sail = new THREE.Mesh(geometry, materials.sail);
sail.castShadow = true;
ship.add(sail);
addBeam(
ship,
new THREE.Vector3(x, 0.45, 0),
new THREE.Vector3(x, 3.35, 0),
0.065,
materials.darkWood,
7
);
addBeam(
ship,
new THREE.Vector3(x, 2.95, -2.05),
new THREE.Vector3(x, 2.95, 2.05),
0.045,
materials.darkWood,
6
);
}
function createTrireme(detailed, withSail = false) {
const ship = new THREE.Group();
const rowers = [];
const hull = new THREE.Mesh(hullGeometry, materials.hull);
hull.castShadow = true;
hull.receiveShadow = true;
ship.add(hull);
const deck = new THREE.Mesh(deckGeometry, materials.deck);
deck.castShadow = true;
deck.receiveShadow = true;
ship.add(deck);
for (const side of [-1, 1]) {
const railPoints = [];
const stripePoints = [];
for (const station of stations) {
railPoints.push(
new THREE.Vector3(
station.x,
station.top + 0.07,
side * station.w * 0.91
)
);
const y =
station.keel +
(station.top - station.keel) * 0.46;
stripePoints.push(
new THREE.Vector3(station.x, y, side * station.w * 0.98)
);
}
for (let i = 0; i < railPoints.length - 1; i++) {
addBeam(
ship,
railPoints[i],
railPoints[i + 1],
0.045,
materials.gold,
6
);
addBeam(
ship,
stripePoints[i],
stripePoints[i + 1],
0.075,
materials.hullStripe,
6
);
}
for (let i = 0; i < 6; i++) {
const station = stations[2 + (i % 4)];
const shield = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.13, 0.035, 8),
i % 2 === 0 ? materials.hullStripe : materials.gold
);
shield.rotation.x = Math.PI / 2;
shield.position.set(
station.x - 1.1 + i * 0.86,
station.top + 0.02,
side * (station.w * 0.93)
);
shield.castShadow = true;
ship.add(shield);
}
}
const ram = new THREE.Mesh(
new THREE.ConeGeometry(0.28, 1.65, 7),
materials.gold
);
ram.rotation.z = -Math.PI / 2;
ram.position.set(7.02, -0.14, 0);
ram.castShadow = true;
ship.add(ram);
const ramBase = new THREE.Mesh(
new THREE.CylinderGeometry(0.3, 0.36, 0.7, 7),
materials.hullStripe
);
ramBase.rotation.z = -Math.PI / 2;
ramBase.position.set(6.35, -0.12, 0);
ship.add(ramBase);
for (const side of [-1, 1]) {
const eye = new THREE.Mesh(
new THREE.SphereGeometry(0.15, 8, 6),
materials.gold
);
eye.scale.z = 0.35;
eye.position.set(5.95, 0.82, side * 0.5);
eye.castShadow = true;
ship.add(eye);
const pupil = new THREE.Mesh(
new THREE.SphereGeometry(0.064, 7, 5),
materials.hull
);
pupil.scale.z = 0.3;
pupil.position.set(6.02, 0.82, side * 0.565);
ship.add(pupil);
}
const sternPost = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 1.15, 0.18),
materials.gold
);
sternPost.position.set(-5.75, 1.2, 0);
sternPost.rotation.z = -0.17;
sternPost.castShadow = true;
ship.add(sternPost);
const sternHouse = new THREE.Mesh(
new THREE.BoxGeometry(1.35, 0.58, 1.55),
materials.darkWood
);
sternHouse.position.set(-4.9, 0.93, 0);
sternHouse.castShadow = true;
ship.add(sternHouse);
const cabinRoof = new THREE.Mesh(
new THREE.BoxGeometry(1.55, 0.13, 1.72),
materials.gold
);
cabinRoof.position.set(-4.9, 1.27, 0);
cabinRoof.castShadow = true;
ship.add(cabinRoof);
if (withSail) {
addSail(ship);
} else {
addBeam(
ship,
new THREE.Vector3(-0.7, 0.45, 0),
new THREE.Vector3(-0.7, 2.75, 0),
0.055,
materials.darkWood,
7
);
const furledSail = new THREE.Mesh(
new THREE.BoxGeometry(0.14, 0.12, 2.1),
materials.sail
);
furledSail.position.set(-0.7, 2.62, 0);
furledSail.castShadow = true;
ship.add(furledSail);
}
const bankSettings = [
{ y: 0.53, z: 1.05, offset: -0.35 },
{ y: 0.87, z: 0.82, offset: 0.0 },
{ y: 1.21, z: 0.60, offset: 0.35 }
];
for (let bank = 0; bank < bankSettings.length; bank++) {
const { y, z, offset } = bankSettings[bank];
for (const side of [-1, 1]) {
const bench = new THREE.Mesh(
new THREE.BoxGeometry(8.5, 0.09, 0.16),
materials.darkWood
);
bench.position.set(0, y - 0.12, side * z);
bench.castShadow = true;
bench.receiveShadow = true;
ship.add(bench);
const xPositions = [-3.9, -2.5, -1.1, 0.3, 1.7, 3.1];
for (let i = 0; i < xPositions.length; i++) {
const x = xPositions[i] + offset;
if (detailed) {
addRower(
ship,
side,
x,
y,
side * z,
side < 0 ? 0 : 1,
rowers
);
} else {
addOar(ship, side, x, y, side * z);
}
}
}
}
addWake(ship);
return { ship, rowers };
}
// Faceted sea.
const seaGeometry = new THREE.PlaneGeometry(110, 110, 42, 42);
const seaPosition = seaGeometry.attributes.position;
const seaColors = [];
for (let i = 0; i < seaPosition.count; i++) {
const x = seaPosition.getX(i);
const y = seaPosition.getY(i);
const wave =
Math.sin(x * 0.33 + y * 0.17) * 0.065 +
Math.sin(x * 0.11 - y * 0.28) * 0.045;
seaPosition.setZ(i, wave);
const shade =
0.88 +
Math.sin(x * 0.19 + y * 0.23) * 0.055 +
Math.sin(y * 0.47) * 0.025;
seaColors.push(
0.065 * shade,
0.285 * shade,
0.335 * shade
);
}
seaGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(seaColors, 3)
);
seaGeometry.computeVertexNormals();
seaGeometry.rotateX(-Math.PI / 2);
const sea = new THREE.Mesh(
seaGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.92,
metalness: 0.08,
flatShading: true
})
);
sea.position.y = -0.16;
sea.receiveShadow = true;
scene.add(sea);
// Distant low-poly islands and a warm sun.
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x4b5b52,
roughness: 1,
flatShading: true
});
const islandData = [
[-19, -0.3, -25, 3.6, 1.6, 2.7],
[-25, -0.7, -28, 5.3, 2.2, 3.6],
[20, -0.45, -31, 5.2, 1.9, 3.2],
[30, -0.6, -38, 7.1, 2.5, 4.7]
];
for (const [x, y, z, sx, sy, sz] of islandData) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(1, 0),
rockMaterial
);
rock.position.set(x, y, z);
rock.scale.set(sx, sy, sz);
rock.rotation.set(0.1, x * 0.2, 0.05);
rock.receiveShadow = true;
scene.add(rock);
}
const sunDisc = new THREE.Mesh(
new THREE.DodecahedronGeometry(2.4, 1),
new THREE.MeshBasicMaterial({ color: 0xffd089 })
);
sunDisc.position.set(-24, 17, -42);
scene.add(sunDisc);
const main = createTrireme(true, false);
const mainShip = main.ship;
const rowers = main.rowers;
scene.add(mainShip);
const backgroundOne = createTrireme(false, true);
backgroundOne.ship.position.set(-10.5, 0, -10.5);
backgroundOne.ship.rotation.y = 0.25;
backgroundOne.ship.scale.setScalar(0.76);
scene.add(backgroundOne.ship);
const backgroundTwo = createTrireme(false, true);
backgroundTwo.ship.position.set(10.8, 0, -15.5);
backgroundTwo.ship.rotation.y = -0.34;
backgroundTwo.ship.scale.setScalar(0.64);
scene.add(backgroundTwo.ship);
// Hovering force-vector rig above the active ship.
const forceRig = new THREE.Group();
forceRig.position.set(0, 3.25, 0);
scene.add(forceRig);
const forceOrigin = new THREE.Vector3(0, 0, 0);
const forceA = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
forceOrigin,
4,
0x50dfcf,
0.48,
0.28
);
const forceB = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
forceOrigin,
4,
0xffb454,
0.48,
0.28
);
const forceResult = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
forceOrigin,
8,
0xf4eedf,
0.58,
0.34
);
forceRig.add(forceA, forceB, forceResult);
const forceRing = new THREE.Mesh(
new THREE.RingGeometry(1.45, 1.55, 32),
new THREE.MeshBasicMaterial({
color: 0xf4eedf,
transparent: true,
opacity: 0.35,
side: THREE.DoubleSide
})
);
forceRing.rotation.x = -Math.PI / 2;
forceRig.add(forceRing);
const bankMagnitude = 18 * 500;
const maximumMagnitude = bankMagnitude * 2;
let phaseOffset = 0;
function formatForce(value) {
const sign = value < 0 ? "−" : "";
const absolute = Math.abs(value);
return `${sign}${(absolute / 1000).toFixed(2)} kN`;
}
function updatePhase() {
const degrees = Number(phaseInput.value);
phaseOffset = THREE.MathUtils.degToRad(degrees);
const cosine = Math.cos(phaseOffset);
const sine = Math.sin(phaseOffset);
const forward = bankMagnitude * (1 + cosine);
const transverse = bankMagnitude * sine;
const magnitude = Math.hypot(forward, transverse);
const loss = THREE.MathUtils.clamp(
1 - magnitude / maximumMagnitude,
0,
1
);
phaseValue.textContent = `${degrees > 0 ? "+" : ""}${degrees}°`;
document.documentElement.style.setProperty(
"--phase-progress",
`${((degrees + 180) / 360) * 100}%`
);
resultantValue.textContent = formatForce(magnitude);
forwardValue.textContent = formatForce(forward);
transverseValue.textContent = formatForce(transverse);
lossValue.textContent = `${(loss * 100).toFixed(1)}%`;
forwardValue.style.color =
forward < -1 ? "#ff776b" : "#50dfcf";
transverseValue.style.color =
Math.abs(transverse) < 1 ? "#ffb454" : "#ffb454";
let label = "Partial coherence";
let tone = "warning";
let description = "partial coherence";
if (Math.abs(degrees) <= 4) {
label = "Full coherence";
description = "full coherence";
tone = "good";
} else if (Math.abs(Math.abs(degrees) - 180) <= 4) {
label = "Complete cancellation";
description = "complete cancellation";
tone = "danger";
} else if (Math.abs(degrees) > 90) {
label = "Partial cancellation / reversal";
description = "partial cancellation";
tone = "danger";
} else {
label = "Partial coherence";
description = "partial coherence";
tone = "warning";
}
statusText.textContent = label;
statusPill.dataset.tone = tone;
statusPill.setAttribute("aria-label", description);
const directionB = new THREE.Vector3(cosine, 0, -sine);
forceB.setDirection(directionB);
forceB.setLength(4, 0.48, 0.28);
if (magnitude > 1) {
const resultDirection = new THREE.Vector3(
forward,
0,
-transverse
).normalize();
forceResult.visible = true;
forceResult.setDirection(resultDirection);
forceResult.setLength(
8 * magnitude / maximumMagnitude,
0.58,
0.34
);
} else {
forceResult.visible = false;
}
const plotLength = 42;
const bx = plotLength * cosine;
const by = -plotLength * sine;
bankALine.setAttribute("x2", plotLength);
bankALine.setAttribute("y2", 0);
bankBLine.setAttribute("x2", bx);
bankBLine.setAttribute("y2", by);
resultLine.setAttribute("x2", plotLength + bx);
resultLine.setAttribute("y2", by);
resultLine.style.opacity = magnitude < 1 ? "0" : "1";
for (const button of document.querySelectorAll(".preset")) {
button.setAttribute(
"aria-pressed",
String(Number(button.dataset.phase) === degrees)
);
}
}
phaseInput.addEventListener("input", updatePhase);
for (const button of document.querySelectorAll(".preset")) {
button.addEventListener("click", () => {
phaseInput.value = button.dataset.phase;
updatePhase();
});
}
updatePhase();
// Direct camera controls: no external controls addon.
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function resetCamera() {
cameraState.desiredTheta = 0.64;
cameraState.desiredPhi = 1.03;
cameraState.desiredRadius = 18.5;
cameraState.desiredTarget.set(0, 0.45, 0);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.desiredTheta -= dx * 0.006;
cameraState.desiredPhi = THREE.MathUtils.clamp(
cameraState.desiredPhi - dy * 0.005,
0.42,
1.42
);
});
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.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius + event.deltaY * 0.012,
10,
29
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("resetView").addEventListener("click", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
});
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
updateCamera(dt);
const rowCycle = elapsed * 2.65;
const shipBob = Math.sin(elapsed * 0.72) * 0.055;
mainShip.position.y = shipBob;
mainShip.rotation.z = Math.sin(elapsed * 0.48) * 0.008;
forceRig.position.y = 3.25 + shipBob;
for (const rower of rowers) {
const cohortPhase = rower.cohort === 1 ? phaseOffset : 0;
const stroke = rowCycle + cohortPhase;
rower.pivot.rotation.x =
rower.side * (0.44 + 0.25 * Math.sin(stroke));
rower.body.position.x =
-0.1 * Math.cos(stroke) - 0.02;
}
backgroundOne.ship.position.y =
Math.sin(elapsed * 0.51 + 1.3) * 0.045;
backgroundOne.ship.rotation.z =
Math.sin(elapsed * 0.34 + 1.3) * 0.006;
backgroundTwo.ship.position.y =
Math.sin(elapsed * 0.43 + 2.7) * 0.035;
backgroundTwo.ship.rotation.z =
Math.sin(elapsed * 0.39 + 2.7) * 0.005;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```