Prompt specification
Build or customize the Three.js 3D scene "Floating tracers around an island" 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: Floating tracers around an island
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/floating-tracers-around-an-island-x1230
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing ocean currents. Place an island obstacle in a shallow tank and animate tracers along predefined diverging paths; show convergence and recirculation qualitatively without claiming a fluid solver. Stylized solid forms.
Working Three.js Starter (floating-tracers-around-an-island-x1230):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Island Wake — Schematic Ocean Currents</title>
<style>
:root {
color-scheme: dark;
--bg: #06141d;
--panel: rgba(7, 25, 35, 0.84);
--panel-border: rgba(137, 220, 238, 0.18);
--text: #e9f8fb;
--muted: #91afb9;
--cyan: #42d9ff;
--blue: #658fff;
--violet: #c58aff;
--amber: #ffc56b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene {
display: block;
touch-action: none;
outline: none;
}
.panel {
position: absolute;
z-index: 10;
border: 1px solid var(--panel-border);
border-radius: 15px;
background: var(--panel);
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.25),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#info {
top: 22px;
left: 22px;
width: min(365px, calc(100vw - 44px));
padding: 20px 21px 18px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--cyan);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 14px rgba(66, 217, 255, 0.85);
content: "";
}
h1 {
margin: 0;
color: var(--text);
font-size: clamp(25px, 3vw, 34px);
font-weight: 670;
letter-spacing: -0.035em;
line-height: 1.05;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
display: grid;
gap: 8px;
margin-top: 17px;
padding-top: 15px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: #b9d0d7;
font-size: 11px;
}
.swatch {
width: 20px;
height: 3px;
flex: 0 0 auto;
border-radius: 999px;
background: var(--cyan);
box-shadow: 0 0 8px currentColor;
}
.swatch.violet {
color: var(--violet);
background: var(--violet);
}
.swatch.amber {
color: var(--amber);
background: var(--amber);
}
.disclaimer {
margin: 15px 0 0;
padding: 11px 12px;
border: 1px solid rgba(255, 197, 107, 0.17);
border-radius: 9px;
background: rgba(255, 197, 107, 0.055);
color: #c7b99e;
font-size: 10px;
line-height: 1.55;
}
.disclaimer strong {
color: var(--amber);
font-weight: 700;
}
#controls {
top: 22px;
right: 22px;
width: 245px;
padding: 15px;
}
.control-title {
margin-bottom: 13px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
min-height: 36px;
padding: 8px 10px;
border: 1px solid rgba(116, 211, 232, 0.2);
border-radius: 8px;
background: rgba(52, 170, 199, 0.1);
color: var(--text);
font: inherit;
font-size: 11px;
font-weight: 650;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(116, 211, 232, 0.42);
background: rgba(52, 170, 199, 0.18);
}
button:active {
transform: translateY(1px);
}
.range-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 15px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#speed-value {
color: var(--cyan);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
margin: 9px 0 13px;
accent-color: var(--cyan);
cursor: pointer;
}
.check-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 9px;
color: #b9d0d7;
font-size: 11px;
}
.check-row label {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
}
input[type="checkbox"] {
width: 14px;
height: 14px;
accent-color: var(--cyan);
}
#camera-hint {
position: absolute;
z-index: 8;
right: 24px;
bottom: 20px;
color: rgba(181, 208, 216, 0.68);
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
overflow: hidden;
pointer-events: none;
}
.annotation {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 8px;
border: 1px solid rgba(154, 218, 231, 0.14);
border-radius: 6px;
background: rgba(5, 20, 29, 0.74);
color: #d5e8ec;
font-size: 9px;
font-weight: 720;
letter-spacing: 0.12em;
line-height: 1;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -50%);
box-shadow: 0 5px 22px rgba(0, 0, 0, 0.2);
}
.annotation .dot {
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 8px currentColor;
}
.annotation .dot.violet {
color: var(--violet);
background: var(--violet);
}
.annotation .dot.cyan {
color: var(--cyan);
background: var(--cyan);
}
@media (max-width: 760px) {
#info {
top: 13px;
left: 13px;
width: calc(100vw - 26px);
padding: 15px 16px;
}
h1 {
font-size: 25px;
}
.subtitle {
max-width: 90%;
font-size: 11px;
}
.legend {
display: none;
}
.disclaimer {
margin-top: 10px;
padding: 8px 10px;
font-size: 9px;
}
#controls {
top: auto;
right: 13px;
bottom: 13px;
width: min(245px, calc(100vw - 26px));
padding: 12px;
}
.control-title {
margin-bottom: 8px;
}
#camera-hint {
display: none;
}
.annotation {
padding: 5px 6px;
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="app">
<div id="labels"></div>
<section id="info" class="panel">
<div class="eyebrow">Qualitative path model</div>
<h1>Island Wake</h1>
<p class="subtitle">
Tracers follow predefined paths around a solid island, separating in
front of the obstacle and gathering again in its wake.
</p>
<div class="legend">
<div class="legend-row">
<span class="swatch"></span>
<span>Predefined through-flow paths</span>
</div>
<div class="legend-row">
<span class="swatch violet"></span>
<span>Illustrative recirculation loop</span>
</div>
<div class="legend-row">
<span class="swatch amber"></span>
<span>Divergence and convergence regions</span>
</div>
</div>
<p class="disclaimer">
<strong>Path-driven illustration.</strong>
Motion is authored along splines. This is not a fluid solver and does
not calculate pressure, momentum, turbulence, or fluid dynamics.
</p>
</section>
<section id="controls" class="panel">
<div class="control-title">Current controls</div>
<div class="button-row">
<button id="play" type="button" aria-pressed="true">Pause</button>
<button id="reset" type="button">Reset view</button>
</div>
<div class="range-label">
<span>Tracer speed</span>
<span id="speed-value">1.00×</span>
</div>
<input
id="speed"
type="range"
min="0.25"
max="2.5"
step="0.05"
value="1"
aria-label="Tracer speed"
/>
<div class="check-row">
<label>
<input id="show-paths" type="checkbox" checked />
Flow guides
</label>
<label>
<input id="show-tracers" type="checkbox" checked />
Tracers
</label>
</div>
</section>
<div id="camera-hint">
Drag to orbit · Shift-drag to pan · Scroll to zoom
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const labelLayer = document.getElementById("labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x06141d);
scene.fog = new THREE.Fog(0x06141d, 27, 48);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.id = "scene";
renderer.domElement.setAttribute(
"aria-label",
"Interactive schematic tank showing ocean-current paths around an island"
);
app.prepend(renderer.domElement);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xbcefff, 0x07131a, 1.65));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.35);
keyLight.position.set(-5, 12, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0007;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x3acfff, 1.15);
rimLight.position.set(8, 5, -9);
scene.add(rimLight);
// ------------------------------------------------------------
// Camera controls, implemented locally without Three.js addons
// ------------------------------------------------------------
const orbit = {
theta: 0.09,
phi: 0.82,
radius: 20,
target: new THREE.Vector3(0, -0.12, 0)
};
const defaultRadius = () =>
window.innerWidth / window.innerHeight < 0.85 ? 27 : 20;
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetView() {
orbit.theta = 0.09;
orbit.phi = 0.82;
orbit.radius = defaultRadius();
orbit.target.set(0, -0.12, 0);
updateCamera();
}
let dragging = false;
let previousPointer = { x: 0, y: 0 };
const canvas = renderer.domElement;
canvas.style.touchAction = "none";
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointer.x = event.clientX;
previousPointer.y = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
previousPointer.x = event.clientX;
previousPointer.y = event.clientY;
if (event.shiftKey) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const vertical = new THREE.Vector3()
.crossVectors(right, forward)
.normalize();
const panScale = orbit.radius * 0.0013;
orbit.target.addScaledVector(right, -dx * panScale);
orbit.target.addScaledVector(vertical, dy * panScale);
} else {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.3,
1.34
);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.style.cursor = "grab";
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("pointerleave", (event) => {
if (!dragging) endDrag(event);
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
11,
34
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
canvas.style.cursor = "grab";
resetView();
// ------------------------------------------------------------
// Tank
// ------------------------------------------------------------
const tankGroup = new THREE.Group();
scene.add(tankGroup);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x0c2932,
roughness: 0.9,
metalness: 0.04
});
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0x123642,
roughness: 0.72,
metalness: 0.08
});
const rimMaterial = new THREE.MeshStandardMaterial({
color: 0x246274,
roughness: 0.58,
metalness: 0.14
});
const floor = new THREE.Mesh(
new THREE.BoxGeometry(19, 0.25, 10.8),
floorMaterial
);
floor.position.y = -1.18;
floor.receiveShadow = true;
tankGroup.add(floor);
function addWall(width, height, depth, x, y, z) {
const wall = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
wallMaterial
);
wall.position.set(x, y, z);
wall.castShadow = true;
wall.receiveShadow = true;
tankGroup.add(wall);
}
addWall(0.3, 1.45, 10.7, -9.35, -0.425, 0);
addWall(0.3, 1.45, 10.7, 9.35, -0.425, 0);
addWall(18.4, 1.45, 0.3, 0, -0.425, -5.2);
addWall(18.4, 1.45, 0.3, 0, -0.425, 5.2);
function addRim(width, depth, x, z) {
const rim = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.12, depth),
rimMaterial
);
rim.position.set(x, 0.36, z);
rim.castShadow = true;
tankGroup.add(rim);
}
addRim(0.42, 10.8, -9.35, 0);
addRim(0.42, 10.8, 9.35, 0);
addRim(18.9, 0.42, 0, -5.2);
addRim(18.9, 0.42, 0, 5.2);
const gridPositions = [];
for (let x = -9; x <= 9; x += 1) {
gridPositions.push(x, -1.045, -5, x, -1.045, 5);
}
for (let z = -5; z <= 5; z += 1) {
gridPositions.push(-9, -1.045, z, 9, -1.045, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x4d8b98,
transparent: true,
opacity: 0.15
})
);
tankGroup.add(grid);
const water = new THREE.Mesh(
new THREE.PlaneGeometry(18.35, 10.05),
new THREE.MeshPhongMaterial({
color: 0x1da9ca,
transparent: true,
opacity: 0.19,
shininess: 90,
specular: 0xb9f3ff,
depthWrite: false,
side: THREE.DoubleSide
})
);
water.rotation.x = -Math.PI / 2;
water.position.y = 0;
water.renderOrder = 2;
tankGroup.add(water);
const waterEdgePoints = [
new THREE.Vector3(-9.12, 0.015, -5.02),
new THREE.Vector3(9.12, 0.015, -5.02),
new THREE.Vector3(9.12, 0.015, 5.02),
new THREE.Vector3(-9.12, 0.015, 5.02)
];
const waterEdge = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(waterEdgePoints),
new THREE.LineBasicMaterial({
color: 0x7fe8ff,
transparent: true,
opacity: 0.48
})
);
tankGroup.add(waterEdge);
// ------------------------------------------------------------
// Stylized solid island
// ------------------------------------------------------------
const islandGroup = new THREE.Group();
scene.add(islandGroup);
const sandMaterial = new THREE.MeshStandardMaterial({
color: 0xb89a62,
roughness: 0.92,
flatShading: true
});
const landMaterial = new THREE.MeshStandardMaterial({
color: 0x4e8067,
roughness: 0.88,
flatShading: true
});
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x526769,
roughness: 0.95,
flatShading: true
});
const islandBase = new THREE.Mesh(
new THREE.CylinderGeometry(1.55, 2.05, 1.15, 14),
sandMaterial
);
islandBase.position.y = -0.425;
islandBase.castShadow = true;
islandBase.receiveShadow = true;
islandGroup.add(islandBase);
const islandMound = new THREE.Mesh(
new THREE.DodecahedronGeometry(1.25, 0),
landMaterial
);
islandMound.position.set(-0.1, 0.65, -0.02);
islandMound.scale.set(1.22, 0.9, 1.04);
islandMound.rotation.set(0.12, 0.42, -0.08);
islandMound.castShadow = true;
islandMound.receiveShadow = true;
islandGroup.add(islandMound);
const sideRockA = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.55, 0),
rockMaterial
);
sideRockA.position.set(0.9, 0.12, 0.55);
sideRockA.scale.set(0.85, 0.72, 1.0);
sideRockA.rotation.set(0.3, 0.2, 0.4);
sideRockA.castShadow = true;
islandGroup.add(sideRockA);
const sideRockB = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.38, 0),
rockMaterial
);
sideRockB.position.set(-1.0, 0.06, -0.55);
sideRockB.scale.set(1.0, 0.75, 0.9);
sideRockB.castShadow = true;
islandGroup.add(sideRockB);
// A small, low-poly palm provides a clear island silhouette.
const palm = new THREE.Group();
palm.position.set(0.25, 1.12, 0.02);
islandGroup.add(palm);
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x75583c,
roughness: 0.95,
flatShading: true
});
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0x2f7859,
roughness: 0.82,
flatShading: true,
side: THREE.DoubleSide
});
function addCylinderBetween(a, b, radiusTop, radiusBottom, material, parent) {
const direction = b.clone().sub(a);
const length = direction.length();
const cylinder = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
length,
7
),
material
);
cylinder.position.copy(a).add(b).multiplyScalar(0.5);
cylinder.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
cylinder.castShadow = true;
parent.add(cylinder);
return cylinder;
}
const trunkPoints = [
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0.08, 0.38, 0.02),
new THREE.Vector3(0.18, 0.77, 0.05),
new THREE.Vector3(0.31, 1.17, 0.08)
];
for (let i = 0; i < trunkPoints.length - 1; i++) {
addCylinderBetween(
trunkPoints[i],
trunkPoints[i + 1],
0.075 - i * 0.006,
0.105 - i * 0.006,
trunkMaterial,
palm
);
}
const palmTop = trunkPoints[trunkPoints.length - 1];
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const direction = new THREE.Vector3(
Math.cos(angle),
-0.18 - 0.08 * Math.sin(i * 2.1),
Math.sin(angle)
).normalize();
const leaf = new THREE.Mesh(
new THREE.ConeGeometry(0.24, 1.25, 4),
leafMaterial
);
leaf.position.copy(palmTop).addScaledVector(direction, 0.54);
leaf.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
leaf.castShadow = true;
palm.add(leaf);
}
const coconutMaterial = new THREE.MeshStandardMaterial({
color: 0x4a3527,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 3; i++) {
const coconut = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.11, 0),
coconutMaterial
);
coconut.position.set(
palmTop.x + (i - 1) * 0.12,
palmTop.y - 0.08,
palmTop.z + 0.08
);
palm.add(coconut);
}
// ------------------------------------------------------------
// Flow paths and tracers
// ------------------------------------------------------------
const flowGroup = new THREE.Group();
const tracerGroup = new THREE.Group();
scene.add(flowGroup, tracerGroup);
const UP = new THREE.Vector3(0, 1, 0);
const FORWARD = new THREE.Vector3(0, 0, 1);
const upperColor = new THREE.Color(0x3bd9ff);
const lowerColor = new THREE.Color(0x668fff);
const eddyColor = new THREE.Color(0xc58aff);
const tracerGeometry = new THREE.SphereGeometry(1, 10, 7);
const arrowGeometry = new THREE.ConeGeometry(0.095, 0.29, 8);
const upperTracerMaterial = new THREE.MeshStandardMaterial({
color: 0xbdf6ff,
emissive: 0x159fca,
emissiveIntensity: 1.15,
roughness: 0.38
});
const lowerTracerMaterial = new THREE.MeshStandardMaterial({
color: 0xd5dcff,
emissive: 0x3157d8,
emissiveIntensity: 1.1,
roughness: 0.38
});
const eddyTracerMaterial = new THREE.MeshStandardMaterial({
color: 0xf0dcff,
emissive: 0x8f40ca,
emissiveIntensity: 1.05,
roughness: 0.4
});
const tracers = [];
let randomSeed = 9147;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function branchPoints(sign) {
return [
[-9.0, 0.0],
[-6.8, 0.0],
[-4.8, sign * 0.08],
[-3.2, sign * 0.85],
[-1.8, sign * 2.1],
[-0.3, sign * 2.9],
[1.8, sign * 2.8],
[3.4, sign * 2.0],
[4.6, sign * 0.95],
[6.2, 0.0],
[9.0, 0.0]
].map(([x, z]) => new THREE.Vector3(x, 0.105, z));
}
function offsetCurve(baseCurve, offset) {
const points = [];
const sampleCount = 44;
for (let i = 0; i <= sampleCount; i++) {
const u = i / sampleCount;
const point = baseCurve.getPointAt(u);
const tangent = baseCurve.getTangentAt(u);
const normal = new THREE.Vector3(
-tangent.z,
0,
tangent.x
).normalize();
point.addScaledVector(normal, offset);
points.push(point);
}
return new THREE.CatmullRomCurve3(
points,
false,
"centripetal"
);
}
function addTube(curve, color, opacity = 0.24, closed = false) {
const geometry = new THREE.TubeGeometry(
curve,
closed ? 110 : 150,
closed ? 0.028 : 0.018,
6,
closed
);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
});
const mesh = new THREE.Mesh(geometry, material);
mesh.renderOrder = 3;
flowGroup.add(mesh);
return mesh;
}
function addDirectionArrows(curve, color, spacing = 1.55, closed = false) {
const length = curve.getLength();
const count = Math.max(3, Math.floor(length / spacing));
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.88
});
for (let i = 0; i < count; i++) {
const u = closed
? (i + 0.5) / count
: (i + 0.75) / count;
const point = curve.getPointAt(u % 1);
const tangent = curve.getTangentAt(u % 1).normalize();
const arrow = new THREE.Mesh(arrowGeometry, material);
arrow.position.copy(point);
arrow.position.y += 0.07;
arrow.quaternion.setFromUnitVectors(UP, tangent);
arrow.renderOrder = 4;
flowGroup.add(arrow);
}
}
function addTracers(
curve,
material,
count,
worldSpeed,
sizeMultiplier = 1
) {
const length = curve.getLength();
for (let i = 0; i < count; i++) {
const mesh = new THREE.Mesh(tracerGeometry, material);
const size = (0.84 + random() * 0.38) * sizeMultiplier;
mesh.scale.set(
0.065 * size,
0.038 * size,
0.19 * size
);
mesh.castShadow = false;
mesh.renderOrder = 5;
tracerGroup.add(mesh);
tracers.push({
curve,
length,
mesh,
phase: (i / count + random() * 0.055) % 1,
speed: worldSpeed * (0.91 + random() * 0.18)
});
}
}
function createBranch(sign, color, tracerMaterial) {
const baseCurve = new THREE.CatmullRomCurve3(
branchPoints(sign),
false,
"centripetal"
);
const strandOffsets = [-0.5, -0.25, 0, 0.25, 0.5];
for (const offset of strandOffsets) {
const strand = offsetCurve(baseCurve, offset);
addTube(strand, color, offset === 0 ? 0.3 : 0.19);
addTracers(
strand,
tracerMaterial,
4,
2.15,
offset === 0 ? 1.08 : 0.9
);
}
addDirectionArrows(baseCurve, color, 1.42);
return baseCurve;
}
createBranch(1, upperColor, upperTracerMaterial);
createBranch(-1, lowerColor, lowerTracerMaterial);
// A closed loop in the island's lee illustrates qualitative recirculation.
const eddyPoints = [];
for (let i = 0; i < 24; i++) {
const angle = (i / 24) * Math.PI * 2;
eddyPoints.push(
new THREE.Vector3(
2.88 + Math.cos(angle) * 1.02,
0.12,
Math.sin(angle) * 0.76
)
);
}
const eddyCurve = new THREE.CatmullRomCurve3(
eddyPoints,
true,
"centripetal"
);
addTube(eddyCurve, eddyColor, 0.5, true);
addDirectionArrows(eddyCurve, eddyColor, 0.95, true);
addTracers(eddyCurve, eddyTracerMaterial, 20, 0.8, 0.92);
// ------------------------------------------------------------
// Highlighted transition regions
// ------------------------------------------------------------
const zoneGroup = new THREE.Group();
scene.add(zoneGroup);
function addZone(x, z, scaleX, scaleZ, color) {
const geometry = new THREE.RingGeometry(0.82, 1, 64);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.26,
side: THREE.DoubleSide,
depthWrite: false
});
const ring = new THREE.Mesh(geometry, material);
ring.rotation.x = -Math.PI / 2;
ring.position.set(x, 0.024, z);
ring.scale.set(scaleX, scaleZ, 1);
ring.renderOrder = 4;
zoneGroup.add(ring);
return ring;
}
const divergenceRing = addZone(
-3.15,
0,
1.18,
0.57,
0xffc56b
);
const convergenceRing = addZone(
4.85,
0,
0.92,
0.58,
0xffc56b
);
const recirculationRing = addZone(
2.88,
0,
1.02,
0.76,
0xc58aff
);
// ------------------------------------------------------------
// Projected HTML annotations
// ------------------------------------------------------------
const annotations = [];
function addAnnotation(text, position, colorClass = "") {
const element = document.createElement("div");
element.className = "annotation";
const dot = document.createElement("span");
dot.className = `dot ${colorClass}`.trim();
const label = document.createElement("span");
label.textContent = text;
element.append(dot, label);
labelLayer.appendChild(element);
annotations.push({
element,
position: new THREE.Vector3(...position)
});
}
addAnnotation("Inflection", [-8.0, 0.25, -3.8], "cyan");
addAnnotation("Divergence", [-3.05, 0.35, -1.35]);
addAnnotation("Wake loop", [2.8, 0.4, -1.25], "violet");
addAnnotation("Convergence", [4.9, 0.35, 1.25]);
addAnnotation("Outflow", [7.9, 0.25, -3.8], "cyan");
const projected = new THREE.Vector3();
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const annotation of annotations) {
projected.copy(annotation.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
annotation.element.style.opacity = visible ? "1" : "0";
annotation.element.style.left =
`${((projected.x + 1) / 2) * width}px`;
annotation.element.style.top =
`${((-projected.y + 1) / 2) * height}px`;
}
}
// ------------------------------------------------------------
// UI controls
// ------------------------------------------------------------
const playButton = document.getElementById("play");
const speedInput = document.getElementById("speed");
const speedValue = document.getElementById("speed-value");
const showPaths = document.getElementById("show-paths");
const showTracers = document.getElementById("show-tracers");
const resetButton = document.getElementById("reset");
let running = true;
let simulationTime = 0;
let speed = 1;
playButton.addEventListener("click", () => {
running = !running;
playButton.textContent = running ? "Pause" : "Resume";
playButton.setAttribute("aria-pressed", String(running));
});
speedInput.addEventListener("input", () => {
speed = Number(speedInput.value);
speedValue.textContent = `${speed.toFixed(2)}×`;
});
showPaths.addEventListener("change", () => {
flowGroup.visible = showPaths.checked;
});
showTracers.addEventListener("change", () => {
tracerGroup.visible = showTracers.checked;
});
resetButton.addEventListener("click", resetView);
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
function updateTracers() {
for (const tracer of tracers) {
const u =
(tracer.phase +
(simulationTime * tracer.speed * speed) / tracer.length) %
1;
const point = tracer.curve.getPointAt(u);
const tangent = tracer.curve.getTangentAt(u).normalize();
tracer.mesh.position.copy(point);
tracer.mesh.position.y += 0.055;
tracer.mesh.quaternion.setFromUnitVectors(FORWARD, tangent);
}
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (running) {
simulationTime += delta;
}
updateTracers();
divergenceRing.material.opacity =
0.2 + Math.sin(simulationTime * 2.1) * 0.075;
convergenceRing.material.opacity =
0.22 + Math.sin(simulationTime * 2.1 + 1.5) * 0.08;
recirculationRing.material.opacity =
0.25 + Math.sin(simulationTime * 1.8 + 0.5) * 0.075;
updateAnnotations();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```