Prompt specification
Build or customize the Three.js 3D scene "Same material different mass comparison" 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: Same material different mass comparison
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/same-material-different-mass-comparison-x1470
Scene Description Prompt:
Heat two amounts of the same model substance with equal power for equal time; show smaller temperature change for the larger mass and separate heat capacity from conductivity. Use Three.js from cdnjs in a single HTML file, with stylized solid shapes.
Working Three.js Starter (same-material-different-mass-comparison-x1470):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Thermal Lab — Heat Capacity vs Conductivity</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(12, 25, 43, 0.92);
--panel-soft: rgba(21, 39, 62, 0.76);
--border: rgba(148, 178, 216, 0.18);
--text: #edf5ff;
--muted: #91a7c0;
--cyan: #53d8fb;
--amber: #ffb454;
--red: #ff685f;
--blue: #4285ff;
}
* {
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;
}
button {
color: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#viewport canvas.dragging {
cursor: grabbing;
}
.brand {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
pointer-events: none;
max-width: 410px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 2px;
border-radius: 99px;
background: var(--cyan);
box-shadow: 0 0 16px var(--cyan);
}
h1 {
margin: 0;
font-size: clamp(25px, 3.2vw, 42px);
line-height: 1;
letter-spacing: -0.045em;
}
.brand p {
max-width: 370px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.panel {
position: fixed;
z-index: 10;
top: 22px;
right: 22px;
bottom: 22px;
width: 370px;
overflow: auto;
padding: 18px;
border: 1px solid var(--border);
border-radius: 22px;
background: var(--panel);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.36),
inset 0 1px rgba(255, 255, 255, 0.035);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: #314a68 transparent;
}
.mode-switch {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
margin-bottom: 18px;
padding: 5px;
border: 1px solid var(--border);
border-radius: 14px;
background: rgba(2, 9, 18, 0.48);
}
.mode-switch button {
min-height: 42px;
padding: 9px 10px;
border: 0;
border-radius: 10px;
background: transparent;
color: var(--muted);
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: 160ms ease;
}
.mode-switch button:hover {
color: var(--text);
background: rgba(255, 255, 255, 0.04);
}
.mode-switch button.active {
color: #06101d;
background: var(--cyan);
box-shadow: 0 5px 18px rgba(83, 216, 251, 0.19);
}
.section-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.section-heading h2 {
margin: 0 0 5px;
font-size: 17px;
letter-spacing: -0.02em;
}
.section-heading p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.concept-pill {
flex: 0 0 auto;
padding: 6px 9px;
border: 1px solid rgba(83, 216, 251, 0.25);
border-radius: 99px;
color: var(--cyan);
background: rgba(83, 216, 251, 0.07);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.control {
margin: 0 0 14px;
padding: 13px 14px 12px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel-soft);
}
.control-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
font-size: 12px;
}
.control-top label {
color: #c9d7e7;
font-weight: 650;
}
.value {
color: var(--cyan);
font-variant-numeric: tabular-nums;
font-weight: 800;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 3px 0 0;
appearance: none;
border-radius: 99px;
outline: none;
background: linear-gradient(
90deg,
var(--cyan) 0%,
var(--cyan) var(--fill, 50%),
#243a54 var(--fill, 50%),
#243a54 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
appearance: none;
border: 3px solid #081522;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 1px var(--cyan), 0 0 15px rgba(83, 216, 251, 0.45);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #081522;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 1px var(--cyan);
}
.equal-energy {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 10px;
margin: 4px 0 14px;
padding: 13px;
border: 1px solid rgba(255, 180, 84, 0.22);
border-radius: 14px;
background:
linear-gradient(90deg, rgba(255, 180, 84, 0.1), transparent),
rgba(255, 180, 84, 0.035);
}
.equal-energy .energy {
font-size: 11px;
color: var(--muted);
text-transform: uppercase;
letter-spacing: 0.08em;
}
.equal-energy strong {
display: block;
margin-top: 4px;
color: var(--amber);
font-size: 17px;
letter-spacing: -0.02em;
}
.equal-energy .vs {
color: #7389a2;
font-size: 10px;
font-weight: 800;
}
.sample-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-bottom: 12px;
}
.sample-card {
min-width: 0;
padding: 13px;
border: 1px solid var(--border);
border-radius: 14px;
background: rgba(5, 14, 26, 0.38);
}
.sample-card .name {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.sample-card .mass {
margin: 5px 0 10px;
font-size: 15px;
font-weight: 800;
}
.delta {
color: var(--cyan);
font-size: 25px;
font-weight: 850;
line-height: 1;
letter-spacing: -0.05em;
font-variant-numeric: tabular-nums;
}
.sample-card.large .delta {
color: var(--amber);
}
.delta-label {
margin-top: 4px;
color: var(--muted);
font-size: 10px;
}
.bar-track {
height: 5px;
margin-top: 12px;
overflow: hidden;
border-radius: 99px;
background: #20344b;
}
.bar-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--blue), var(--cyan));
transition: width 180ms ease;
}
.large .bar-fill {
background: linear-gradient(90deg, #ff8b55, var(--amber));
}
.equation {
margin: 12px 0;
padding: 14px;
border: 1px solid rgba(83, 216, 251, 0.18);
border-radius: 14px;
background: rgba(83, 216, 251, 0.055);
}
.equation .formula {
color: var(--text);
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
text-align: center;
}
.equation .formula span {
color: var(--cyan);
}
.equation p {
margin: 9px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
text-align: center;
}
.insight {
padding: 12px 13px;
border-left: 3px solid var(--amber);
border-radius: 0 11px 11px 0;
background: rgba(255, 180, 84, 0.07);
color: #d9e3ef;
font-size: 11px;
line-height: 1.55;
}
.insight strong {
color: var(--amber);
}
.conduct-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin: 12px 0;
}
.conduct-card {
padding: 13px;
border: 1px solid var(--border);
border-radius: 14px;
background: rgba(5, 14, 26, 0.38);
}
.conduct-card .rod-name {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.conduct-card .k-value {
margin: 6px 0 9px;
color: var(--amber);
font-size: 17px;
font-weight: 850;
}
.conduct-card .reach {
color: var(--cyan);
font-size: 21px;
font-weight: 850;
letter-spacing: -0.04em;
}
.conduct-card p {
margin: 4px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.divider {
height: 1px;
margin: 18px 0;
background: var(--border);
}
.panel-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 16px;
}
.panel-actions button {
min-height: 40px;
border: 1px solid var(--border);
border-radius: 11px;
background: rgba(255, 255, 255, 0.035);
color: var(--text);
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: 150ms ease;
}
.panel-actions button:hover {
border-color: rgba(83, 216, 251, 0.45);
background: rgba(83, 216, 251, 0.08);
}
.panel-actions button.primary {
border-color: transparent;
color: #06101d;
background: var(--cyan);
}
.legend {
position: fixed;
z-index: 5;
left: 30px;
bottom: 28px;
width: 205px;
padding: 12px 13px;
border: 1px solid var(--border);
border-radius: 14px;
background: rgba(8, 20, 35, 0.76);
pointer-events: none;
backdrop-filter: blur(12px);
}
.legend-title {
margin-bottom: 8px;
color: #b8c8da;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.gradient {
height: 7px;
border-radius: 99px;
background: linear-gradient(90deg, #2879ff, #53d8fb, #ffb454, #ff685f);
}
.legend-scale {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: var(--muted);
font-size: 9px;
}
.hint {
position: fixed;
z-index: 5;
right: 414px;
bottom: 29px;
color: rgba(196, 213, 231, 0.64);
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
display: none;
min-width: 126px;
padding: 10px 12px;
border: 1px solid rgba(148, 178, 216, 0.22);
border-radius: 12px;
background: rgba(7, 17, 31, 0.82);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
text-align: center;
transform: translate(-50%, -100%);
backdrop-filter: blur(10px);
}
.scene-label.visible {
display: block;
}
.scene-label span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.scene-label strong {
display: block;
margin: 3px 0;
font-size: 16px;
}
.scene-label em {
color: var(--cyan);
font-size: 10px;
font-style: normal;
font-weight: 800;
}
.scene-label.warm em {
color: var(--amber);
}
[hidden] {
display: none !important;
}
@media (max-width: 850px) {
.brand {
top: 17px;
left: 18px;
max-width: calc(100% - 36px);
}
.brand p {
display: none;
}
.brand h1 {
font-size: 27px;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 51vh;
padding: 14px;
border-radius: 18px;
}
.mode-switch {
position: sticky;
top: -14px;
z-index: 2;
margin-top: -2px;
background: rgba(10, 23, 40, 0.97);
}
.legend {
top: 90px;
bottom: auto;
left: 18px;
width: 170px;
}
.hint {
display: none;
}
}
@media (max-width: 480px) {
.sample-grid,
.conduct-grid {
grid-template-columns: 1fr 1fr;
}
.sample-card,
.conduct-card {
padding: 10px;
}
.delta {
font-size: 21px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<header class="brand">
<div class="eyebrow">Interactive thermal lab</div>
<h1>Energy, mass & transport</h1>
<p>
Compare equal heating of different amounts of one substance, then isolate
conductivity from heat capacity.
</p>
</header>
<div id="labels" aria-hidden="true">
<div id="labelSmall" class="scene-label"></div>
<div id="labelLarge" class="scene-label warm"></div>
<div id="labelLow" class="scene-label warm"></div>
<div id="labelHigh" class="scene-label"></div>
</div>
<aside class="panel">
<nav class="mode-switch" aria-label="Experiment mode">
<button id="capacityTab" class="active" aria-selected="true">
01 · Heat capacity
</button>
<button id="conductivityTab" aria-selected="false">
02 · Conductivity
</button>
</nav>
<section id="capacityView">
<div class="section-heading">
<div>
<h2>Equal heat, different masses</h2>
<p>Same substance, heater power, and heating time.</p>
</div>
<div class="concept-pill">Q = mcΔT</div>
</div>
<div class="control">
<div class="control-top">
<label for="massRatio">Large sample mass</label>
<span id="massRatioValue" class="value"></span>
</div>
<input
id="massRatio"
type="range"
min="1.5"
max="4"
step="0.5"
value="3"
aria-label="Mass of the larger sample"
>
</div>
<div class="control">
<div class="control-top">
<label for="power">Equal heater power</label>
<span id="powerValue" class="value"></span>
</div>
<input
id="power"
type="range"
min="250"
max="2000"
step="50"
value="1000"
aria-label="Equal heater power"
>
</div>
<div class="control">
<div class="control-top">
<label for="time">Equal heating time</label>
<span id="timeValue" class="value"></span>
</div>
<input
id="time"
type="range"
min="10"
max="120"
step="5"
value="60"
aria-label="Equal heating time"
>
</div>
<div class="control">
<div class="control-top">
<label for="specificHeat">Specific heat capacity</label>
<span id="specificHeatValue" class="value"></span>
</div>
<input
id="specificHeat"
type="range"
min="500"
max="2000"
step="50"
value="1000"
aria-label="Specific heat capacity"
>
</div>
<div class="equal-energy">
<div class="energy">Energy each<strong id="energyEach"></strong></div>
<div class="vs">EQUAL</div>
<div class="energy">Energy each<strong id="energyEach2"></strong></div>
</div>
<div class="sample-grid">
<article class="sample-card">
<div class="name">Smaller amount</div>
<div class="mass">1 kg</div>
<div id="smallDelta" class="delta"></div>
<div class="delta-label">temperature change</div>
<div class="bar-track"><div id="smallBar" class="bar-fill"></div></div>
</article>
<article class="sample-card large">
<div class="name">Larger amount</div>
<div id="largeMass" class="mass"></div>
<div id="largeDelta" class="delta"></div>
<div class="delta-label">temperature change</div>
<div class="bar-track"><div id="largeBar" class="bar-fill"></div></div>
</article>
</div>
<div class="equation">
<div class="formula">ΔT = <span>Q / (mc)</span></div>
<p>
With equal <em>Q</em> and equal specific heat <em>c</em>,
ΔT is inversely proportional to mass.
</p>
</div>
<div class="insight">
<strong>Notice:</strong> the larger sample warms more slowly because the
same added energy is spread across more material.
</div>
</section>
<section id="conductivityView" hidden>
<div class="section-heading">
<div>
<h2>How far does heat travel?</h2>
<p>Identical rods; only thermal conductivity changes.</p>
</div>
<div class="concept-pill">Heat transport</div>
</div>
<div class="control">
<div class="control-top">
<label for="contrast">High-k conductivity</label>
<span id="contrastValue" class="value"></span>
</div>
<input
id="contrast"
type="range"
min="2"
max="10"
step="0.5"
value="6"
aria-label="Thermal conductivity of the high conductivity rod"
>
</div>
<div class="conduct-grid">
<article class="conduct-card">
<div class="rod-name">Low conductivity</div>
<div id="lowK" class="k-value"></div>
<div id="lowReach" class="reach"></div>
<p>segments warmed above ambient</p>
</article>
<article class="conduct-card">
<div class="rod-name">High conductivity</div>
<div id="highK" class="k-value"></div>
<div id="highReach" class="reach"></div>
<p>segments warmed above ambient</p>
</article>
</div>
<div class="equation">
<div class="formula">Heat flow ∝ <span>conductivity</span></div>
<p>
Conductivity controls the <b>spatial profile</b> and rate of heat
transfer through a material.
</p>
</div>
<div class="insight">
<strong>Different concept:</strong> heat capacity determines how much
temperature changes for a given amount of stored energy. Conductivity
determines how readily heat moves from one place to another.
</div>
<p
id="schematicNote"
style="margin: 12px 2px 0; color: var(--muted); font-size: 10px; line-height: 1.5"
>
The diffusion animation is schematic and time-compressed. Both rods
receive the same heater power and have the same dimensions and heat
capacity.
</p>
</section>
<div class="panel-actions">
<button id="pauseButton" class="primary">Pause animation</button>
<button id="resetButton">Reset experiment</button>
</div>
</aside>
<div class="legend">
<div id="legendTitle" class="legend-title">Sample temperature</div>
<div class="gradient"></div>
<div class="legend-scale">
<span>cooler</span>
<span>warmer</span>
</div>
</div>
<div class="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 $ = (id) => document.getElementById(id);
const viewport = $("viewport");
const state = {
massRatio: 3,
power: 1000,
time: 60,
specificHeat: 1000,
contrast: 6,
mode: "capacity",
running: true
};
const defaults = { ...state };
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 14, 28);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
// Custom camera controls — no addons.
const orbit = {
theta: 0.56,
phi: 1.04,
radius: 11.3,
target: new THREE.Vector3(0, 0.85, 0),
dragging: false,
lastX: 0,
lastY: 0
};
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 resetCamera() {
orbit.theta = 0.56;
orbit.phi = 1.04;
orbit.radius = 11.3;
orbit.target.set(0, 0.85, 0);
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
orbit.dragging = true;
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!orbit.dragging) return;
const dx = event.clientX - orbit.lastX;
const dy = event.clientY - orbit.lastY;
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.005, 0.38, 1.43);
updateCamera();
});
function endDrag(event) {
orbit.dragging = false;
renderer.domElement.classList.remove("dragging");
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
7.2,
17
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
// Lighting and floor.
scene.add(new THREE.HemisphereLight(0x9dcfff, 0x162033, 1.8));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.3);
keyLight.position.set(-4, 9, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x48bfff, 1.8);
rimLight.position.set(6, 4, -7);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0x091524,
roughness: 0.92,
metalness: 0.04
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.34;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(32, 32, 0x15314a, 0x10263b);
grid.position.y = -0.325;
grid.material.transparent = true;
grid.material.opacity = 0.38;
scene.add(grid);
const plinthMaterial = new THREE.MeshStandardMaterial({
color: 0x13243a,
roughness: 0.72,
metalness: 0.16
});
const accentMaterial = new THREE.MeshStandardMaterial({
color: 0x25435e,
roughness: 0.55,
metalness: 0.25
});
function makePlinth(width, depth, y = -0.16) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.3, depth),
plinthMaterial
);
mesh.position.y = y;
mesh.receiveShadow = true;
mesh.castShadow = true;
return mesh;
}
// Shared colors.
const coldColor = new THREE.Color(0x2879ff);
const cyanColor = new THREE.Color(0x53d8fb);
const amberColor = new THREE.Color(0xffb454);
const hotColor = new THREE.Color(0xff685f);
const yellowColor = new THREE.Color(0xffe49a);
function temperatureColor(delta, target) {
const t = THREE.MathUtils.clamp(delta / 110, 0, 1);
if (t < 0.55) {
return target.copy(coldColor).lerp(amberColor, t / 0.55);
}
return target.copy(amberColor).lerp(hotColor, (t - 0.55) / 0.45);
}
function conductionColor(delta, target) {
const t = THREE.MathUtils.clamp(delta / 85, 0, 1);
if (t < 0.38) {
return target.copy(coldColor).lerp(cyanColor, t / 0.38);
}
if (t < 0.72) {
return target
.copy(cyanColor)
.lerp(amberColor, (t - 0.38) / 0.34);
}
return target
.copy(amberColor)
.lerp(yellowColor, (t - 0.72) / 0.28);
}
// ---------------------------------------------------------
// HEAT-CAPACITY EXPERIMENT
// ---------------------------------------------------------
const capacityGroup = new THREE.Group();
scene.add(capacityGroup);
capacityGroup.add(makePlinth(7.2, 4.1));
const heaterMaterials = [];
const sampleMaterials = [];
const thermometerMaterials = [];
const sampleMeshes = [];
const thermometerFills = [];
const sampleAnchors = [];
const heaterGeometry = new THREE.CylinderGeometry(0.86, 0.91, 0.2, 48);
const sampleGeometry = new THREE.CylinderGeometry(0.76, 0.76, 1, 48);
const capGeometry = new THREE.CylinderGeometry(0.77, 0.77, 0.035, 48);
const ringGeometry = new THREE.TorusGeometry(0.79, 0.022, 8, 48);
const sampleXs = [-1.85, 1.85];
sampleXs.forEach((x, index) => {
const heaterMaterial = new THREE.MeshStandardMaterial({
color: 0xff8b3d,
emissive: 0xff5b18,
emissiveIntensity: 1.6,
roughness: 0.4,
metalness: 0.42
});
heaterMaterials.push(heaterMaterial);
const heater = new THREE.Mesh(heaterGeometry, heaterMaterial);
heater.position.set(x, 0.12, 0);
heater.castShadow = true;
heater.receiveShadow = true;
capacityGroup.add(heater);
const support = new THREE.Mesh(
new THREE.CylinderGeometry(0.91, 0.95, 0.16, 48),
accentMaterial
);
support.position.set(x, -0.03, 0);
support.receiveShadow = true;
capacityGroup.add(support);
const sampleMaterial = new THREE.MeshStandardMaterial({
color: coldColor.clone(),
emissive: coldColor.clone(),
emissiveIntensity: 0.08,
roughness: 0.52,
metalness: 0.12
});
sampleMaterials.push(sampleMaterial);
const sample = new THREE.Mesh(sampleGeometry, sampleMaterial);
sample.position.x = x;
sample.castShadow = true;
sample.receiveShadow = true;
capacityGroup.add(sample);
const cap = new THREE.Mesh(capGeometry, sampleMaterial);
cap.position.y = 0.5;
sample.add(cap);
const ring = new THREE.Mesh(ringGeometry, sampleMaterial);
ring.rotation.x = Math.PI / 2;
ring.position.y = -0.28;
sample.add(ring);
sampleMeshes.push(sample);
// Solid thermometer.
const thermometerX = x + 1.02;
const thermometerZ = 0.28;
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 1.9, 18),
new THREE.MeshStandardMaterial({
color: 0xc8d8e8,
roughness: 0.38,
metalness: 0.22
})
);
stem.position.set(thermometerX, 1.22, thermometerZ);
stem.castShadow = true;
capacityGroup.add(stem);
const fillMaterial = new THREE.MeshStandardMaterial({
color: 0x53d8fb,
emissive: 0x238ba8,
emissiveIntensity: 0.22,
roughness: 0.38
});
thermometerMaterials.push(fillMaterial);
const fill = new THREE.Mesh(
new THREE.CylinderGeometry(0.078, 0.078, 1, 18),
fillMaterial
);
fill.position.set(thermometerX, 0.35, thermometerZ);
fill.scale.y = 0.03;
capacityGroup.add(fill);
thermometerFills.push(fill);
const bulb = new THREE.Mesh(
new THREE.SphereGeometry(0.13, 20, 14),
fillMaterial
);
bulb.position.set(thermometerX, 0.25, thermometerZ);
bulb.castShadow = true;
capacityGroup.add(bulb);
const anchor = new THREE.Vector3();
sampleAnchors.push(anchor);
});
// ---------------------------------------------------------
// CONDUCTIVITY EXPERIMENT
// ---------------------------------------------------------
const conductivityGroup = new THREE.Group();
conductivityGroup.visible = false;
scene.add(conductivityGroup);
conductivityGroup.add(makePlinth(7.4, 4.4));
const segmentCount = 30;
const segmentLength = 0.18;
const startX = -2.7;
const ambient = 20;
const rodZ = [-1.16, 1.16];
const highSegments = [];
const lowSegments = [];
const conductionHeaterMaterials = [];
const conductionPulses = [];
const heaterCubeGeometry = new THREE.BoxGeometry(0.55, 0.62, 0.66);
const segmentGeometry = new THREE.BoxGeometry(
segmentLength * 0.92,
0.3,
0.43
);
rodZ.forEach((z, rodIndex) => {
const heaterMaterial = new THREE.MeshStandardMaterial({
color: 0xff8b3d,
emissive: 0xff5b18,
emissiveIntensity: 1.7,
roughness: 0.38,
metalness: 0.44
});
conductionHeaterMaterials.push(heaterMaterial);
const heater = new THREE.Mesh(heaterCubeGeometry, heaterMaterial);
heater.position.set(-3.08, 0.43, z);
heater.castShadow = true;
conductivityGroup.add(heater);
const support = new THREE.Mesh(
new THREE.BoxGeometry(0.68, 0.12, 0.78),
accentMaterial
);
support.position.set(-3.08, 0.07, z);
support.receiveShadow = true;
conductivityGroup.add(support);
const segments = [];
for (let i = 0; i < segmentCount; i++) {
const material = new THREE.MeshStandardMaterial({
color: coldColor.clone(),
emissive: coldColor.clone(),
emissiveIntensity: 0.08,
roughness: 0.56,
metalness: 0.12
});
const segment = new THREE.Mesh(segmentGeometry, material);
segment.position.set(
startX + (i + 0.5) * segmentLength,
0.44,
z
);
segment.castShadow = true;
segment.receiveShadow = true;
conductivityGroup.add(segment);
segments.push(segment);
}
if (rodIndex === 0) {
lowSegments.push(...segments);
} else {
highSegments.push(...segments);
}
const pulseMaterial = new THREE.MeshStandardMaterial({
color: 0xffd27c,
emissive: 0xff7b25,
emissiveIntensity: 2.2,
roughness: 0.28
});
const pulse = new THREE.Mesh(
new THREE.SphereGeometry(0.105, 18, 12),
pulseMaterial
);
pulse.position.set(-2.5, 0.73, z);
conductivityGroup.add(pulse);
conductionPulses.push(pulse);
});
const lowTemperature = new Array(segmentCount).fill(ambient);
const lowNext = new Array(segmentCount).fill(ambient);
const highTemperature = new Array(segmentCount).fill(ambient);
const highNext = new Array(segmentCount).fill(ambient);
let conductionClock = 0;
function simulateConduction(steps) {
const highK = state.contrast;
const lowK = state.contrast / 4;
// Normalized, time-compressed 1D diffusion coefficients.
const highDiffusion = 0.0015 * highK;
const lowDiffusion = 0.0015 * lowK;
const loss = 0.00065;
const source =
0.0032 *
(state.power / 1000) *
Math.sqrt(state.time / 60);
for (let step = 0; step < steps; step++) {
for (let i = 0; i < segmentCount; i++) {
const highLeft = i === 0 ? highTemperature[0] : highTemperature[i - 1];
const highRight =
i === segmentCount - 1 ? ambient : highTemperature[i + 1];
const lowLeft = i === 0 ? lowTemperature[0] : lowTemperature[i - 1];
const lowRight =
i === segmentCount - 1 ? ambient : lowTemperature[i + 1];
highNext[i] =
highTemperature[i] +
highDiffusion *
(highLeft - 2 * highTemperature[i] + highRight) -
loss * (highTemperature[i] - ambient);
lowNext[i] =
lowTemperature[i] +
lowDiffusion *
(lowLeft - 2 * lowTemperature[i] + lowRight) -
loss * (lowTemperature[i] - ambient);
}
highNext[0] += source;
lowNext[0] += source;
for (let i = 0; i < segmentCount; i++) {
highTemperature[i] = highNext[i];
lowTemperature[i] = lowNext[i];
}
}
}
function warmReach(temperatures) {
let reach = 0;
for (const temperature of temperatures) {
if (temperature > ambient + 0.35) reach++;
else break;
}
return reach;
}
function resetConduction() {
lowTemperature.fill(ambient);
lowNext.fill(ambient);
highTemperature.fill(ambient);
highNext.fill(ambient);
conductionClock = 0;
// Pre-roll so the spatial difference is immediately visible.
simulateConduction(4000);
updateConductionReadouts();
}
function updateConductionReadouts() {
$("highK").textContent = `${state.contrast.toFixed(1)} W/m·K`;
$("lowK").textContent = `${(state.contrast / 4).toFixed(1)} W/m·K`;
$("highReach").textContent = `${warmReach(highTemperature)}/${segmentCount}`;
$("lowReach").textContent = `${warmReach(lowTemperature)}/${segmentCount}`;
$("labelHigh").innerHTML = `
<span>High conductivity</span>
<strong>${state.contrast.toFixed(1)} W/m·K</strong>
<em>heat travels farther</em>
`;
$("labelLow").innerHTML = `
<span>Low conductivity</span>
<strong>${(state.contrast / 4).toFixed(1)} W/m·K</strong>
<em>heat stays near the heater</em>
`;
}
// ---------------------------------------------------------
// UI AND CALCULATIONS
// ---------------------------------------------------------
function formatEnergy(joules) {
if (joules >= 1000) {
return `${(joules / 1000).toFixed(1)} kJ`;
}
return `${joules.toFixed(0)} J`;
}
function setRangeFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percentage = ((value - min) / (max - min)) * 100;
input.style.setProperty("--fill", `${percentage}%`);
}
const sampleColor = new THREE.Color();
function updateCapacityExperiment() {
const energy = state.power * state.time;
const smallDelta = energy / (1 * state.specificHeat);
const largeDelta = energy / (state.massRatio * state.specificHeat);
$("massRatioValue").textContent = `${state.massRatio.toFixed(1)} kg`;
$("powerValue").textContent = `${state.power} W`;
$("timeValue").textContent = `${state.time} s`;
$("specificHeatValue").textContent =
`${state.specificHeat} J/(kg·K)`;
$("energyEach").textContent = formatEnergy(energy);
$("energyEach2").textContent = formatEnergy(energy);
$("smallDelta").textContent = `+${smallDelta.toFixed(1)} K`;
$("largeDelta").textContent = `+${largeDelta.toFixed(1)} K`;
$("largeMass").textContent = `${state.massRatio.toFixed(1)} kg`;
const scale = 100 / 130;
$("smallBar").style.width = `${Math.min(100, smallDelta * scale)}%`;
$("largeBar").style.width = `${Math.min(100, largeDelta * scale)}%`;
const smallHeight = 0.72;
const largeHeight = 0.72 * state.massRatio;
sampleMeshes[0].scale.y = smallHeight;
sampleMeshes[0].position.y = 0.31 + smallHeight / 2;
sampleMeshes[1].scale.y = largeHeight;
sampleMeshes[1].position.y = 0.31 + largeHeight / 2;
sampleAnchors[0].set(
sampleXs[0],
0.31 + smallHeight + 0.38,
0
);
sampleAnchors[1].set(
sampleXs[1],
0.31 + largeHeight + 0.38,
0
);
temperatureColor(smallDelta, sampleColor);
sampleMaterials[0].color.copy(sampleColor);
sampleMaterials[0].emissive.copy(sampleColor);
temperatureColor(largeDelta, sampleColor);
sampleMaterials[1].color.copy(sampleColor);
sampleMaterials[1].emissive.copy(sampleColor);
const fillFraction = THREE.MathUtils.clamp(smallDelta / 120, 0.02, 1);
thermometerFills[0].scale.y = 1.65 * fillFraction;
thermometerFills[0].position.y = 0.32 + (1.65 * fillFraction) / 2;
thermometerMaterials[0].color.copy(sampleMaterials[0].color);
thermometerMaterials[0].emissive.copy(sampleMaterials[0].color);
const largeFillFraction = THREE.MathUtils.clamp(largeDelta / 120, 0.02, 1);
thermometerFills[1].scale.y = 1.65 * largeFillFraction;
thermometerFills[1].position.y = 0.32 + (1.65 * largeFillFraction) / 2;
thermometerMaterials[1].color.copy(sampleMaterials[1].color);
thermometerMaterials[1].emissive.copy(sampleMaterials[1].color);
$("labelSmall").innerHTML = `
<span>Smaller amount</span>
<strong>1 kg</strong>
<em>ΔT +${smallDelta.toFixed(1)} K</em>
`;
$("labelLarge").innerHTML = `
<span>Larger amount</span>
<strong>${state.massRatio.toFixed(1)} kg</strong>
<em>ΔT +${largeDelta.toFixed(1)} K</em>
`;
["massRatio", "power", "time", "specificHeat"].forEach((id) => {
setRangeFill($(id));
});
}
function readState() {
state.massRatio = Number($("massRatio").value);
state.power = Number($("power").value);
state.time = Number($("time").value);
state.specificHeat = Number($("specificHeat").value);
state.contrast = Number($("contrast").value);
}
[
"massRatio",
"power",
"time",
"specificHeat",
"contrast"
].forEach((id) => {
$(id).addEventListener("input", () => {
readState();
updateCapacityExperiment();
if (id === "contrast" || id === "power" || id === "time") {
resetConduction();
} else {
updateConductionReadouts();
}
setRangeFill($(id));
});
});
function setMode(mode) {
state.mode = mode;
const capacity = mode === "capacity";
capacityGroup.visible = capacity;
conductivityGroup.visible = !capacity;
$("capacityView").hidden = !capacity;
$("conductivityView").hidden = capacity;
$("capacityTab").classList.toggle("active", capacity);
$("conductivityTab").classList.toggle("active", !capacity);
$("capacityTab").setAttribute("aria-selected", String(capacity));
$("conductivityTab").setAttribute("aria-selected", String(!capacity));
$("legendTitle").textContent = capacity
? "Sample temperature"
: "Along-rod temperature";
if (!capacity) {
resetConduction();
}
}
$("capacityTab").addEventListener("click", () => setMode("capacity"));
$("conductivityTab").addEventListener("click", () =>
setMode("conductivity")
);
$("pauseButton").addEventListener("click", () => {
state.running = !state.running;
$("pauseButton").textContent = state.running
? "Pause animation"
: "Resume animation";
});
$("resetButton").addEventListener("click", () => {
Object.assign(state, defaults);
$("massRatio").value = state.massRatio;
$("power").value = state.power;
$("time").value = state.time;
$("specificHeat").value = state.specificHeat;
$("contrast").value = state.contrast;
state.running = true;
$("pauseButton").textContent = "Pause animation";
readState();
updateCapacityExperiment();
resetConduction();
resetCamera();
setMode("capacity");
});
// Projected HTML labels.
const projected = new THREE.Vector3();
function placeLabel(element, anchor) {
projected.copy(anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
element.style.display = visible ? "block" : "none";
if (!visible) return;
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
function updateLabels() {
if (state.mode === "capacity") {
placeLabel($("labelSmall"), sampleAnchors[0]);
placeLabel($("labelLarge"), sampleAnchors[1]);
} else {
placeLabel(
$("labelLow"),
new THREE.Vector3(2.35, 1.02, rodZ[0])
);
placeLabel(
$("labelHigh"),
new THREE.Vector3(2.35, 1.02, rodZ[1])
);
}
}
function onResize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
// Initial state.
readState();
updateCapacityExperiment();
resetConduction();
updateCamera();
// Animation.
const clock = new THREE.Clock();
let elapsed = 0;
let readoutTimer = 0;
const rodColor = new THREE.Color();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (state.running) {
elapsed += delta;
}
const pulse = 0.5 + 0.5 * Math.sin(elapsed * 5.2);
heaterMaterials.forEach((material) => {
material.emissiveIntensity = 1.1 + pulse * 2.0;
});
conductionHeaterMaterials.forEach((material) => {
material.emissiveIntensity = 1.1 + pulse * 2.0;
});
if (state.mode === "conductivity") {
if (state.running) {
const steps = Math.floor(delta * 480);
if (steps > 0) simulateConduction(steps);
conductionClock += delta;
}
for (let i = 0; i < segmentCount; i++) {
const highDelta = highTemperature[i] - ambient;
const lowDelta = lowTemperature[i] - ambient;
conductionColor(highDelta, rodColor);
highSegments[i].material.color.copy(rodColor);
highSegments[i].material.emissive.copy(rodColor);
conductionColor(lowDelta, rodColor);
lowSegments[i].material.color.copy(rodColor);
lowSegments[i].material.emissive.copy(rodColor);
}
const highSpeed = 0.1 + state.contrast * 0.025;
const lowSpeed = 0.1 + (state.contrast / 4) * 0.025;
const lowProgress = (conductionClock * lowSpeed) % 1;
const highProgress = (conductionClock * highSpeed) % 1;
conductionPulses[0].position.x = -2.48 + lowProgress * 5.05;
conductionPulses[1].position.x = -2.48 + highProgress * 5.05;
readoutTimer += delta;
if (readoutTimer > 0.2) {
readoutTimer = 0;
updateConductionReadouts();
}
}
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```