Prompt specification
Build or customize the Three.js 3D scene "Air-mass interaction teaching board" 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: Air-mass interaction teaching board
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/air-mass-interaction-teaching-board-x1276
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing weather fronts. Provide controls for boundary position and contrast between two schematic air masses; update conceptual cloud zones and labeled cross sections without implying quantitative weather prediction. Low-poly.
Working Three.js Starter (air-mass-interaction-teaching-board-x1276):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Weather Front Lab — Conceptual Three.js Schematic</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 22, 37, 0.88);
--panel-border: rgba(160, 197, 224, 0.18);
--text: #edf6ff;
--muted: #9eb3c7;
--cool: #55aee3;
--warm: #f3a35b;
--accent: #9be7ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
overflow: hidden;
background:
radial-gradient(circle at 35% 25%, #172c42 0, transparent 38%),
linear-gradient(145deg, #081322, #050b14 70%);
}
#scene {
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.intro {
position: fixed;
top: 24px;
left: 26px;
z-index: 3;
max-width: 430px;
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.65);
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.65rem, 3vw, 2.65rem);
line-height: 1.05;
letter-spacing: -0.04em;
}
.intro p {
max-width: 390px;
margin: 10px 0 0;
color: #b6c8d9;
font-size: 0.94rem;
line-height: 1.5;
}
.forecast-badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 13px;
padding: 7px 10px;
border: 1px solid rgba(255, 209, 138, 0.28);
border-radius: 999px;
background: rgba(35, 27, 18, 0.68);
color: #ffd08a;
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.forecast-badge::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: #ffd08a;
content: "";
box-shadow: 0 0 12px rgba(255, 208, 138, 0.7);
}
.panel {
position: fixed;
z-index: 5;
top: 18px;
right: 18px;
bottom: 18px;
width: min(390px, calc(100vw - 36px));
overflow: auto;
padding: 19px;
border: 1px solid var(--panel-border);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 22px 70px rgba(0, 0, 0, 0.4),
inset 0 1px rgba(255, 255, 255, 0.03);
backdrop-filter: blur(18px) saturate(125%);
scrollbar-width: thin;
scrollbar-color: #334b61 transparent;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 18px;
}
.panel-heading h2 {
margin: 0;
font-size: 1.06rem;
letter-spacing: -0.02em;
}
.panel-heading p {
margin: 4px 0 0;
color: var(--muted);
font-size: 0.76rem;
line-height: 1.45;
}
.reset-button {
flex: 0 0 auto;
padding: 7px 10px;
border: 1px solid rgba(159, 193, 219, 0.22);
border-radius: 9px;
background: rgba(255, 255, 255, 0.045);
color: #cfe0ef;
cursor: pointer;
font-size: 0.72rem;
font-weight: 700;
}
.reset-button:hover {
background: rgba(255, 255, 255, 0.09);
}
.control-section {
padding: 15px 0;
border-top: 1px solid rgba(170, 205, 232, 0.11);
}
.control-section:first-of-type {
padding-top: 0;
border-top: 0;
}
.control-label {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
font-size: 0.82rem;
font-weight: 750;
}
.control-label output {
color: var(--accent);
font-size: 0.72rem;
font-weight: 750;
text-align: right;
}
.hint {
display: block;
margin-top: 7px;
color: var(--muted);
font-size: 0.69rem;
line-height: 1.45;
}
.segmented {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.segmented button {
min-height: 42px;
padding: 9px;
border: 1px solid rgba(160, 197, 224, 0.16);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
color: #aebfd0;
cursor: pointer;
font-size: 0.77rem;
font-weight: 800;
transition: 160ms ease;
}
.segmented button:hover {
border-color: rgba(160, 197, 224, 0.35);
color: white;
}
.segmented button[aria-pressed="true"] {
border-color: rgba(155, 231, 255, 0.55);
background: rgba(155, 231, 255, 0.11);
color: #dff8ff;
box-shadow: inset 0 0 0 1px rgba(155, 231, 255, 0.08);
}
.segmented button[data-type="warm"][aria-pressed="true"] {
border-color: rgba(255, 208, 138, 0.55);
background: rgba(255, 208, 138, 0.11);
color: #fff0d9;
}
input[type="range"] {
width: 100%;
height: 22px;
margin: 0;
appearance: none;
background: transparent;
cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 5px;
border-radius: 99px;
background: linear-gradient(90deg, #29475f, #607486, #795a3f);
}
input[type="range"]::-moz-range-track {
height: 5px;
border-radius: 99px;
background: linear-gradient(90deg, #29475f, #607486, #795a3f);
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
margin-top: -6px;
appearance: none;
border: 3px solid #dff6ff;
border-radius: 50%;
background: #4a9fc7;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #dff6ff;
border-radius: 50%;
background: #4a9fc7;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}
.endpoints {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 4px;
color: #8298ab;
font-size: 0.64rem;
font-weight: 650;
}
.toggle-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.toggle {
display: flex;
align-items: center;
gap: 8px;
padding: 9px 10px;
border: 1px solid rgba(160, 197, 224, 0.13);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
color: #c6d6e4;
cursor: pointer;
font-size: 0.72rem;
font-weight: 700;
}
.toggle input {
width: 15px;
height: 15px;
accent-color: #73cbea;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 8px;
}
.section-title h3 {
margin: 0;
font-size: 0.83rem;
}
.not-to-scale {
color: #8298ab;
font-size: 0.61rem;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.section-wrap {
overflow: hidden;
border: 1px solid rgba(160, 197, 224, 0.14);
border-radius: 12px;
background: rgba(2, 9, 17, 0.48);
}
#crossSection {
display: block;
width: 100%;
height: auto;
}
#crossSection text {
font-family: inherit;
user-select: none;
}
.section-note {
min-height: 42px;
margin: 9px 2px 0;
color: #a5bacb;
font-size: 0.71rem;
line-height: 1.5;
}
.caution {
margin-top: 3px;
padding: 12px;
border: 1px solid rgba(255, 208, 138, 0.2);
border-radius: 11px;
background: rgba(255, 208, 138, 0.055);
color: #d7c5a9;
font-size: 0.69rem;
line-height: 1.5;
}
.caution strong {
color: #ffd08a;
}
.legend {
position: fixed;
z-index: 3;
left: 26px;
bottom: 22px;
display: flex;
align-items: center;
gap: 15px;
padding: 10px 13px;
border: 1px solid rgba(160, 197, 224, 0.14);
border-radius: 12px;
background: rgba(8, 18, 31, 0.72);
color: #a9bdce;
backdrop-filter: blur(12px);
font-size: 0.69rem;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.swatch {
width: 11px;
height: 11px;
border-radius: 3px;
background: var(--cool);
box-shadow: 0 0 9px rgba(85, 174, 227, 0.25);
}
.swatch.warm {
background: var(--warm);
box-shadow: 0 0 9px rgba(243, 163, 91, 0.25);
}
.swatch.cloud {
background: #dce8ef;
}
.camera-hint {
position: fixed;
right: 430px;
bottom: 24px;
z-index: 3;
color: rgba(187, 207, 223, 0.72);
font-size: 0.68rem;
pointer-events: none;
}
.webgl-error {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
padding: 30px;
background: #07111f;
color: #dbeaf5;
text-align: center;
}
@media (max-width: 900px) {
.camera-hint {
display: none;
}
.legend {
bottom: auto;
top: 170px;
}
}
@media (max-width: 680px) {
.intro {
top: 15px;
left: 16px;
max-width: calc(100vw - 32px);
}
.intro p {
max-width: 310px;
font-size: 0.8rem;
}
.forecast-badge {
margin-top: 8px;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 49vh;
padding: 15px;
border-radius: 15px;
}
.legend {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport">
<canvas id="scene" aria-label="Interactive three-dimensional conceptual weather front"></canvas>
</div>
<header class="intro">
<div class="eyebrow">Atmospheric teaching schematic</div>
<h1>Weather Front Lab</h1>
<p>
Explore how a conceptual boundary between cool and warm air shapes
cloud zones, precipitation zones, and frontal geometry.
</p>
<div class="forecast-badge">Not a weather forecast</div>
</header>
<aside class="panel" aria-label="Conceptual weather front controls">
<div class="panel-heading">
<div>
<h2>Conceptual controls</h2>
<p>Illustrative relationships only; no measured values are represented.</p>
</div>
<button class="reset-button" id="resetButton" type="button">Reset</button>
</div>
<section class="control-section">
<div class="control-label">
<span>Front family</span>
</div>
<div class="segmented" role="group" aria-label="Front family">
<button type="button" data-type="cold" aria-pressed="true">Cold front</button>
<button type="button" data-type="warm" aria-pressed="false">Warm front</button>
</div>
<small class="hint">
Cold fronts use a steeper conceptual boundary and a compact cloud tower.
Warm fronts use a gentler boundary and a broader, layered cloud zone.
</small>
</section>
<section class="control-section">
<div class="control-label">
<span>Schematic boundary position</span>
<output id="positionOutput">Near center</output>
</div>
<input
id="positionInput"
type="range"
min="0"
max="100"
value="50"
aria-label="Move the schematic boundary along the scene"
/>
<div class="endpoints">
<span>Toward cool side</span>
<span>Toward warm side</span>
</div>
</section>
<section class="control-section">
<div class="control-label">
<span>Air-mass contrast</span>
<output id="contrastOutput">Clearly contrasted</output>
</div>
<input
id="contrastInput"
type="range"
min="0"
max="100"
value="72"
aria-label="Change the visual contrast between the two schematic air masses"
/>
<div class="endpoints">
<span>Both muted</span>
<span>Colors clearly separated</span>
</div>
</section>
<section class="control-section">
<div class="control-label"><span>Visible layers</span></div>
<div class="toggle-grid">
<label class="toggle">
<input id="cloudToggle" type="checkbox" checked />
Cloud zones
</label>
<label class="toggle">
<input id="precipToggle" type="checkbox" checked />
Precipitation
</label>
<label class="toggle">
<input id="labelToggle" type="checkbox" checked />
Scene labels
</label>
</div>
</section>
<section class="control-section">
<div class="section-title">
<h3 id="sectionTitle">Cold-front cross-section</h3>
<span class="not-to-scale">Not to scale</span>
</div>
<div class="section-wrap">
<svg
id="crossSection"
viewBox="0 0 620 230"
role="img"
aria-label="Labeled conceptual cross-section of a weather front"
>
<defs>
<marker
id="arrowCool"
viewBox="0 0 10 10"
refX="8"
refY="5"
markerWidth="7"
markerHeight="7"
orient="auto-start-reverse"
>
<path d="M 0 0 L 10 5 L 0 10 z" fill="#55aee3"></path>
</marker>
<marker
id="arrowWarm"
viewBox="0 0 10 10"
refX="8"
refY="5"
markerWidth="7"
markerHeight="7"
orient="auto-start-reverse"
>
<path d="M 0 0 L 10 5 L 0 10 z" fill="#f3a35b"></path>
</marker>
<linearGradient id="skyGradient" x1="0" x2="0" y1="0" y2="1">
<stop offset="0%" stop-color="#112337"></stop>
<stop offset="100%" stop-color="#07111f"></stop>
</linearGradient>
</defs>
<rect width="620" height="230" fill="url(#skyGradient)"></rect>
<polygon id="sectionCool" fill="#55aee3" fill-opacity="0.25"></polygon>
<polygon id="sectionWarm" fill="#f3a35b" fill-opacity="0.25"></polygon>
<g id="sectionClouds"></g>
<g id="sectionRain"></g>
<line
x1="20"
y1="136"
x2="600"
y2="136"
stroke="#607486"
stroke-width="2"
></line>
<path
id="sectionFront"
fill="none"
stroke="#dff6ff"
stroke-width="4"
stroke-linecap="round"
></path>
<g id="sectionLabels">
<text
id="coolText"
x="65"
y="72"
fill="#bfe8ff"
font-size="13"
font-weight="800"
letter-spacing="1"
>COOL AIR</text>
<text
id="warmText"
x="477"
y="72"
fill="#ffd5aa"
font-size="13"
font-weight="800"
letter-spacing="1"
>WARM AIR</text>
<text
id="surfaceText"
x="275"
y="61"
fill="#eef8ff"
font-size="11"
font-weight="750"
>FRONTAL SURFACE</text>
<text
id="cloudText"
x="310"
y="43"
fill="#dce8ef"
font-size="10"
font-weight="700"
letter-spacing="0.6"
>CLOUD ZONE</text>
<text
id="precipText"
x="310"
y="118"
fill="#9cd8f4"
font-size="9"
font-weight="700"
letter-spacing="0.5"
>PRECIPITATION ZONE</text>
</g>
<g id="sectionMotion">
<path
id="motionPath"
d="M 95 169 L 190 169"
fill="none"
stroke="#55aee3"
stroke-width="3"
marker-end="url(#arrowCool)"
></path>
<text
id="motionText"
x="65"
y="193"
fill="#a9c2d5"
font-size="10"
font-weight="700"
>COOL AIR ADVANCING</text>
</g>
</svg>
</div>
<p class="section-note" id="sectionNote">
The cooler air forms a wedge beneath the frontal boundary. The compact
cloud zone marks a conceptual area of ascent and precipitation.
</p>
</section>
<div class="caution">
<strong>Educational schematic only.</strong>
Boundary position, contrast, cloud cover, and precipitation are
illustrative. This visualization does not use real observations and must
not be interpreted as quantitative weather prediction.
</div>
</aside>
<div class="legend" aria-hidden="true">
<span class="legend-item"><span class="swatch"></span>Cool air mass</span>
<span class="legend-item"><span class="swatch warm"></span>Warm air mass</span>
<span class="legend-item"><span class="swatch cloud"></span>Cloud zone</span>
</div>
<div class="camera-hint">Drag to orbit · Scroll to zoom · Double-click to reset view</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const viewport = document.querySelector("#viewport");
const positionInput = document.querySelector("#positionInput");
const contrastInput = document.querySelector("#contrastInput");
const positionOutput = document.querySelector("#positionOutput");
const contrastOutput = document.querySelector("#contrastOutput");
const cloudToggle = document.querySelector("#cloudToggle");
const precipToggle = document.querySelector("#precipToggle");
const labelToggle = document.querySelector("#labelToggle");
const resetButton = document.querySelector("#resetButton");
const frontButtons = [...document.querySelectorAll("[data-type]")];
const sectionTitle = document.querySelector("#sectionTitle");
const sectionNote = document.querySelector("#sectionNote");
const sectionCool = document.querySelector("#sectionCool");
const sectionWarm = document.querySelector("#sectionWarm");
const sectionFront = document.querySelector("#sectionFront");
const sectionClouds = document.querySelector("#sectionClouds");
const sectionRain = document.querySelector("#sectionRain");
const sectionLabels = document.querySelector("#sectionLabels");
const surfaceText = document.querySelector("#surfaceText");
const cloudText = document.querySelector("#cloudText");
const precipText = document.querySelector("#precipText");
const motionPath = document.querySelector("#motionPath");
const motionText = document.querySelector("#motionText");
const state = {
type: "cold",
position: 50,
contrast: 0.72,
showClouds: true,
showPrecipitation: true,
showLabels: true
};
let renderer;
try {
renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
} catch (error) {
const message = document.createElement("div");
message.className = "webgl-error";
message.textContent =
"WebGL could not be started. Please open this file in a browser with WebGL enabled.";
document.body.appendChild(message);
throw error;
}
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;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07111f, 0.035);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 1.1, 0);
const cameraState = {
radius: 13.8,
yaw: 0.48,
pitch: 0.42
};
function updateCamera() {
const { radius, yaw, pitch } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.cos(pitch) * Math.sin(yaw),
cameraTarget.y + radius * Math.sin(pitch),
cameraTarget.z + radius * Math.cos(pitch) * Math.cos(yaw)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// Custom orbit/zoom controls implemented directly in this file.
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
let activePointerId = null;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
activePointerId = event.pointerId;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.0045,
0.12,
1.12
);
updateCamera();
});
function stopDragging(event) {
if (event && activePointerId !== null) {
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
dragging = false;
activePointerId = null;
canvas.style.cursor = "grab";
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("lostpointercapture", stopDragging);
canvas.style.cursor = "grab";
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
7.2,
22
);
updateCamera();
},
{ passive: false }
);
function resetCamera() {
cameraState.radius = 13.8;
cameraState.yaw = 0.48;
cameraState.pitch = 0.42;
updateCamera();
}
canvas.addEventListener("dblclick", resetCamera);
const hemisphereLight = new THREE.HemisphereLight(0xb9ddf5, 0x17202c, 2.1);
scene.add(hemisphereLight);
const keyLight = new THREE.DirectionalLight(0xd9efff, 2.6);
keyLight.position.set(-5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xf4a45e, 1.4);
rimLight.position.set(7, 4, -6);
scene.add(rimLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x0c1b2b,
roughness: 0.96,
metalness: 0.03
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(13, 8),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.035;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(12, 12, 0x35536b, 0x1b3348);
grid.position.y = -0.005;
grid.scale.z = 8 / 12;
grid.material.transparent = true;
grid.material.opacity = 0.5;
scene.add(grid);
const airMassGroup = new THREE.Group();
scene.add(airMassGroup);
const coolMassMaterial = new THREE.MeshStandardMaterial({
color: 0x55aee3,
transparent: true,
opacity: 0.2,
roughness: 0.82,
metalness: 0,
depthWrite: false,
side: THREE.DoubleSide
});
const warmMassMaterial = new THREE.MeshStandardMaterial({
color: 0xf3a35b,
transparent: true,
opacity: 0.2,
roughness: 0.82,
metalness: 0,
depthWrite: false,
side: THREE.DoubleSide
});
const coolMass = new THREE.Mesh(new THREE.BufferGeometry(), coolMassMaterial);
const warmMass = new THREE.Mesh(new THREE.BufferGeometry(), warmMassMaterial);
coolMass.renderOrder = 1;
warmMass.renderOrder = 1;
airMassGroup.add(coolMass, warmMass);
function createPrismGeometry(points, zMinimum = -2.8, zMaximum = 2.8) {
const positions = [];
const indices = [];
const count = points.length;
for (const z of [zMaximum, zMinimum]) {
for (const point of points) {
positions.push(point[0], point[1], z);
}
}
for (let i = 1; i < count - 1; i++) {
indices.push(0, i, i + 1);
indices.push(count, count + i + 1, count + i);
}
for (let i = 0; i < count; i++) {
const next = (i + 1) % count;
indices.push(i, count + i, count + next);
indices.push(i, count + next, next);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const boundaryMaterial = new THREE.MeshBasicMaterial({
color: 0x9be7ff,
transparent: true,
opacity: 0.25,
side: THREE.DoubleSide,
depthWrite: false
});
const boundaryMesh = new THREE.Mesh(
new THREE.BufferGeometry(),
boundaryMaterial
);
boundaryMesh.renderOrder = 3;
scene.add(boundaryMesh);
const boundaryLineMaterial = new THREE.LineBasicMaterial({
color: 0xdff6ff,
transparent: true,
opacity: 0.86
});
const boundaryLines = new THREE.LineSegments(
new THREE.BufferGeometry(),
boundaryLineMaterial
);
scene.add(boundaryLines);
// Low-poly cloud pieces.
const cloudGeometryA = new THREE.DodecahedronGeometry(0.5, 0);
const cloudGeometryB = new THREE.TetrahedronGeometry(0.55, 0);
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xdce8ef,
roughness: 1,
metalness: 0,
flatShading: true,
transparent: true,
opacity: 0.8
});
const cloudGroup = new THREE.Group();
scene.add(cloudGroup);
const cloudClusters = [];
for (let i = 0; i < 12; i++) {
const cluster = new THREE.Group();
const pieces = [];
for (let j = 0; j < 6; j++) {
const geometry = j % 2 === 0 ? cloudGeometryA : cloudGeometryB;
const piece = new THREE.Mesh(geometry, cloudMaterial);
piece.castShadow = true;
piece.receiveShadow = true;
cluster.add(piece);
pieces.push(piece);
}
cloudGroup.add(cluster);
cloudClusters.push({ cluster, pieces });
}
const precipitationMaterial = new THREE.LineBasicMaterial({
color: 0x8ed9f5,
transparent: true,
opacity: 0.72
});
const precipitationLines = new THREE.LineSegments(
new THREE.BufferGeometry(),
precipitationMaterial
);
scene.add(precipitationLines);
function seededRandom(seed) {
let value = seed >>> 0;
return function random() {
value += 0x6d2b79f5;
let result = value;
result = Math.imul(result ^ (result >>> 15), result | 1);
result ^= result + Math.imul(result ^ (result >>> 7), result | 61);
return ((result ^ (result >>> 14)) >>> 0) / 4294967296;
};
}
function createTextSprite(text, accent = "#dff6ff", width = 3.1) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 640;
labelCanvas.height = 144;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, labelCanvas.width, labelCanvas.height);
context.fillStyle = "rgba(5, 14, 25, 0.82)";
context.strokeStyle = accent;
context.lineWidth = 4;
context.beginPath();
context.roundRect(8, 8, 624, 128, 22);
context.fill();
context.stroke();
context.fillStyle = accent;
context.font = "800 38px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 320, 74);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 0.225, 1);
sprite.renderOrder = 10;
sprite.userData.canvas = labelCanvas;
sprite.userData.texture = texture;
sprite.userData.accent = accent;
return sprite;
}
function updateSpriteText(sprite, text, accent = sprite.userData.accent) {
sprite.userData.texture.dispose();
sprite.material.map = null;
sprite.material.dispose();
const replacement = createTextSprite(text, accent, sprite.scale.x);
sprite.userData.texture = replacement.userData.texture;
sprite.material.map = replacement.userData.texture;
sprite.material.needsUpdate = true;
sprite.userData.canvas = replacement.userData.canvas;
}
const labelsGroup = new THREE.Group();
scene.add(labelsGroup);
const coolLabel = createTextSprite("COOL AIR MASS", "#bfe8ff", 3.15);
const warmLabel = createTextSprite("WARM AIR MASS", "#ffd5aa", 3.15);
const frontLabel = createTextSprite("COLD FRONT", "#dff6ff", 2.55);
const advanceLabel = createTextSprite("RELATIVE ADVANCE", "#dff6ff", 2.75);
coolLabel.position.set(-3.85, 2.48, -3.0);
warmLabel.position.set(3.75, 2.48, -3.0);
labelsGroup.add(coolLabel, warmLabel, frontLabel, advanceLabel);
function createArrow() {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color: 0x55aee3,
emissive: 0x163548,
emissiveIntensity: 0.35,
roughness: 0.7,
flatShading: true
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, 0.72, 6),
material
);
shaft.rotation.z = -Math.PI / 2;
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.14, 0.32, 6),
material
);
head.rotation.z = -Math.PI / 2;
head.position.x = 0.5;
group.add(shaft, head);
group.userData.material = material;
group.userData.head = head;
return group;
}
const advanceArrow = createArrow();
advanceArrow.position.set(-2.55, 0.32, 3.15);
scene.add(advanceArrow);
const neutralColor = new THREE.Color("#82909e");
const coolTargetColor = new THREE.Color("#55aee3");
const warmTargetColor = new THREE.Color("#f3a35b");
function boundaryPosition() {
return THREE.MathUtils.lerp(-2.4, 2.4, state.position / 100);
}
function frontalSlope() {
return state.type === "cold" ? 1.55 : 3.05;
}
function currentColors() {
const colorAmount = 0.27 + state.contrast * 0.73;
return {
cool: neutralColor.clone().lerp(coolTargetColor, colorAmount),
warm: neutralColor.clone().lerp(warmTargetColor, colorAmount)
};
}
function updateAirMasses(boundary) {
const height = 3.2;
const slope = frontalSlope();
const coolPoints = [
[-6, 0],
[boundary, 0],
[boundary - slope, height],
[-6, height]
];
const warmPoints = [
[boundary, 0],
[6, 0],
[6, height],
[boundary - slope, height]
];
coolMass.geometry.dispose();
warmMass.geometry.dispose();
coolMass.geometry = createPrismGeometry(coolPoints);
warmMass.geometry = createPrismGeometry(warmPoints);
const colors = currentColors();
coolMassMaterial.color.copy(colors.cool);
warmMassMaterial.color.copy(colors.warm);
coolMassMaterial.opacity = 0.13 + state.contrast * 0.11;
warmMassMaterial.opacity = 0.13 + state.contrast * 0.11;
}
function updateBoundary(boundary) {
const slope = frontalSlope();
const topX = boundary - slope;
const zNear = 2.82;
const zFar = -2.82;
const positions = new Float32Array([
boundary, 0, zFar,
boundary, 0, zNear,
topX, 3.2, zFar,
topX, 3.2, zNear
]);
const indices = [0, 1, 2, 1, 3, 2];
boundaryMesh.geometry.dispose();
boundaryMesh.geometry = new THREE.BufferGeometry();
boundaryMesh.geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
boundaryMesh.geometry.setIndex(indices);
boundaryMesh.geometry.computeVertexNormals();
const accent =
state.type === "cold" ? new THREE.Color("#9be7ff") : new THREE.Color("#ffd08a");
boundaryMaterial.color.copy(accent);
boundaryMaterial.opacity = 0.14 + state.contrast * 0.18;
boundaryLineMaterial.color.copy(accent);
const linePositions = new Float32Array([
boundary, 0, zNear,
topX, 3.2, zNear,
boundary, 0, zFar,
topX, 3.2, zFar,
boundary, 0, zNear,
boundary, 0, zFar,
topX, 3.2, zNear,
topX, 3.2, zFar
]);
boundaryLines.geometry.dispose();
boundaryLines.geometry = new THREE.BufferGeometry();
boundaryLines.geometry.setAttribute(
"position",
new THREE.BufferAttribute(linePositions, 3)
);
frontLabel.position.set(
boundary - slope * 0.55,
1.72,
3.08
);
}
function updateClouds(boundary) {
const random = seededRandom(state.type === "cold" ? 913 : 571);
const isCold = state.type === "cold";
cloudMaterial.opacity = 0.48 + state.contrast * 0.4;
cloudMaterial.color.set(isCold ? 0xdce8ef : 0xeee5da);
cloudClusters.forEach((entry, index) => {
const { cluster, pieces } = entry;
const z = -2.35 + (index / (cloudClusters.length - 1)) * 4.7;
let x;
let y;
let scaleX;
let scaleY;
let scaleZ;
if (isCold) {
x = boundary + (random() - 0.5) * 0.85;
y = 1.08 + random() * 0.72;
scaleX = 0.65 + random() * 0.42;
scaleY = 1.15 + random() * 0.85;
scaleZ = 0.58 + random() * 0.38;
} else {
x = boundary - 0.45 - random() * 2.45;
y = 1.9 + random() * 0.52;
scaleX = 0.95 + random() * 0.58;
scaleY = 0.48 + random() * 0.26;
scaleZ = 0.58 + random() * 0.34;
}
cluster.position.set(x, y, z);
cluster.scale.set(scaleX, scaleY, scaleZ);
pieces.forEach((piece, pieceIndex) => {
const angle = (pieceIndex / pieces.length) * Math.PI * 2;
const spread = pieceIndex === 0 ? 0 : 0.19 + random() * 0.12;
piece.position.set(
Math.cos(angle) * spread,
pieceIndex === 0 ? 0.16 : random() * 0.24,
Math.sin(angle) * spread
);
piece.rotation.set(
random() * 0.35,
random() * Math.PI,
random() * 0.25
);
});
});
const dropCount = 24;
const rainPositions = new Float32Array(dropCount * 6);
const rainRandom = seededRandom(state.type === "cold" ? 441 : 882);
for (let i = 0; i < dropCount; i++) {
const z = -2.2 + rainRandom() * 4.4;
let x;
let top;
let bottom;
if (isCold) {
x = boundary + 0.08 + rainRandom() * 0.62;
top = 1.15 + rainRandom() * 0.42;
bottom = 0.08;
} else {
x = boundary - 2.7 + rainRandom() * 2.95;
top = 1.8 + rainRandom() * 0.25;
bottom = 0.75 + rainRandom() * 0.75;
}
const offset = i * 6;
rainPositions[offset] = x;
rainPositions[offset + 1] = top;
rainPositions[offset + 2] = z;
rainPositions[offset + 3] = x + (isCold ? 0.08 : 0.02);
rainPositions[offset + 4] = bottom;
rainPositions[offset + 5] = z;
}
precipitationLines.geometry.dispose();
precipitationLines.geometry = new THREE.BufferGeometry();
precipitationLines.geometry.setAttribute(
"position",
new THREE.BufferAttribute(rainPositions, 3)
);
precipitationLines.visible = state.showPrecipitation;
cloudGroup.visible = state.showClouds;
}
function updateArrow(boundary) {
if (state.type === "cold") {
advanceArrow.position.set(boundary - 2.65, 0.32, 3.15);
advanceArrow.rotation.y = 0;
advanceArrow.userData.material.color.copy(coolTargetColor);
advanceArrow.userData.material.emissive.set(0x163548);
updateSpriteText(advanceLabel, "COOL AIR ADVANCE", "#bfe8ff");
} else {
advanceArrow.position.set(boundary + 2.55, 0.32, 3.15);
advanceArrow.rotation.y = Math.PI;
advanceArrow.userData.material.color.copy(warmTargetColor);
advanceArrow.userData.material.emissive.set(0x4a2d18);
updateSpriteText(advanceLabel, "WARM AIR ADVANCE", "#ffd5aa");
}
advanceLabel.position.set(
advanceArrow.position.x,
0.86,
3.15
);
}
function updateSceneLabels(boundary) {
labelsGroup.visible = state.showLabels;
updateSpriteText(
frontLabel,
state.type === "cold" ? "COLD FRONT" : "WARM FRONT",
state.type === "cold" ? "#9be7ff" : "#ffd08a"
);
}
function mapSectionX(value) {
return 20 + ((value + 6) / 12) * 580;
}
function svgColor(color) {
return `#${color.getHexString()}`;
}
function updateSection(boundary) {
const slope = frontalSlope();
const colors = currentColors();
const coolColor = svgColor(colors.cool);
const warmColor = svgColor(colors.warm);
sectionCool.setAttribute("fill", coolColor);
sectionWarm.setAttribute("fill", warmColor);
sectionCool.setAttribute("fill-opacity", 0.18 + state.contrast * 0.17);
sectionWarm.setAttribute("fill-opacity", 0.18 + state.contrast * 0.17);
const groundY = 136;
const topY = 34;
const bottomX = mapSectionX(boundary);
const topX = mapSectionX(boundary - slope);
const leftX = mapSectionX(-6);
const rightX = mapSectionX(6);
sectionCool.setAttribute(
"points",
`${leftX},${groundY} ${bottomX},${groundY} ${topX},${topY} ${leftX},${topY}`
);
sectionWarm.setAttribute(
"points",
`${bottomX},${groundY} ${rightX},${groundY} ${rightX},${topY} ${topX},${topY}`
);
sectionFront.setAttribute("d", `M ${bottomX} ${groundY} L ${topX} ${topY}`);
sectionFront.setAttribute(
"stroke",
state.type === "cold" ? "#9be7ff" : "#ffd08a"
);
const cloudOpacity = 0.5 + state.contrast * 0.45;
let cloudMarkup = "";
let rainMarkup = "";
if (state.type === "cold") {
const centers = [
bottomX - 10,
bottomX + 18,
bottomX + 44
];
centers.forEach((center, index) => {
const width = 27 + index * 5;
const top = 58 + index * 5;
const base = 103 + index * 3;
cloudMarkup += `
<g opacity="${cloudOpacity}">
<polygon
points="${center - width},${base}
${center - width + 5},${top + 12}
${center - width + 14},${top + 4}
${center - width + 27},${top + 11}
${center + width},${base + 2}
${center + width - 6},${top + 22}
${center + 5},${top + 27}"
fill="#dce8ef"
stroke="#f4fbff"
stroke-width="1"
stroke-linejoin="round"
></polygon>
</g>
`;
for (let i = 0; i < 3; i++) {
const x = center - 12 + i * 12;
const y = base + 5 + (i % 2) * 4;
rainMarkup += `
<line
x1="${x}" y1="${y}"
x2="${x + 4}" y2="${y + 18}"
stroke="#8ed9f5"
stroke-width="2"
stroke-linecap="round"
opacity="0.8"
></line>
`;
}
});
sectionTitle.textContent = "Cold-front cross-section";
sectionNote.textContent =
"The cooler air forms a wedge beneath the frontal boundary. The compact cloud zone marks a conceptual area of ascent and precipitation.";
cloudText.textContent = "COMPACT CLOUD TOWER";
precipText.textContent = "CONCEPTUAL SHOWERS";
motionText.textContent = "COOL AIR ADVANCING";
motionPath.setAttribute("d", "M 80 169 L 190 169");
motionPath.setAttribute("stroke", coolColor);
motionPath.setAttribute("marker-end", "url(#arrowCool)");
} else {
const centers = [bottomX - 148, bottomX - 100, bottomX - 48, bottomX + 5];
centers.forEach((center, index) => {
const width = 42 + index * 3;
const top = 65 + (index % 2) * 8;
cloudMarkup += `
<g opacity="${cloudOpacity}">
<polygon
points="${center - width},${top + 30}
${center - width + 9},${top + 10}
${center - width + 24},${top + 1}
${center - width + 40},${top + 12}
${center + width},${top + 24}
${center + width - 8},${top + 36}
${center - width + 7},${top + 37}"
fill="#e7e1d8"
stroke="#fff9ef"
stroke-width="1"
stroke-linejoin="round"
></polygon>
</g>
`;
for (let i = 0; i < 3; i++) {
const x = center - 15 + i * 14;
const y = top + 39 + (i % 2) * 3;
rainMarkup += `
<line
x1="${x}" y1="${y}"
x2="${x + 2}" y2="${y + 10}"
stroke="#b9dce8"
stroke-width="1.6"
stroke-linecap="round"
opacity="0.68"
></line>
`;
}
});
sectionTitle.textContent = "Warm-front cross-section";
sectionNote.textContent =
"The warm air is shown gliding over a gentler frontal boundary. A broad, layered cloud zone occupies the cooler air ahead of the front.";
cloudText.textContent = "BROAD LAYERED CLOUDS";
precipText.textContent = "CONCEPTUAL LIGHT PRECIPITATION";
motionText.textContent = "WARM AIR ADVANCING";
motionPath.setAttribute("d", "M 540 169 L 420 169");
motionPath.setAttribute("stroke", warmColor);
motionPath.setAttribute("marker-end", "url(#arrowWarm)");
}
sectionClouds.innerHTML = cloudMarkup;
sectionRain.innerHTML = rainMarkup;
sectionClouds.style.display = state.showClouds ? "" : "none";
sectionRain.style.display = state.showPrecipitation ? "" : "none";
sectionLabels.style.display = state.showLabels ? "" : "none";
surfaceText.setAttribute("x", Math.max(180, Math.min(430, topX + 10)));
cloudText.setAttribute("x", state.type === "cold" ? bottomX - 28 : bottomX - 86);
precipText.setAttribute("x", state.type === "cold" ? bottomX - 36 : bottomX - 103);
}
function updateReadouts() {
const boundary = boundaryPosition();
if (boundary < -0.8) {
positionOutput.textContent = "Toward cool side";
} else if (boundary > 0.8) {
positionOutput.textContent = "Toward warm side";
} else {
positionOutput.textContent = "Near center";
}
if (state.contrast < 0.34) {
contrastOutput.textContent = "Subtle distinction";
} else if (state.contrast < 0.7) {
contrastOutput.textContent = "Moderately contrasted";
} else {
contrastOutput.textContent = "Clearly contrasted";
}
}
function updateEverything() {
const boundary = boundaryPosition();
updateReadouts();
updateAirMasses(boundary);
updateBoundary(boundary);
updateClouds(boundary);
updateArrow(boundary);
updateSceneLabels(boundary);
updateSection(boundary);
}
frontButtons.forEach((button) => {
button.addEventListener("click", () => {
state.type = button.dataset.type;
frontButtons.forEach((candidate) => {
candidate.setAttribute(
"aria-pressed",
String(candidate.dataset.type === state.type)
);
});
updateEverything();
});
});
positionInput.addEventListener("input", () => {
state.position = Number(positionInput.value);
updateEverything();
});
contrastInput.addEventListener("input", () => {
state.contrast = Number(contrastInput.value) / 100;
updateEverything();
});
cloudToggle.addEventListener("change", () => {
state.showClouds = cloudToggle.checked;
updateEverything();
});
precipToggle.addEventListener("change", () => {
state.showPrecipitation = precipToggle.checked;
updateEverything();
});
labelToggle.addEventListener("change", () => {
state.showLabels = labelToggle.checked;
updateEverything();
});
resetButton.addEventListener("click", () => {
state.type = "cold";
state.position = 50;
state.contrast = 0.72;
state.showClouds = true;
state.showPrecipitation = true;
state.showLabels = true;
positionInput.value = "50";
contrastInput.value = "72";
cloudToggle.checked = true;
precipToggle.checked = true;
labelToggle.checked = true;
frontButtons.forEach((button) => {
button.setAttribute(
"aria-pressed",
String(button.dataset.type === state.type)
);
});
resetCamera();
updateEverything();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
updateEverything();
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```