Prompt specification
Build or customize the Three.js 3D scene "Activation-energy landscape pair" 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: Activation-energy landscape pair
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/activation-energy-landscape-pair-x1925
Scene Description Prompt:
Compare schematic activation-energy barriers with equal starting and ending energies in a cutaway exhibit. Use Three.js from cdnjs in standalone HTML.
Working Three.js Starter (activation-energy-landscape-pair-x1925):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Activation Energy — Cutaway Exhibit</title>
<style>
:root {
--cyan: #55e5ff;
--amber: #ffb65c;
--ink: #eaf7ff;
--muted: #8ea6b8;
--panel: rgba(8, 16, 29, 0.78);
--line: rgba(131, 194, 220, 0.22);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #060a12;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
z-index: 5;
pointer-events: none;
}
.title-block {
top: 28px;
left: 32px;
max-width: 440px;
}
.eyebrow {
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
margin-bottom: 8px;
}
h1 {
margin: 0;
font-size: clamp(27px, 3vw, 46px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 760;
text-shadow: 0 5px 30px rgba(0,0,0,.5);
}
.subtitle {
margin: 12px 0 0;
max-width: 390px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.controls {
top: 28px;
right: 28px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid var(--line);
background: rgba(10, 19, 32, 0.72);
color: #dff7ff;
border-radius: 8px;
padding: 9px 12px;
font: 700 10px/1 Inter, ui-sans-serif, system-ui, sans-serif;
letter-spacing: .12em;
text-transform: uppercase;
cursor: pointer;
transition: border-color .2s, color .2s, background .2s, transform .2s;
}
button:hover,
button.active {
color: var(--cyan);
border-color: rgba(85,229,255,.6);
background: rgba(19, 48, 65, .8);
transform: translateY(-1px);
}
.summary {
left: 28px;
bottom: 28px;
display: grid;
grid-template-columns: repeat(3, minmax(120px, 1fr));
gap: 1px;
width: min(560px, calc(100vw - 56px));
overflow: hidden;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--line);
box-shadow: 0 16px 50px rgba(0,0,0,.35);
backdrop-filter: blur(14px);
}
.metric {
min-height: 76px;
padding: 14px 16px;
background: var(--panel);
}
.metric .label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
.metric .value {
margin-top: 7px;
font-size: 17px;
font-weight: 750;
letter-spacing: -.02em;
}
.metric .value span {
color: var(--muted);
font-size: 11px;
font-weight: 600;
}
.cyan { color: var(--cyan); }
.amber { color: var(--amber); }
.hint {
right: 28px;
bottom: 28px;
color: #708798;
font-size: 10px;
font-weight: 700;
letter-spacing: .11em;
text-transform: uppercase;
text-align: right;
line-height: 1.8;
}
.hint strong {
display: block;
color: #b7c8d4;
font-weight: 700;
}
.note {
position: fixed;
z-index: 5;
left: 50%;
bottom: 28px;
transform: translateX(-50%);
color: #62798a;
font-size: 9px;
font-weight: 700;
letter-spacing: .12em;
text-transform: uppercase;
pointer-events: none;
}
@media (max-width: 820px) {
.title-block { top: 20px; left: 20px; }
.subtitle { display: none; }
.controls { top: 20px; right: 20px; }
.summary {
left: 20px;
bottom: 20px;
width: calc(100vw - 40px);
grid-template-columns: 1fr 1fr 1fr;
}
.metric { padding: 11px 10px; }
.metric .value { font-size: 14px; }
.hint, .note { display: none; }
}
@media (max-width: 520px) {
.controls button:first-child { display: none; }
.summary { grid-template-columns: 1fr; width: 220px; }
.metric { min-height: 0; padding: 9px 11px; }
.metric .value { margin-top: 4px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive cutaway exhibit comparing two activation-energy barriers"></canvas>
<div class="hud title-block">
<div class="eyebrow">Interactive chemistry exhibit</div>
<h1>Activation Energy</h1>
<p class="subtitle">
Two schematic reaction paths share identical starting and ending energies.
The height of the peak determines the activation barrier.
</p>
</div>
<div class="hud controls">
<button id="frontView">Front view</button>
<button id="perspectiveView" class="active">3D view</button>
<button id="motionButton">Pause</button>
</div>
<div class="hud summary">
<div class="metric">
<div class="label">Shared endpoints</div>
<div class="value">20 → 20 <span>kJ/mol</span></div>
</div>
<div class="metric">
<div class="label">Lower barrier</div>
<div class="value cyan">ΔE‡ = 40 <span>kJ/mol</span></div>
</div>
<div class="metric">
<div class="label">Higher barrier</div>
<div class="value amber">ΔE‡ = 80 <span>kJ/mol</span></div>
</div>
</div>
<div class="hud hint">
<strong>Drag to orbit · Scroll to zoom</strong>
Schematic values are illustrative
</div>
<div class="note">Equal endpoints · Different barriers · ΔE reaction = 0</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* ------------------------------------------------------------------ */
/* Renderer and scene */
/* ------------------------------------------------------------------ */
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x060a12);
scene.fog = new THREE.FogExp2(0x060a12, 0.026);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
scene.add(new THREE.HemisphereLight(0xb9e8ff, 0x111827, 1.2));
const keyLight = new THREE.DirectionalLight(0xd9f4ff, 3.4);
keyLight.position.set(5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x36d9ff, 38, 9, 2);
cyanLight.position.set(-5, 4.5, -2.4);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xff9d3d, 34, 9, 2);
amberLight.position.set(5, 4.5, -2.1);
scene.add(amberLight);
const rimLight = new THREE.PointLight(0x6b72ff, 20, 16, 2);
rimLight.position.set(0, 7, 2);
scene.add(rimLight);
/* ------------------------------------------------------------------ */
/* Materials */
/* ------------------------------------------------------------------ */
const mat = {
floor: new THREE.MeshStandardMaterial({
color: 0x0a111d,
roughness: 0.72,
metalness: 0.22
}),
platform: new THREE.MeshStandardMaterial({
color: 0x101a28,
roughness: 0.5,
metalness: 0.38
}),
wall: new THREE.MeshStandardMaterial({
color: 0x101a27,
roughness: 0.84,
metalness: 0.12
}),
wallInset: new THREE.MeshStandardMaterial({
color: 0x08111d,
roughness: 0.68,
metalness: 0.25
}),
frame: new THREE.MeshStandardMaterial({
color: 0x263748,
roughness: 0.34,
metalness: 0.78
}),
dark: new THREE.MeshStandardMaterial({
color: 0x07101a,
roughness: 0.5,
metalness: 0.45
}),
cyan: new THREE.MeshStandardMaterial({
color: 0x55e5ff,
emissive: 0x1a8da8,
emissiveIntensity: 1.6,
roughness: 0.26,
metalness: 0.35
}),
amber: new THREE.MeshStandardMaterial({
color: 0xffb65c,
emissive: 0x9b4e0c,
emissiveIntensity: 1.5,
roughness: 0.26,
metalness: 0.35
})
};
function box(w, h, d, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
/* ------------------------------------------------------------------ */
/* Canvas texture helpers */
/* ------------------------------------------------------------------ */
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function canvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makePanelTexture(accent) {
const c = document.createElement("canvas");
c.width = 1024;
c.height = 720;
const ctx = c.getContext("2d");
const g = ctx.createLinearGradient(0, 0, 0, c.height);
g.addColorStop(0, "#101d2c");
g.addColorStop(0.55, "#091421");
g.addColorStop(1, "#060d17");
ctx.fillStyle = g;
ctx.fillRect(0, 0, c.width, c.height);
ctx.strokeStyle = "rgba(141,190,213,0.075)";
ctx.lineWidth = 1;
for (let x = 0; x <= c.width; x += 64) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, c.height);
ctx.stroke();
}
for (let y = 0; y <= c.height; y += 60) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(c.width, y);
ctx.stroke();
}
const glow = ctx.createRadialGradient(c.width * 0.5, c.height * 0.25, 0,
c.width * 0.5, c.height * 0.25, c.width * 0.55);
glow.addColorStop(0, accent + "12");
glow.addColorStop(1, accent + "00");
ctx.fillStyle = glow;
ctx.fillRect(0, 0, c.width, c.height);
ctx.strokeStyle = accent + "42";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(24, c.height - 24);
ctx.lineTo(c.width - 24, c.height - 24);
ctx.stroke();
return canvasTexture(c);
}
function makeTextPlane(text, subtitle, width = 9) {
const c = document.createElement("canvas");
c.width = 1536;
c.height = 220;
const ctx = c.getContext("2d");
ctx.clearRect(0, 0, c.width, c.height);
ctx.textAlign = "center";
ctx.fillStyle = "#d9f4ff";
ctx.font = "700 76px Arial, sans-serif";
ctx.fillText(text, c.width / 2, 90);
ctx.fillStyle = "#6f8da0";
ctx.font = "600 29px Arial, sans-serif";
ctx.letterSpacing = "5px";
ctx.fillText(subtitle, c.width / 2, 151);
const texture = canvasTexture(c);
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(width, width * 220 / 1536), material);
return mesh;
}
function makeBadge(text, color, worldWidth, parent, x, y, z, filled = true) {
const c = document.createElement("canvas");
c.width = 1200;
c.height = 210;
const ctx = c.getContext("2d");
if (filled) {
roundedRect(ctx, 8, 8, c.width - 16, c.height - 16, 38);
ctx.fillStyle = "rgba(5,13,24,0.88)";
ctx.fill();
ctx.strokeStyle = color + "aa";
ctx.lineWidth = 4;
ctx.stroke();
}
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = color;
ctx.font = "700 63px Arial, sans-serif";
ctx.fillText(text, c.width / 2, c.height / 2 + 3);
const texture = canvasTexture(c);
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false,
toneMapped: false
}));
sprite.scale.set(worldWidth, worldWidth * 210 / 1200, 1);
sprite.position.set(x, y, z);
sprite.renderOrder = 20;
parent.add(sprite);
return sprite;
}
function makeCaption(text, color, worldWidth, parent, x, y, z, fontSize = 52) {
const c = document.createElement("canvas");
c.width = 1200;
c.height = 140;
const ctx = c.getContext("2d");
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = color;
ctx.font = `700 ${fontSize}px Arial, sans-serif`;
ctx.fillText(text, c.width / 2, c.height / 2 + 2);
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: canvasTexture(c),
transparent: true,
depthWrite: false,
depthTest: false,
toneMapped: false
}));
sprite.scale.set(worldWidth, worldWidth * 140 / 1200, 1);
sprite.position.set(x, y, z);
sprite.renderOrder = 21;
parent.add(sprite);
return sprite;
}
/* ------------------------------------------------------------------ */
/* Cutaway room */
/* ------------------------------------------------------------------ */
box(18, 0.34, 10.6, mat.floor, 0, -0.24, 0);
box(16.7, 0.25, 8.45, mat.platform, 0, 0.12, -0.2);
const wall = box(18, 7.7, 0.28, mat.wall, 0, 3.85, -4.72);
wall.receiveShadow = true;
box(17.3, 6.8, 0.08, mat.wallInset, 0, 3.8, -4.54);
// Full-height left wall and deliberately sectioned right wall.
box(0.28, 6.35, 9.9, mat.wall, -8.88, 3.12, 0.12);
box(0.28, 0.92, 9.9, mat.wall, 8.88, 0.42, 0.12);
const cutMaterial = new THREE.MeshStandardMaterial({
color: 0x496174,
emissive: 0x142d3b,
emissiveIntensity: 0.8,
roughness: 0.35,
metalness: 0.7
});
box(0.31, 0.055, 9.85, cutMaterial, 8.88, 0.905, 0.12);
// Platform grid.
const gridVertices = [];
for (let x = -8; x <= 8; x += 0.5) {
gridVertices.push(x, 0.252, -4.25, x, 0.252, 3.85);
}
for (let z = -4; z <= 4; z += 0.5) {
gridVertices.push(-8.1, 0.252, z, 8.1, 0.252, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute("position", new THREE.Float32BufferAttribute(gridVertices, 3));
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x41627a,
transparent: true,
opacity: 0.16
})
);
scene.add(grid);
// Exhibit wall title.
const wallTitle = makeTextPlane(
"TWO ROUTES. ONE DESTINATION.",
"SCHEMATIC POTENTIAL-ENERGY PROFILES",
8.7
);
wallTitle.position.set(0, 6.82, -4.48);
scene.add(wallTitle);
/* ------------------------------------------------------------------ */
/* Energy curves */
/* ------------------------------------------------------------------ */
class EnergyCurve extends THREE.Curve {
constructor(peak, baseline = -0.72) {
super();
this.peak = peak;
this.baseline = baseline;
}
getPoint(t, target = new THREE.Vector3()) {
const x = THREE.MathUtils.lerp(-2.55, 2.55, t);
let e = 0;
const smooth = x => {
x = THREE.MathUtils.clamp(x, 0, 1);
return x * x * (3 - 2 * x);
};
if (t < 0.12) {
e = 0;
} else if (t < 0.50) {
e = smooth((t - 0.12) / 0.38);
} else if (t < 0.88) {
e = 1 - smooth((t - 0.50) / 0.38);
} else {
e = 0;
}
const y = this.baseline + (this.peak - this.baseline) * e;
return target.set(x, y, 0);
}
}
function addArrow(parent, start, end, color, radius = 0.018, headRadius = 0.09) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const shaftLength = Math.max(0.01, length - 0.18);
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, shaftLength, 10),
new THREE.MeshBasicMaterial({ color })
);
shaft.position.copy(start).addScaledVector(direction, 0.5);
shaft.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
parent.add(shaft);
const head = new THREE.Mesh(
new THREE.ConeGeometry(headRadius, 0.18, 18),
new THREE.MeshBasicMaterial({ color })
);
head.position.copy(end).addScaledVector(direction.clone().normalize(), -0.09);
head.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
parent.add(head);
}
function createProfile(cx, colorHex, peak, barrier, speed, routeName, routeNote) {
const group = new THREE.Group();
group.position.set(cx, 3.7, -4.12);
scene.add(group);
// Panel body, face, and frame.
box(6.34, 4.58, 0.18, mat.dark, 0, 0, -0.04, group);
const face = new THREE.Mesh(
new THREE.PlaneGeometry(6.08, 4.32),
new THREE.MeshStandardMaterial({
map: makePanelTexture(colorHex),
roughness: 0.7,
metalness: 0.15,
emissive: 0x0b1722,
emissiveIntensity: 0.18
})
);
face.position.z = 0.065;
group.add(face);
box(0.08, 4.66, 0.22, mat.frame, -3.15, 0, 0.10, group);
box(0.08, 4.66, 0.22, mat.frame, 3.15, 0, 0.10, group);
box(6.36, 0.08, 0.22, mat.frame, 0, 2.29, 0.10, group);
box(6.36, 0.08, 0.22, mat.frame, 0, -2.29, 0.10, group);
const curve = new EnergyCurve(peak);
// Filled area under the profile.
const shape = new THREE.Shape();
shape.moveTo(-2.55, -0.72);
for (let i = 0; i <= 100; i++) {
const p = curve.getPoint(i / 100);
shape.lineTo(p.x, p.y);
}
shape.lineTo(2.55, -0.72);
shape.closePath();
const fill = new THREE.Mesh(
new THREE.ShapeGeometry(shape),
new THREE.MeshBasicMaterial({
color: colorHex,
transparent: true,
opacity: 0.075,
depthWrite: false,
side: THREE.DoubleSide
})
);
fill.position.z = 0.15;
group.add(fill);
// Main curve and soft glow.
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 140, 0.065, 10, false),
new THREE.MeshStandardMaterial({
color: colorHex,
emissive: colorHex,
emissiveIntensity: 1.5,
roughness: 0.28,
metalness: 0.28
})
);
tube.position.z = 0.27;
group.add(tube);
const glow = new THREE.Mesh(
new THREE.TubeGeometry(curve, 140, 0.15, 8, false),
new THREE.MeshBasicMaterial({
color: colorHex,
transparent: true,
opacity: 0.12,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
glow.position.z = 0.255;
group.add(glow);
// Shared endpoint-energy line.
const baselineGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-2.55, -0.72, 0.27),
new THREE.Vector3( 2.55, -0.72, 0.27)
]);
const baseline = new THREE.Line(
baselineGeometry,
new THREE.LineDashedMaterial({
color: 0x9ab3c4,
dashSize: 0.12,
gapSize: 0.09,
transparent: true,
opacity: 0.58
})
);
baseline.computeLineDistances();
group.add(baseline);
// Axes.
addArrow(
group,
new THREE.Vector3(-2.68, -1.78, 0.22),
new THREE.Vector3(2.66, -1.78, 0.22),
0x526b7d,
0.014,
0.075
);
addArrow(
group,
new THREE.Vector3(-2.72, -1.78, 0.22),
new THREE.Vector3(-2.72, 1.70, 0.22),
0x526b7d,
0.014,
0.075
);
// Activation barrier arrow.
addArrow(
group,
new THREE.Vector3(0, -0.72, 0.39),
new THREE.Vector3(0, peak, 0.39),
colorHex,
0.019,
0.10
);
const markerGeometry = new THREE.SphereGeometry(0.10, 20, 12);
[
[-2.55, -0.72, 0.33],
[0, peak, 0.34],
[2.55, -0.72, 0.33]
].forEach(p => {
const marker = new THREE.Mesh(
markerGeometry,
new THREE.MeshBasicMaterial({ color: colorHex })
);
marker.position.set(...p);
group.add(marker);
});
// Labels.
makeBadge(routeName, colorHex, 3.85, group, -0.18, 2.48, 0.55);
makeCaption("POTENTIAL ENERGY", "#8098aa", 2.25, group, -1.63, 1.60, 0.48, 42);
makeBadge(`ΔE‡ = ${barrier} kJ/mol`, colorHex, 2.25, group, 1.40, peak * 0.43, 0.50);
makeCaption("REACTANTS", "#d3e2eb", 1.55, group, -1.68, -1.03, 0.46, 47);
makeCaption("20 kJ/mol", colorHex, 1.45, group, -1.68, -1.36, 0.46, 43);
makeCaption("PRODUCTS", "#d3e2eb", 1.48, group, 1.67, -1.03, 0.46, 47);
makeCaption("20 kJ/mol", colorHex, 1.45, group, 1.67, -1.36, 0.46, 43);
makeCaption("REACTION COORDINATE →", "#738b9c", 2.70, group, 0, -2.08, 0.46, 42);
// Animated tracer.
const orb = new THREE.Mesh(
new THREE.SphereGeometry(0.12, 24, 16),
new THREE.MeshBasicMaterial({ color: 0xffffff })
);
group.add(orb);
const halo = new THREE.Mesh(
new THREE.SphereGeometry(0.21, 18, 12),
new THREE.MeshBasicMaterial({
color: colorHex,
transparent: true,
opacity: 0.16,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
group.add(halo);
// Display plinth and front plaque.
box(6.25, 0.95, 1.25, mat.platform, cx, 0.72, -3.70);
box(5.9, 0.045, 1.28, new THREE.MeshStandardMaterial({
color: colorHex,
emissive: colorHex,
emissiveIntensity: 0.8,
roughness: 0.32,
metalness: 0.6
}), cx, 1.215, -3.70);
makeBadge(routeNote, colorHex, 4.20, scene, cx, 0.74, -3.01);
return { group, curve, orb, halo, speed };
}
const profileA = createProfile(
-3.55,
"#55e5ff",
0.43,
40,
0.115,
"PATH A / LOWER BARRIER",
"LOWER ENERGY COST"
);
const profileB = createProfile(
3.55,
"#ffb65c",
1.72,
80,
0.058,
"PATH B / HIGHER BARRIER",
"HIGHER ENERGY COST"
);
/* ------------------------------------------------------------------ */
/* Atmospheric particles */
/* ------------------------------------------------------------------ */
const dustCount = 130;
const dustPositions = new Float32Array(dustCount * 3);
const dustBase = [];
for (let i = 0; i < dustCount; i++) {
const x = THREE.MathUtils.randFloatSpread(16.5);
const y = THREE.MathUtils.randFloat(0.35, 7.2);
const z = THREE.MathUtils.randFloat(-4.2, 4.0);
dustPositions.set([x, y, z], i * 3);
dustBase.push({ x, y, z, phase: Math.random() * Math.PI * 2 });
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute("position", new THREE.BufferAttribute(dustPositions, 3));
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0x87cbe0,
size: 0.028,
transparent: true,
opacity: 0.42,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
scene.add(dust);
/* ------------------------------------------------------------------ */
/* Direct camera controls */
/* ------------------------------------------------------------------ */
const controls = {
target: new THREE.Vector3(0, 3.05, -0.35),
theta: 0.27,
phi: 1.15,
radius: 15.6,
targetTheta: 0.27,
targetPhi: 1.15,
targetRadius: 15.6
};
function updateCamera(immediate = false) {
const amount = immediate ? 1 : 0.075;
controls.theta += (controls.targetTheta - controls.theta) * amount;
controls.phi += (controls.targetPhi - controls.phi) * amount;
controls.radius += (controls.targetRadius - controls.radius) * amount;
const spherical = new THREE.Spherical(
controls.radius,
controls.phi,
controls.theta
);
camera.position.setFromSpherical(spherical).add(controls.target);
camera.lookAt(controls.target);
}
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
controls.targetTheta = THREE.MathUtils.clamp(
controls.targetTheta - dx * 0.005,
-0.68,
0.68
);
controls.targetPhi = THREE.MathUtils.clamp(
controls.targetPhi - dy * 0.004,
0.72,
1.42
);
});
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.style.cursor = "grab";
canvas.addEventListener("wheel", event => {
event.preventDefault();
controls.targetRadius = THREE.MathUtils.clamp(
controls.targetRadius * Math.exp(event.deltaY * 0.001),
10.5,
22
);
}, { passive: false });
window.addEventListener("keydown", event => {
if (event.key === "ArrowLeft") {
controls.targetTheta = THREE.MathUtils.clamp(controls.targetTheta - 0.08, -0.68, 0.68);
}
if (event.key === "ArrowRight") {
controls.targetTheta = THREE.MathUtils.clamp(controls.targetTheta + 0.08, -0.68, 0.68);
}
if (event.key === "ArrowUp") {
controls.targetPhi = THREE.MathUtils.clamp(controls.targetPhi - 0.06, 0.72, 1.42);
}
if (event.key === "ArrowDown") {
controls.targetPhi = THREE.MathUtils.clamp(controls.targetPhi + 0.06, 0.72, 1.42);
}
});
document.querySelector("#frontView").addEventListener("click", () => {
controls.targetTheta = 0;
controls.targetPhi = 1.29;
controls.targetRadius = 14.7;
setActiveButton("frontView");
});
document.querySelector("#perspectiveView").addEventListener("click", () => {
controls.targetTheta = 0.27;
controls.targetPhi = 1.15;
controls.targetRadius = 15.6;
setActiveButton("perspectiveView");
});
function setActiveButton(id) {
document.querySelectorAll(".controls button").forEach(button => {
button.classList.toggle("active", button.id === id);
});
}
let motionEnabled = true;
const motionButton = document.querySelector("#motionButton");
motionButton.addEventListener("click", () => {
motionEnabled = !motionEnabled;
motionButton.textContent = motionEnabled ? "Pause" : "Play";
motionButton.classList.toggle("active", !motionEnabled);
});
/* ------------------------------------------------------------------ */
/* Resize and animation */
/* ------------------------------------------------------------------ */
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
const scratch = new THREE.Vector3();
function animateProfile(profile, time) {
const t = (time * profile.speed) % 1;
profile.curve.getPoint(t, scratch);
profile.orb.position.set(scratch.x, scratch.y, 0.42);
profile.halo.position.copy(profile.orb.position);
const pulse = 1 + Math.sin(time * 4.2) * 0.12;
profile.halo.scale.setScalar(pulse);
}
function animate() {
const elapsed = clock.getElapsedTime();
updateCamera();
if (motionEnabled) {
animateProfile(profileA, elapsed);
animateProfile(profileB, elapsed);
const positions = dustGeometry.attributes.position;
for (let i = 0; i < dustCount; i++) {
const base = dustBase[i];
positions.array[i * 3] = base.x + Math.sin(elapsed * 0.18 + base.phase) * 0.08;
positions.array[i * 3 + 1] = base.y + Math.sin(elapsed * 0.28 + base.phase) * 0.12;
positions.array[i * 3 + 2] = base.z + Math.cos(elapsed * 0.16 + base.phase) * 0.06;
}
positions.needsUpdate = true;
}
renderer.render(scene, camera);
}
updateCamera(true);
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```