Prompt specification
Build or customize the Three.js 3D scene "Bimetal strip bending analogy" 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: Bimetal strip bending analogy
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/bimetal-strip-bending-analogy-x1506
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring thermal expansion of solid materials. Join two thin strips with different expansion coefficients and animate schematic curvature during heating; label the shape approximate and show which side expands more. Stylized solid forms.
Working Three.js Starter (bimetal-strip-bending-analogy-x1506):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bimetal Strip — Thermal Expansion</title>
<style>
:root {
color-scheme: dark;
--bg: #07141e;
--panel: rgba(10, 28, 39, 0.82);
--line: rgba(151, 210, 229, 0.18);
--text: #e9f7fb;
--muted: #8daebc;
--hot: #ff8a36;
--cool: #34c5df;
}
* {
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;
color: var(--text);
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.25),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.title-panel {
top: 22px;
left: 22px;
width: 350px;
padding: 20px 22px;
}
.eyebrow {
color: #78d8ed;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 6px;
font-size: clamp(25px, 3vw, 38px);
font-weight: 650;
line-height: 1.02;
letter-spacing: -0.04em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.formula {
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #b7d4df;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
line-height: 1.5;
}
.legend-panel {
left: 22px;
bottom: 22px;
width: 350px;
padding: 17px 18px;
}
.legend-title {
margin-bottom: 12px;
color: #bad3dd;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 12px 1fr auto;
gap: 11px;
align-items: center;
margin: 11px 0;
}
.swatch {
width: 11px;
height: 32px;
border-radius: 8px;
box-shadow: 0 0 16px currentColor;
}
.swatch.hot {
color: var(--hot);
background: linear-gradient(#ffb15c, #ed7628);
}
.swatch.cool {
color: var(--cool);
background: linear-gradient(#68e3f3, #1398b9);
}
.layer-name {
font-size: 13px;
font-weight: 700;
}
.layer-detail {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.layer-tag {
padding: 5px 7px;
border: 1px solid currentColor;
border-radius: 6px;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.1em;
}
.hot-text {
color: var(--hot);
}
.cool-text {
color: var(--cool);
}
.explanation {
margin: 14px 0 0;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #abc6d1;
font-size: 11px;
line-height: 1.55;
}
.temperature-panel {
top: 22px;
right: 22px;
width: 240px;
padding: 18px;
}
.temperature-heading {
display: flex;
align-items: center;
justify-content: space-between;
color: #a8c5d0;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.phase {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--hot);
letter-spacing: 0.08em;
}
.phase-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.temperature {
margin: 9px 0 12px;
font-size: 43px;
font-weight: 620;
line-height: 1;
letter-spacing: -0.05em;
font-variant-numeric: tabular-nums;
}
.temperature small {
color: var(--muted);
font-size: 17px;
font-weight: 500;
}
.temperature-track {
height: 5px;
overflow: hidden;
border-radius: 10px;
background: rgba(255, 255, 255, 0.08);
}
.temperature-fill {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #26bcd5, #ff8a36);
box-shadow: 0 0 15px #ff7430;
transition: width 0.08s linear;
}
.strain {
display: flex;
justify-content: space-between;
margin-top: 10px;
color: var(--muted);
font-size: 10px;
}
.strain strong {
color: #d9edf3;
font-weight: 650;
font-variant-numeric: tabular-nums;
}
.controls-panel {
right: 22px;
bottom: 22px;
width: 240px;
padding: 14px;
}
.button-row {
display: flex;
gap: 8px;
}
button {
flex: 1;
min-height: 36px;
border: 1px solid rgba(130, 210, 230, 0.24);
border-radius: 9px;
background: rgba(84, 177, 201, 0.12);
color: #dff7fc;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(130, 225, 244, 0.5);
background: rgba(84, 177, 201, 0.22);
}
button:active {
transform: translateY(1px);
}
.controls-help {
margin: 10px 2px 0;
color: #789aa8;
font-size: 9px;
text-align: center;
letter-spacing: 0.04em;
}
.caption {
position: fixed;
z-index: 9;
left: 50%;
bottom: 24px;
transform: translateX(-50%);
padding: 9px 14px;
border: 1px solid rgba(255, 157, 74, 0.28);
border-radius: 999px;
background: rgba(25, 22, 18, 0.78);
color: #ffc58f;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-align: center;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
}
.world-label {
position: fixed;
z-index: 5;
display: flex;
align-items: center;
gap: 9px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 10px;
background: rgba(7, 20, 30, 0.86);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25);
pointer-events: none;
transform: translate(-50%, -100%);
white-space: nowrap;
transition: opacity 100ms linear;
}
.world-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 17px;
background: currentColor;
opacity: 0.45;
}
.world-label .label-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
.world-label strong {
display: block;
color: #f1fbfd;
font-size: 10px;
letter-spacing: 0.08em;
}
.world-label small {
display: block;
margin-top: 2px;
color: currentColor;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
}
#highLabel {
color: var(--hot);
}
#lowLabel {
color: var(--cool);
}
@media (max-width: 800px) {
.title-panel {
top: 12px;
left: 12px;
width: min(330px, calc(100vw - 24px));
padding: 15px 17px;
}
.formula,
.legend-panel .explanation {
display: none;
}
.temperature-panel {
top: 132px;
right: 12px;
width: 190px;
padding: 13px;
}
.temperature {
font-size: 34px;
}
.legend-panel {
left: 12px;
bottom: 12px;
width: 260px;
padding: 12px;
}
.legend-row {
margin: 7px 0;
}
.controls-panel {
right: 12px;
bottom: 12px;
width: 190px;
}
.caption {
display: none;
}
.world-label {
padding: 6px 8px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<section class="panel title-panel">
<div class="eyebrow">Thermal expansion / bimetal strip</div>
<h1>Two solids.<br />One curved result.</h1>
<p class="subtitle">
Bonded layers expand by different amounts when heated.
</p>
<div class="formula">
κ ∝ (α<sub>high</sub> − α<sub>low</sub>) · ΔT / thickness
</div>
</section>
<section class="panel temperature-panel">
<div class="temperature-heading">
<span>Temperature</span>
<span class="phase">
<span class="phase-dot"></span>
<span id="phaseText">HEATING</span>
</span>
</div>
<div class="temperature">
<span id="temperatureValue">22</span><small> °C</small>
</div>
<div class="temperature-track">
<div class="temperature-fill" id="temperatureFill"></div>
</div>
<div class="strain">
<span>Differential strain</span>
<strong id="strainValue">0.00%</strong>
</div>
</section>
<section class="panel legend-panel">
<div class="legend-title">Layer behavior</div>
<div class="legend-row">
<div class="swatch hot"></div>
<div>
<div class="layer-name">Brass layer</div>
<div class="layer-detail">α ≈ 19 × 10⁻⁶ / K</div>
</div>
<div class="layer-tag hot-text">OUTER</div>
</div>
<div class="legend-row">
<div class="swatch cool"></div>
<div>
<div class="layer-name">Steel layer</div>
<div class="layer-detail">α ≈ 12 × 10⁻⁶ / K</div>
</div>
<div class="layer-tag cool-text">INNER</div>
</div>
<p class="explanation">
Brass wants to lengthen more, so it becomes the longer outer arc.
The bonded pair therefore curls toward the lower-expansion steel layer.
</p>
</section>
<section class="panel controls-panel">
<div class="button-row">
<button id="pauseButton" type="button">Pause cycle</button>
<button id="resetButton" type="button">Restart heat</button>
</div>
<p class="controls-help">DRAG TO ORBIT · SCROLL TO ZOOM</p>
</section>
<div class="caption">
Approximate schematic · curvature exaggerated · not to scale
</div>
<div class="world-label" id="highLabel">
<span class="label-dot"></span>
<div>
<strong>BRASS</strong>
<small>HIGH α · MORE EXPANSION</small>
</div>
</div>
<div class="world-label" id="lowLabel">
<span class="label-dot"></span>
<div>
<strong>STEEL</strong>
<small>LOW α · LESS EXPANSION</small>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene setup
// ------------------------------------------------------------
const stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D bimetal strip demonstrating differential thermal expansion"
);
renderer.domElement.tabIndex = 0;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07141e);
scene.fog = new THREE.Fog(0x07141e, 13, 27);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, -0.05, 0);
const orbit = {
radius: 12.5,
theta: 0.68,
phi: 0.38
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
const cosPhi = Math.cos(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * Math.sin(orbit.theta) * cosPhi,
cameraTarget.y + orbit.radius * sinPhi,
cameraTarget.z + orbit.radius * Math.cos(orbit.theta) * cosPhi
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(
0xa7e8ff,
0x17242b,
1.8
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xe7f8ff, 3.6);
keyLight.position.set(4, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x3ac9ef, 2.1);
rimLight.position.set(-7, 3, -6);
scene.add(rimLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x0a1b24,
roughness: 0.9,
metalness: 0.05
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(36, 30),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.12;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(
28,
28,
0x286270,
0x14333e
);
grid.position.y = -1.105;
const gridMaterials = Array.isArray(grid.material)
? grid.material
: [grid.material];
gridMaterials.forEach((material) => {
material.transparent = true;
material.opacity = 0.28;
});
scene.add(grid);
// ------------------------------------------------------------
// Stylized heat source
// ------------------------------------------------------------
const heater = new THREE.Group();
scene.add(heater);
const heaterBase = new THREE.Mesh(
new THREE.CylinderGeometry(1.9, 2.08, 0.2, 64),
new THREE.MeshStandardMaterial({
color: 0x172b33,
metalness: 0.55,
roughness: 0.38
})
);
heaterBase.position.y = -0.99;
heaterBase.castShadow = true;
heaterBase.receiveShadow = true;
heater.add(heaterBase);
const heaterMaterial = new THREE.MeshStandardMaterial({
color: 0x9f291b,
emissive: 0xff3b18,
emissiveIntensity: 0.8,
metalness: 0.18,
roughness: 0.46
});
const heaterGlow = new THREE.Mesh(
new THREE.CylinderGeometry(1.42, 1.54, 0.09, 64),
heaterMaterial
);
heaterGlow.position.y = -0.84;
heaterGlow.receiveShadow = true;
heater.add(heaterGlow);
const heatRings = [];
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0xff6535,
transparent: true,
opacity: 0.15,
depthWrite: false
});
[0.72, 1.03, 1.34].forEach((radius, index) => {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.018 + index * 0.004, 8, 80),
ringMaterial.clone()
);
ring.rotation.x = Math.PI / 2;
ring.position.y = -0.765 + index * 0.012;
heater.add(ring);
heatRings.push(ring);
});
const heatLight = new THREE.PointLight(0xff4d24, 0, 7, 2);
heatLight.position.set(0, -0.45, 0);
scene.add(heatLight);
// ------------------------------------------------------------
// Swept-strip geometry
// ------------------------------------------------------------
const STRIP_LENGTH = 7.4;
const STRIP_WIDTH = 1.22;
const STRIP_THICKNESS = 0.22;
const SEGMENTS = 72;
const BASE_Y = 0.25;
const MAX_CURVATURE = 0.065;
const AMBIENT_TEMP = 22;
const MAX_TEMP = 320;
const brassMaterial = new THREE.MeshStandardMaterial({
color: 0xf39a38,
emissive: 0x4a1700,
emissiveIntensity: 0.05,
metalness: 0.38,
roughness: 0.28,
flatShading: true
});
const steelMaterial = new THREE.MeshStandardMaterial({
color: 0x28b8d8,
emissive: 0x002f3c,
emissiveIntensity: 0.08,
metalness: 0.58,
roughness: 0.31,
flatShading: true
});
function createStripGeometry() {
const geometry = new THREE.BufferGeometry();
const vertexCount = (SEGMENTS + 1) * 4;
geometry.setAttribute(
"position",
new THREE.BufferAttribute(
new Float32Array(vertexCount * 3),
3
).setUsage(THREE.DynamicDrawUsage)
);
const indices = [];
for (let i = 0; i < SEGMENTS; i++) {
const a = i * 4;
const b = (i + 1) * 4;
for (let side = 0; side < 4; side++) {
const next = (side + 1) % 4;
indices.push(
a + side, a + next, b + next,
a + side, b + next, b + side
);
}
}
const end = SEGMENTS * 4;
indices.push(
0, 3, 2,
0, 2, 1,
end, end + 1, end + 2,
end, end + 2, end + 3
);
geometry.setIndex(indices);
return geometry;
}
function createDynamicLine() {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(
new Float32Array((SEGMENTS + 1) * 3),
3
).setUsage(THREE.DynamicDrawUsage)
);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color: 0x07131a,
transparent: true,
opacity: 0.9
})
);
line.frustumCulled = false;
scene.add(line);
return line;
}
const brassStrip = new THREE.Mesh(
createStripGeometry(),
brassMaterial
);
brassStrip.castShadow = true;
brassStrip.receiveShadow = true;
brassStrip.frustumCulled = false;
scene.add(brassStrip);
const steelStrip = new THREE.Mesh(
createStripGeometry(),
steelMaterial
);
steelStrip.castShadow = true;
steelStrip.receiveShadow = true;
steelStrip.frustumCulled = false;
scene.add(steelStrip);
const seamLine = createDynamicLine();
const brassEdgeLine = createDynamicLine();
const steelEdgeLine = createDynamicLine();
brassEdgeLine.material.color.setHex(0xffd092);
brassEdgeLine.material.opacity = 0.42;
steelEdgeLine.material.color.setHex(0x91efff);
steelEdgeLine.material.opacity = 0.38;
function curveAt(x, curvature) {
const y = BASE_Y - curvature * x * x;
const slope = -2 * curvature * x;
const theta = Math.atan(slope);
const point = new THREE.Vector3(x, y, 0);
const normal = new THREE.Vector3(
-Math.sin(theta),
Math.cos(theta),
0
);
const tangent = new THREE.Vector3(1, slope, 0).normalize();
return { point, normal, tangent };
}
function updateStripGeometry(curvature) {
const halfThickness = STRIP_THICKNESS * 0.5;
const crossSection = [
[-halfThickness, -STRIP_WIDTH * 0.5],
[ halfThickness, -STRIP_WIDTH * 0.5],
[ halfThickness, STRIP_WIDTH * 0.5],
[-halfThickness, STRIP_WIDTH * 0.5]
];
function writeStrip(mesh, centerOffset) {
const position = mesh.geometry.attributes.position;
for (let i = 0; i <= SEGMENTS; i++) {
const x =
-STRIP_LENGTH * 0.5 +
(STRIP_LENGTH * i) / SEGMENTS;
const { point, normal } = curveAt(x, curvature);
const center = point
.clone()
.addScaledVector(normal, centerOffset);
for (let corner = 0; corner < 4; corner++) {
const [localY, localZ] = crossSection[corner];
const index = i * 4 + corner;
position.setXYZ(
index,
center.x + normal.x * localY,
center.y + normal.y * localY,
center.z + localZ
);
}
}
position.needsUpdate = true;
mesh.geometry.computeVertexNormals();
}
// Upper layer: high-expansion brass.
// Lower layer: low-expansion steel.
writeStrip(brassStrip, halfThickness);
writeStrip(steelStrip, -halfThickness);
function writeLine(line, mode) {
const position = line.geometry.attributes.position;
for (let i = 0; i <= SEGMENTS; i++) {
const x =
-STRIP_LENGTH * 0.5 +
(STRIP_LENGTH * i) / SEGMENTS;
const { point, normal } = curveAt(x, curvature);
let worldPoint;
if (mode === "seam") {
worldPoint = point;
} else if (mode === "brass") {
worldPoint = point.clone().addScaledVector(
normal,
STRIP_THICKNESS
);
} else {
worldPoint = point.clone().addScaledVector(
normal,
-STRIP_THICKNESS
);
}
worldPoint.z = STRIP_WIDTH * 0.5 + 0.006;
position.setXYZ(i, worldPoint.x, worldPoint.y, worldPoint.z);
}
position.needsUpdate = true;
}
writeLine(seamLine, "seam");
writeLine(brassEdgeLine, "brass");
writeLine(steelEdgeLine, "steel");
}
updateStripGeometry(0);
// ------------------------------------------------------------
// Expansion arrows
// ------------------------------------------------------------
function createDoubleArrow(color) {
const forward = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(),
1,
color,
0.28,
0.18
);
const backward = new THREE.ArrowHelper(
new THREE.Vector3(-1, 0, 0),
new THREE.Vector3(),
1,
color,
0.28,
0.18
);
[forward, backward].forEach((arrow) => {
arrow.line.material.transparent = true;
arrow.cone.material.transparent = true;
arrow.renderOrder = 4;
scene.add(arrow);
});
return { forward, backward };
}
const highArrow = createDoubleArrow(0xff9c48);
const lowArrow = createDoubleArrow(0x67e4f5);
function setArrowOpacity(arrow, opacity) {
arrow.line.material.opacity = opacity;
arrow.cone.material.opacity = opacity;
}
function updateDoubleArrow(pair, origin, direction, length, opacity) {
const endpoint = origin
.clone()
.addScaledVector(direction, length);
pair.forward.position.copy(origin);
pair.forward.setDirection(direction);
pair.forward.setLength(length, 0.28, 0.18);
pair.backward.position.copy(endpoint);
pair.backward.setDirection(direction.clone().negate());
pair.backward.setLength(length, 0.28, 0.18);
setArrowOpacity(pair.forward, opacity);
setArrowOpacity(pair.backward, opacity);
}
// ------------------------------------------------------------
// UI and projected labels
// ------------------------------------------------------------
const temperatureValue = document.getElementById("temperatureValue");
const temperatureFill = document.getElementById("temperatureFill");
const phaseText = document.getElementById("phaseText");
const phaseDot = document.querySelector(".phase-dot");
const strainValue = document.getElementById("strainValue");
const pauseButton = document.getElementById("pauseButton");
const resetButton = document.getElementById("resetButton");
const highLabel = document.getElementById("highLabel");
const lowLabel = document.getElementById("lowLabel");
const highAnchor = new THREE.Vector3();
const lowAnchor = new THREE.Vector3();
function placeLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
element.style.opacity = visible ? "1" : "0";
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
// ------------------------------------------------------------
// Direct camera controls — no external control modules
// ------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.0045,
0.14,
1.22
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("pointerleave", () => {
if (!dragging) renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
7.2,
18
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.style.cursor = "grab";
// ------------------------------------------------------------
// Thermal cycle
// ------------------------------------------------------------
const CYCLE_DURATION = 16;
let simulationTime = 0;
let paused = false;
function smoothstep(value) {
const x = THREE.MathUtils.clamp(value, 0, 1);
return x * x * (3 - 2 * x);
}
function thermalState(time) {
const cycle = time % CYCLE_DURATION;
if (cycle < 6) {
return {
heat: smoothstep(cycle / 6),
phase: "HEATING",
color: "#ff8a36"
};
}
if (cycle < 9) {
return {
heat: 1,
phase: "HOT HOLD",
color: "#ff5d38"
};
}
return {
heat: 1 - smoothstep((cycle - 9) / 7),
phase: "COOLING",
color: "#5dcfe4"
};
}
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume cycle" : "Pause cycle";
});
resetButton.addEventListener("click", () => {
simulationTime = 0;
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
simulationTime += delta;
}
const state = thermalState(simulationTime);
const curvature = MAX_CURVATURE * state.heat;
const temperature =
AMBIENT_TEMP +
(MAX_TEMP - AMBIENT_TEMP) * state.heat;
const differentialStrain =
(19 - 12) *
1e-6 *
(temperature - AMBIENT_TEMP) *
100;
updateStripGeometry(curvature);
temperatureValue.textContent = Math.round(temperature);
temperatureFill.style.width = `${state.heat * 100}%`;
phaseText.textContent = state.phase;
phaseText.style.color = state.color;
phaseDot.style.color = state.color;
strainValue.textContent = `${differentialStrain.toFixed(2)}%`;
const pulse =
0.5 +
0.5 *
Math.sin(simulationTime * 3.3);
heaterMaterial.emissiveIntensity =
0.45 + state.heat * (1.5 + pulse * 1.1);
heatLight.intensity = state.heat * (8 + pulse * 4);
heatRings.forEach((ring, index) => {
const ringPulse =
1 +
state.heat *
(0.025 + pulse * 0.035) *
(index + 1) *
0.45;
ring.scale.setScalar(ringPulse);
ring.material.opacity =
0.06 + state.heat * (0.18 + pulse * 0.12);
});
// Higher-expansion arrow becomes visibly longer.
const arrowCurve = curveAt(-2.15, curvature);
const frontZ = STRIP_WIDTH * 0.5 + 0.2;
const highOrigin = arrowCurve.point
.clone()
.addScaledVector(
arrowCurve.normal,
STRIP_THICKNESS + 0.12
);
highOrigin.z = frontZ;
const lowOrigin = arrowCurve.point
.clone()
.addScaledVector(
arrowCurve.normal,
-STRIP_THICKNESS - 0.12
);
lowOrigin.z = frontZ;
updateDoubleArrow(
highArrow,
highOrigin,
arrowCurve.tangent,
2.15 + state.heat * 1.25,
0.3 + state.heat * 0.7
);
updateDoubleArrow(
lowArrow,
lowOrigin,
arrowCurve.tangent,
2.15 + state.heat * 0.5,
0.26 + state.heat * 0.62
);
const highCurve = curveAt(-2.85, curvature);
highAnchor
.copy(highCurve.point)
.addScaledVector(
highCurve.normal,
STRIP_THICKNESS + 0.2
);
highAnchor.z = STRIP_WIDTH * 0.5 + 0.06;
const lowCurve = curveAt(1.05, curvature);
lowAnchor
.copy(lowCurve.point)
.addScaledVector(
lowCurve.normal,
-STRIP_THICKNESS - 0.2
);
lowAnchor.z = STRIP_WIDTH * 0.5 + 0.06;
placeLabel(highLabel, highAnchor);
placeLabel(lowLabel, lowAnchor);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```