Prompt specification
Build or customize the Three.js 3D scene "Heating-curve stage demonstration" 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: Heating-curve stage demonstration
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/heating-curve-stage-demonstration-x1490
Scene Description Prompt:
Link a stylized material sample to an energy–temperature graph showing idealized warming, melting, and further warming. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (heating-curve-stage-demonstration-x1490):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Thermal Phase Study</title>
<style>
:root {
color-scheme: dark;
--bg: #071014;
--panel: #0d181d;
--panel-soft: #101e23;
--line: #21343a;
--line-soft: #172a30;
--text: #edf7f5;
--muted: #8da5a8;
--phase: #78e0cf;
--teal: #78e0cf;
--amber: #ffc86b;
--coral: #ff805f;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
}
body {
background:
radial-gradient(circle at 12% 0%, rgba(55, 128, 124, 0.13), transparent 30rem),
radial-gradient(circle at 95% 80%, rgba(255, 128, 95, 0.08), transparent 34rem),
var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
overflow-x: hidden;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.app {
width: min(1480px, 100%);
margin: 0 auto;
padding: 24px;
}
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
margin-bottom: 20px;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
width: 44px;
height: 44px;
border: 1px solid #315058;
border-radius: 13px;
display: grid;
place-items: center;
background:
linear-gradient(135deg, rgba(120, 224, 207, 0.18), rgba(255, 128, 95, 0.08));
box-shadow: inset 0 1px rgba(255, 255, 255, 0.07);
}
.brand-mark svg {
width: 25px;
height: 25px;
}
.brand-title {
margin: 0;
font-size: 15px;
font-weight: 750;
letter-spacing: 0.02em;
}
.brand-subtitle {
margin: 3px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.top-note {
color: var(--muted);
font-size: 12px;
letter-spacing: 0.04em;
}
.layout {
display: grid;
grid-template-columns: minmax(0, 1.08fr) minmax(440px, 0.92fr);
gap: 18px;
align-items: stretch;
}
.panel {
position: relative;
min-width: 0;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 24px;
background: linear-gradient(145deg, rgba(17, 31, 36, 0.96), rgba(8, 17, 21, 0.98));
box-shadow:
0 30px 70px rgba(0, 0, 0, 0.24),
inset 0 1px rgba(255, 255, 255, 0.025);
}
/* 3D stage */
.stage {
min-height: 710px;
isolation: isolate;
}
.viewport {
position: absolute;
inset: 0;
z-index: 0;
background:
radial-gradient(circle at 51% 44%, rgba(75, 135, 132, 0.12), transparent 32%),
linear-gradient(180deg, #0b171c, #071014);
}
.viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
.viewport canvas.dragging {
cursor: grabbing;
}
.stage-top {
position: absolute;
z-index: 3;
top: 23px;
left: 23px;
right: 23px;
display: flex;
align-items: center;
justify-content: space-between;
pointer-events: none;
}
.live-label {
display: flex;
align-items: center;
gap: 8px;
color: #a9bec0;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--phase);
box-shadow: 0 0 14px var(--phase);
transition: background 250ms ease, box-shadow 250ms ease;
}
.view-button {
pointer-events: auto;
border: 1px solid #2a4047;
border-radius: 999px;
padding: 8px 12px;
background: rgba(10, 23, 28, 0.75);
color: #b8cbcd;
font-size: 11px;
cursor: pointer;
transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}
.view-button:hover {
border-color: #4b7478;
color: white;
background: rgba(19, 38, 43, 0.9);
}
.stage-copy {
position: absolute;
z-index: 2;
left: 28px;
top: 80px;
width: min(270px, calc(100% - 56px));
pointer-events: none;
}
.phase-chip {
display: inline-flex;
align-items: center;
min-height: 26px;
padding: 0 10px;
border: 1px solid color-mix(in srgb, var(--chip-color) 40%, transparent);
border-radius: 999px;
background: color-mix(in srgb, var(--chip-color) 9%, transparent);
color: var(--chip-color);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
}
.stage-copy h2 {
margin: 13px 0 8px;
max-width: 240px;
font-size: clamp(28px, 3vw, 42px);
line-height: 1.02;
letter-spacing: -0.045em;
font-weight: 680;
}
.stage-copy p {
margin: 0;
max-width: 245px;
color: #91a8aa;
font-size: 13px;
line-height: 1.6;
}
.readout {
position: absolute;
z-index: 2;
right: 24px;
bottom: 24px;
display: grid;
grid-template-columns: 1fr 1fr;
min-width: 254px;
overflow: hidden;
border: 1px solid #294047;
border-radius: 16px;
background: rgba(8, 18, 22, 0.82);
backdrop-filter: blur(14px);
pointer-events: none;
}
.readout-cell {
padding: 13px 16px;
}
.readout-cell + .readout-cell {
border-left: 1px solid #24373d;
}
.readout-label {
color: #789296;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.readout-value {
margin-top: 4px;
color: var(--phase);
font-size: 23px;
font-weight: 650;
letter-spacing: -0.04em;
transition: color 250ms ease;
}
.orbit-hint {
position: absolute;
z-index: 2;
left: 26px;
bottom: 26px;
color: #587075;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.1em;
pointer-events: none;
}
/* Graph panel */
.graph-panel {
min-height: 710px;
padding: 26px 27px 24px;
display: flex;
flex-direction: column;
}
.graph-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
}
.eyebrow {
margin: 0 0 7px;
color: #718e92;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.graph-header h2 {
margin: 0;
font-size: 24px;
line-height: 1.15;
letter-spacing: -0.035em;
font-weight: 650;
}
.graph-header p {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.legend {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px 13px;
max-width: 230px;
padding-top: 3px;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
color: #8fa6a9;
font-size: 10px;
white-space: nowrap;
}
.legend-dot {
width: 7px;
height: 7px;
border-radius: 50%;
}
.graph-wrap {
position: relative;
flex: 1;
min-height: 420px;
margin-top: 13px;
}
#heatGraph {
display: block;
width: 100%;
height: 100%;
min-height: 420px;
overflow: visible;
touch-action: none;
}
.grid-line {
stroke: #203138;
stroke-width: 1;
stroke-dasharray: 3 7;
}
.axis-line {
stroke: #3a5157;
stroke-width: 1.2;
}
.axis-label {
fill: #6f898e;
font-size: 10px;
font-family: inherit;
}
.axis-title {
fill: #9bb0b3;
font-size: 11px;
font-weight: 650;
font-family: inherit;
}
.phase-label {
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
font-family: inherit;
}
.heat-path-shadow {
fill: none;
stroke: rgba(120, 224, 207, 0.12);
stroke-width: 12;
stroke-linecap: round;
stroke-linejoin: round;
filter: blur(5px);
}
.heat-path {
fill: none;
stroke: url(#heatGradient);
stroke-width: 4;
stroke-linecap: round;
stroke-linejoin: round;
}
.marker-line {
stroke: #d7e8e7;
stroke-width: 1;
stroke-dasharray: 3 5;
opacity: 0.45;
}
.marker-halo {
fill: rgba(255, 255, 255, 0.1);
stroke: rgba(255, 255, 255, 0.45);
stroke-width: 1;
}
.marker-dot {
fill: white;
stroke: #0d181d;
stroke-width: 3;
}
.marker-label rect {
fill: #e8f4f1;
stroke: #0d181d;
stroke-width: 2;
}
.marker-label text {
fill: #102027;
font-size: 10px;
font-weight: 800;
text-anchor: middle;
font-family: inherit;
}
.plot-hit {
cursor: crosshair;
}
.transport {
margin-top: 4px;
padding-top: 18px;
border-top: 1px solid var(--line-soft);
}
.transport-top {
display: flex;
align-items: center;
gap: 13px;
}
.play-button {
flex: 0 0 auto;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 9px;
min-width: 142px;
height: 42px;
padding: 0 17px;
border: 0;
border-radius: 12px;
background: var(--phase);
color: #071014;
font-size: 12px;
font-weight: 800;
cursor: pointer;
box-shadow: 0 8px 26px color-mix(in srgb, var(--phase) 18%, transparent);
transition: transform 160ms ease, background 200ms ease;
}
.play-button:hover {
transform: translateY(-1px);
}
.play-button:active {
transform: translateY(1px);
}
.play-icon {
width: 16px;
font-size: 12px;
text-align: center;
}
.energy-slider {
--fill: 0%;
width: 100%;
height: 6px;
margin: 0;
border-radius: 999px;
outline: none;
appearance: none;
background:
linear-gradient(
to right,
var(--phase) 0%,
var(--phase) var(--fill),
#263a40 var(--fill),
#263a40 100%
);
cursor: pointer;
}
.energy-slider::-webkit-slider-thumb {
width: 18px;
height: 18px;
border: 3px solid #0d181d;
border-radius: 50%;
appearance: none;
background: var(--phase);
box-shadow: 0 0 0 1px var(--phase), 0 0 18px color-mix(in srgb, var(--phase) 45%, transparent);
}
.energy-slider::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #0d181d;
border-radius: 50%;
background: var(--phase);
box-shadow: 0 0 0 1px var(--phase);
}
.transport-bottom {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin-top: 13px;
color: #769095;
font-size: 10px;
}
.reset-button {
border: 0;
padding: 5px 0;
background: transparent;
color: #a4b9bb;
font-size: 10px;
font-weight: 700;
cursor: pointer;
}
.reset-button:hover {
color: white;
}
.energy-number {
color: var(--phase);
font-weight: 800;
}
.footer-note {
margin: 15px 2px 0;
color: #526b70;
font-size: 10px;
line-height: 1.5;
}
@media (max-width: 1050px) {
.layout {
grid-template-columns: 1fr;
}
.stage,
.graph-panel {
min-height: 650px;
}
.graph-wrap {
min-height: 430px;
}
}
@media (max-width: 620px) {
.app {
padding: 13px;
}
.topbar {
align-items: flex-start;
}
.top-note {
display: none;
}
.stage {
min-height: 580px;
}
.stage-copy {
top: 74px;
left: 20px;
}
.stage-copy h2 {
max-width: 190px;
font-size: 31px;
}
.stage-copy p {
max-width: 185px;
font-size: 11px;
}
.readout {
left: 18px;
right: 18px;
bottom: 18px;
min-width: 0;
}
.orbit-hint {
display: none;
}
.graph-panel {
min-height: 650px;
padding: 22px 17px 19px;
}
.graph-header {
display: block;
}
.legend {
justify-content: flex-start;
margin-top: 14px;
}
.graph-wrap {
margin-left: -8px;
margin-right: -8px;
}
.transport-top {
flex-wrap: wrap;
}
.play-button {
width: 100%;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 28 28" fill="none">
<path d="M14 3.5 23.5 9v10L14 24.5 4.5 19V9L14 3.5Z"
stroke="#78e0cf" stroke-width="1.4"/>
<path d="m14 8 5 3v6l-5 3-5-3v-6l5-3Z"
stroke="#ffc86b" stroke-width="1.4"/>
<circle cx="14" cy="14" r="2" fill="#ff805f"/>
</svg>
</div>
<div>
<p class="brand-title">Thermal Phase Study</p>
<p class="brand-subtitle">Matter / Energy / Interaction</p>
</div>
</div>
<div class="top-note">Interactive specimen 01 · Idealized model</div>
</header>
<main class="layout">
<section class="panel stage" aria-label="Interactive 3D material specimen">
<div class="viewport" id="viewport"></div>
<div class="stage-top">
<div class="live-label">
<span class="live-dot"></span>
LIVE SPECIMEN
</div>
<button class="view-button" id="resetCamera" type="button">
↺ Reset view
</button>
</div>
<div class="stage-copy">
<div class="phase-chip" id="phaseChip">SOLID</div>
<h2 id="phaseName" aria-live="polite">Solid state</h2>
<p id="phaseDescription">
An ordered structure. Added energy increases molecular motion.
</p>
</div>
<div class="readout">
<div class="readout-cell">
<div class="readout-label">Temperature</div>
<div class="readout-value" id="temperatureValue">20°C</div>
</div>
<div class="readout-cell">
<div class="readout-label">Energy input</div>
<div class="readout-value" id="energyValue">0%</div>
</div>
</div>
<div class="orbit-hint">DRAG TO ORBIT · SCROLL TO ZOOM</div>
</section>
<section class="panel graph-panel" aria-label="Energy and temperature graph">
<div class="graph-header">
<div>
<p class="eyebrow">Thermal Curve</p>
<h2>Energy → Temperature</h2>
<p>
Follow the specimen through warming, melting, and further warming.
</p>
</div>
<div class="legend" aria-label="Phase legend">
<div class="legend-item">
<span class="legend-dot" style="background:#78e0cf"></span>
Solid
</div>
<div class="legend-item">
<span class="legend-dot" style="background:#ffc86b"></span>
Melting
</div>
<div class="legend-item">
<span class="legend-dot" style="background:#ff805f"></span>
Liquid
</div>
</div>
</div>
<div class="graph-wrap">
<svg
id="heatGraph"
viewBox="0 0 760 430"
role="img"
aria-label="Idealized heating curve. Temperature rises while the material is solid, remains constant during melting, then rises again while liquid."
>
<defs>
<linearGradient id="heatGradient" x1="74" y1="0" x2="722" y2="0"
gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#78e0cf"/>
<stop offset="0.32" stop-color="#ffc86b"/>
<stop offset="0.56" stop-color="#ff805f"/>
<stop offset="1" stop-color="#ffe08a"/>
</linearGradient>
</defs>
<!-- Phase regions -->
<rect x="74" y="48" width="205.36" height="290"
fill="#78e0cf" opacity="0.045"/>
<rect x="279.36" y="48" width="155.52" height="290"
fill="#ffc86b" opacity="0.065"/>
<rect x="434.88" y="48" width="287.12" height="290"
fill="#ff805f" opacity="0.045"/>
<!-- Grid -->
<g>
<line class="grid-line" x1="74" y1="338" x2="722" y2="338"/>
<line class="grid-line" x1="74" y1="272.65" x2="722" y2="272.65"/>
<line class="grid-line" x1="74" y1="207.24" x2="722" y2="207.24"/>
<line class="grid-line" x1="74" y1="141.88" x2="722" y2="141.88"/>
<line class="grid-line" x1="74" y1="76.53" x2="722" y2="76.53"/>
<line class="grid-line" x1="74" y1="48" x2="74" y2="338"/>
<line class="grid-line" x1="236" y1="48" x2="236" y2="338"/>
<line class="grid-line" x1="398" y1="48" x2="398" y2="338"/>
<line class="grid-line" x1="560" y1="48" x2="560" y2="338"/>
<line class="grid-line" x1="722" y1="48" x2="722" y2="338"/>
</g>
<!-- Region dividers -->
<line x1="279.36" y1="48" x2="279.36" y2="338"
stroke="#53656a" stroke-dasharray="2 7" opacity="0.45"/>
<line x1="434.88" y1="48" x2="434.88" y2="338"
stroke="#53656a" stroke-dasharray="2 7" opacity="0.45"/>
<!-- Axes -->
<line class="axis-line" x1="74" y1="48" x2="74" y2="338"/>
<line class="axis-line" x1="74" y1="338" x2="722" y2="338"/>
<!-- Y labels -->
<text class="axis-label" x="57" y="342" text-anchor="end">20</text>
<text class="axis-label" x="57" y="276.65" text-anchor="end">40</text>
<text class="axis-label" x="57" y="211.24" text-anchor="end">60</text>
<text class="axis-label" x="57" y="145.88" text-anchor="end">80</text>
<text class="axis-label" x="57" y="80.53" text-anchor="end">100</text>
<text class="axis-title" x="18" y="193"
text-anchor="middle"
transform="rotate(-90 18 193)">Temperature (°C)</text>
<!-- X labels -->
<text class="axis-label" x="74" y="364" text-anchor="middle">0</text>
<text class="axis-label" x="236" y="364" text-anchor="middle">25</text>
<text class="axis-label" x="398" y="364" text-anchor="middle">50</text>
<text class="axis-label" x="560" y="364" text-anchor="middle">75</text>
<text class="axis-label" x="722" y="364" text-anchor="middle">100</text>
<text class="axis-title" x="398" y="397" text-anchor="middle">
Relative energy input
</text>
<!-- Phase labels -->
<text class="phase-label" x="176" y="74"
text-anchor="middle" fill="#78e0cf">SOLID</text>
<text class="phase-label" x="357" y="74"
text-anchor="middle" fill="#ffc86b">MELTING</text>
<text class="phase-label" x="578" y="74"
text-anchor="middle" fill="#ff805f">LIQUID</text>
<!-- Heating curve -->
<path
id="energyPath"
class="heat-path-shadow"
d="M 74 338 L 279.36 207.24 L 434.88 207.24 L 722 56"
/>
<path
class="heat-path"
d="M 74 338 L 279.36 207.24 L 434.88 207.24 L 722 56"
/>
<!-- Current state marker -->
<line id="markerLine" class="marker-line"
x1="74" x2="74" y1="48" y2="338"/>
<circle id="markerHalo" class="marker-halo" cx="74" cy="338" r="11"/>
<circle id="markerDot" class="marker-dot" cx="74" cy="338" r="5"/>
<g id="markerLabel" class="marker-label" transform="translate(74 302)">
<rect x="-27" y="-24" width="54" height="23" rx="11.5"/>
<text x="0" y="-8.5">20°C</text>
</g>
<!-- Interactive overlay -->
<rect id="plotHit"
class="plot-hit"
x="74" y="48" width="648" height="290"
fill="#ffffff" opacity="0.001"/>
</svg>
</div>
<div class="transport">
<div class="transport-top">
<button class="play-button" id="playButton" type="button">
<span class="play-icon" id="playIcon">▶</span>
<span id="playText">Run heating</span>
</button>
<input
id="energySlider"
class="energy-slider"
type="range"
min="0"
max="1000"
step="1"
value="0"
aria-label="Relative energy input"
/>
</div>
<div class="transport-bottom">
<span>Drag the graph or use the slider</span>
<button class="reset-button" id="resetEnergy" type="button">Reset</button>
<span><span class="energy-number" id="energyPercent">0%</span> energy</span>
</div>
</div>
</section>
</main>
<p class="footer-note">
Idealized single-component phase-change model. The plateau represents latent
heat absorbed while the structure changes phase; values are not calibrated
to a specific material.
</p>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const graphSVG = document.getElementById("heatGraph");
const slider = document.getElementById("energySlider");
const playButton = document.getElementById("playButton");
const playIcon = document.getElementById("playIcon");
const playText = document.getElementById("playText");
const phaseChip = document.getElementById("phaseChip");
const phaseName = document.getElementById("phaseName");
const phaseDescription = document.getElementById("phaseDescription");
const temperatureValue = document.getElementById("temperatureValue");
const energyValue = document.getElementById("energyValue");
const energyPercent = document.getElementById("energyPercent");
const markerLine = document.getElementById("markerLine");
const markerHalo = document.getElementById("markerHalo");
const markerDot = document.getElementById("markerDot");
const markerLabel = document.getElementById("markerLabel");
const markerText = markerLabel.querySelector("text");
const plotHit = document.getElementById("plotHit");
const PLOT = {
left: 74,
right: 722,
top: 48,
bottom: 338
};
const width = PLOT.right - PLOT.left;
const height = PLOT.bottom - PLOT.top;
const state = {
energy: 0,
playing: false,
graphDragging: false
};
const clamp = THREE.MathUtils.clamp;
const smoothstep = (x) => {
x = clamp(x, 0, 1);
return x * x * (3 - 2 * x);
};
function thermalFromEnergy(energy) {
if (energy < 0.32) {
const progress = energy / 0.32;
return {
phase: "solid",
temperature: 20 + 40 * progress,
melt: 0,
color: "#78e0cf"
};
}
if (energy < 0.56) {
const progress = (energy - 0.32) / 0.24;
return {
phase: "melting",
temperature: 60,
melt: smoothstep(progress),
color: "#ffc86b"
};
}
const progress = (energy - 0.56) / 0.44;
return {
phase: "liquid",
temperature: 60 + 45 * progress,
melt: 1,
color: "#ff805f"
};
}
function graphX(energy) {
return PLOT.left + energy * width;
}
function graphY(temperature) {
const normalized = (temperature - 20) / (105 - 20);
return PLOT.bottom - normalized * height;
}
function syncUI() {
const thermal = thermalFromEnergy(state.energy);
const x = graphX(state.energy);
const y = graphY(thermal.temperature);
const roundedTemperature = Math.round(thermal.temperature);
const percentage = Math.round(state.energy * 100);
document.documentElement.style.setProperty("--phase", thermal.color);
document.documentElement.style.setProperty("--chip-color", thermal.color);
if (thermal.phase === "solid") {
phaseChip.textContent = "SOLID";
phaseName.textContent = "Solid state";
phaseDescription.textContent =
"An ordered structure. Added energy increases molecular motion.";
} else if (thermal.phase === "melting") {
phaseChip.textContent = "PHASE CHANGE";
phaseName.textContent = "Melting";
phaseDescription.textContent =
"Latent heat breaks the structure apart while temperature stays nearly constant.";
} else {
phaseChip.textContent = "LIQUID";
phaseName.textContent = "Further warming";
phaseDescription.textContent =
"The material is liquid. Additional energy now raises its temperature again.";
}
temperatureValue.textContent = `${roundedTemperature}°C`;
energyValue.textContent = `${percentage}%`;
energyPercent.textContent = `${percentage}%`;
slider.value = String(Math.round(state.energy * 1000));
slider.style.setProperty("--fill", `${state.energy * 100}%`);
markerLine.setAttribute("x1", x);
markerLine.setAttribute("x2", x);
markerHalo.setAttribute("cx", x);
markerHalo.setAttribute("cy", y);
markerDot.setAttribute("cx", x);
markerDot.setAttribute("cy", y);
const labelX = clamp(x, PLOT.left + 31, PLOT.right - 31);
const labelY = clamp(y - 27, PLOT.top + 14, PLOT.bottom - 14);
markerLabel.setAttribute(
"transform",
`translate(${labelX} ${labelY})`
);
markerText.textContent = `${roundedTemperature}°C`;
}
function setEnergy(value) {
state.energy = clamp(value, 0, 1);
syncUI();
}
function updatePlayButton() {
if (state.playing) {
playIcon.textContent = "Ⅱ";
playText.textContent = "Pause heating";
} else {
playIcon.textContent = "▶";
playText.textContent =
state.energy >= 0.999 ? "Replay heating" : "Run heating";
}
}
playButton.addEventListener("click", () => {
if (state.playing) {
state.playing = false;
} else {
if (state.energy >= 0.999) {
state.energy = 0;
}
state.playing = true;
}
updatePlayButton();
});
document.getElementById("resetEnergy").addEventListener("click", () => {
state.playing = false;
setEnergy(0);
updatePlayButton();
});
slider.addEventListener("input", () => {
state.playing = false;
updatePlayButton();
setEnergy(Number(slider.value) / 1000);
});
function pointerEnergy(event) {
const bounds = graphSVG.getBoundingClientRect();
const svgX = ((event.clientX - bounds.left) / bounds.width) * 760;
return clamp((svgX - PLOT.left) / width, 0, 1);
}
plotHit.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
state.graphDragging = true;
state.playing = false;
updatePlayButton();
plotHit.setPointerCapture(event.pointerId);
setEnergy(pointerEnergy(event));
event.preventDefault();
});
plotHit.addEventListener("pointermove", (event) => {
if (!state.graphDragging) return;
setEnergy(pointerEnergy(event));
});
function endGraphDrag(event) {
if (!state.graphDragging) return;
state.graphDragging = false;
if (plotHit.hasPointerCapture(event.pointerId)) {
plotHit.releasePointerCapture(event.pointerId);
}
}
plotHit.addEventListener("pointerup", endGraphDrag);
plotHit.addEventListener("pointercancel", endGraphDrag);
/* ---------------------------------------------------------------
Three.js scene
---------------------------------------------------------------- */
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
36,
1,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setClearColor(0x000000, 0);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
0xa8fff0,
0x071014,
2.1
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d4, 3.7);
keyLight.position.set(4.5, 6, 4);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 18;
keyLight.shadow.camera.left = -4;
keyLight.shadow.camera.right = 4;
keyLight.shadow.camera.top = 4;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x65e8d4, 28, 9, 2);
rimLight.position.set(-3.2, 2.8, 2.4);
scene.add(rimLight);
const heatLight = new THREE.PointLight(0xff805f, 5, 6, 2);
heatLight.position.set(0, 1.8, 0.8);
scene.add(heatLight);
// Pedestal
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x17272d,
roughness: 0.68,
metalness: 0.28
});
const topMaterial = new THREE.MeshStandardMaterial({
color: 0x21383e,
roughness: 0.48,
metalness: 0.32
});
const pedestalBase = new THREE.Mesh(
new THREE.CylinderGeometry(1.46, 1.62, 0.28, 80),
baseMaterial
);
pedestalBase.position.y = 0.02;
pedestalBase.castShadow = true;
pedestalBase.receiveShadow = true;
scene.add(pedestalBase);
const pedestalTop = new THREE.Mesh(
new THREE.CylinderGeometry(1.3, 1.42, 0.09, 80),
topMaterial
);
pedestalTop.position.y = 0.205;
pedestalTop.castShadow = true;
pedestalTop.receiveShadow = true;
scene.add(pedestalTop);
const pedestalRing = new THREE.Mesh(
new THREE.TorusGeometry(1.315, 0.018, 10, 100),
new THREE.MeshStandardMaterial({
color: 0x5dcbbb,
emissive: 0x153b36,
emissiveIntensity: 0.6,
roughness: 0.3,
metalness: 0.65
})
);
pedestalRing.rotation.x = Math.PI / 2;
pedestalRing.position.y = 0.255;
scene.add(pedestalRing);
// Ground and technical grid
const shadowFloor = new THREE.Mesh(
new THREE.CircleGeometry(6, 96),
new THREE.ShadowMaterial({
color: 0x000000,
opacity: 0.36
})
);
shadowFloor.rotation.x = -Math.PI / 2;
shadowFloor.position.y = -0.125;
shadowFloor.receiveShadow = true;
scene.add(shadowFloor);
const grid = new THREE.GridHelper(8, 24, 0x31575c, 0x193037);
grid.position.y = -0.115;
const gridMaterials = Array.isArray(grid.material)
? grid.material
: [grid.material];
gridMaterials.forEach((material) => {
material.transparent = true;
material.opacity = 0.22;
material.depthWrite = false;
});
scene.add(grid);
// Specimen
const specimenPivot = new THREE.Group();
scene.add(specimenPivot);
const solidGeometry = new THREE.IcosahedronGeometry(1, 1);
const solidPositions = solidGeometry.attributes.position;
for (let i = 0; i < solidPositions.count; i++) {
const x = solidPositions.getX(i);
const y = solidPositions.getY(i);
const z = solidPositions.getZ(i);
const length = Math.hypot(x, y, z) || 1;
const nx = x / length;
const ny = y / length;
const nz = z / length;
const irregularity =
1 +
0.10 * Math.sin(nx * 5.1 + ny * 2.7) +
0.065 * Math.cos(nz * 4.2 - nx * 2.4);
solidPositions.setXYZ(
i,
nx * 1.08 * irregularity,
ny * 0.92 * irregularity,
nz * 1.02 * irregularity
);
}
solidGeometry.computeVertexNormals();
const solidMaterial = new THREE.MeshPhysicalMaterial({
color: 0x78e0cf,
roughness: 0.29,
metalness: 0.08,
clearcoat: 0.45,
clearcoatRoughness: 0.28,
emissive: 0x123c36,
emissiveIntensity: 0.28,
flatShading: true,
transparent: true,
opacity: 1,
depthWrite: false
});
const solidMesh = new THREE.Mesh(solidGeometry, solidMaterial);
solidMesh.position.y = 1.12;
solidMesh.scale.setScalar(0.9);
solidMesh.rotation.set(0.12, -0.35, -0.08);
solidMesh.castShadow = true;
solidMesh.receiveShadow = true;
solidMesh.renderOrder = 2;
specimenPivot.add(solidMesh);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0xc6fff1,
transparent: true,
opacity: 0.28,
depthWrite: false
});
const solidEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(solidGeometry, 12),
edgeMaterial
);
solidEdges.renderOrder = 3;
solidMesh.add(solidEdges);
const liquidGeometry = new THREE.SphereGeometry(1, 64, 36);
const liquidBasePositions = new Float32Array(
liquidGeometry.attributes.position.array
);
const liquidMaterial = new THREE.MeshPhysicalMaterial({
color: 0xff805f,
roughness: 0.17,
metalness: 0.04,
clearcoat: 1,
clearcoatRoughness: 0.12,
emissive: 0x6d160b,
emissiveIntensity: 0.4,
transparent: true,
opacity: 0,
depthWrite: false
});
const liquidMesh = new THREE.Mesh(liquidGeometry, liquidMaterial);
liquidMesh.position.y = 0.98;
liquidMesh.visible = false;
liquidMesh.castShadow = true;
liquidMesh.receiveShadow = true;
liquidMesh.renderOrder = 3;
specimenPivot.add(liquidMesh);
const puddleMaterial = new THREE.MeshPhysicalMaterial({
color: 0xff805f,
roughness: 0.2,
metalness: 0,
clearcoat: 1,
transparent: true,
opacity: 0,
depthWrite: false
});
const puddle = new THREE.Mesh(
new THREE.SphereGeometry(1, 48, 18),
puddleMaterial
);
puddle.position.y = 0.275;
puddle.visible = false;
puddle.receiveShadow = true;
puddle.renderOrder = 1;
specimenPivot.add(puddle);
const bubbleMaterial = new THREE.MeshBasicMaterial({
color: 0xfff1d2,
transparent: true,
opacity: 0,
depthWrite: false
});
const bubbles = [];
const bubbleSpecs = [
[-0.35, 0.65, 0.18, 0.075],
[0.28, 0.58, 0.22, 0.055],
[-0.10, 1.14, -0.25, 0.095],
[0.42, 0.91, -0.12, 0.065],
[-0.46, 1.08, -0.18, 0.052],
[0.05, 0.48, 0.38, 0.07]
];
bubbleSpecs.forEach(([x, y, z, radius]) => {
const bubble = new THREE.Mesh(
new THREE.SphereGeometry(radius, 18, 12),
bubbleMaterial
);
bubble.position.set(x, y, z);
bubble.userData = { x, y, z, radius, offset: Math.random() * 6.28 };
bubble.visible = false;
bubble.renderOrder = 4;
bubbles.push(bubble);
specimenPivot.add(bubble);
});
// Heat rings
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0xff805f,
transparent: true,
opacity: 0.1,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const heatRing = new THREE.Mesh(
new THREE.TorusGeometry(1.18, 0.012, 8, 100),
ringMaterial
);
heatRing.rotation.x = Math.PI / 2;
heatRing.position.y = 0.285;
scene.add(heatRing);
const outerRingMaterial = ringMaterial.clone();
outerRingMaterial.opacity = 0.05;
const outerHeatRing = new THREE.Mesh(
new THREE.TorusGeometry(1.52, 0.008, 8, 100),
outerRingMaterial
);
outerHeatRing.rotation.x = Math.PI / 2;
outerHeatRing.position.y = 0.27;
scene.add(outerHeatRing);
// Heat particles
const particleCount = 46;
const particlePositions = new Float32Array(particleCount * 3);
const particleSpecs = [];
for (let i = 0; i < particleCount; i++) {
particleSpecs.push({
angle: Math.random() * Math.PI * 2,
radius: 1.15 + Math.random() * 0.8,
height: 0.35 + Math.random() * 1.8,
speed: 0.12 + Math.random() * 0.25,
phase: Math.random() * Math.PI * 2
});
}
const particleGeometry = new THREE.BufferGeometry();
particleGeometry.setAttribute(
"position",
new THREE.BufferAttribute(particlePositions, 3)
);
const particleMaterial = new THREE.PointsMaterial({
color: 0xffc878,
size: 0.035,
transparent: true,
opacity: 0,
blending: THREE.AdditiveBlending,
depthWrite: false,
sizeAttenuation: true
});
const particles = new THREE.Points(particleGeometry, particleMaterial);
scene.add(particles);
const solidCold = new THREE.Color(0x78e0cf);
const solidWarm = new THREE.Color(0xf3c56e);
const liquidCool = new THREE.Color(0xff805f);
const liquidHot = new THREE.Color(0xffe08a);
/* ---------------------------------------------------------------
Direct camera controls: orbit, pan-free rotation, wheel zoom
---------------------------------------------------------------- */
const orbit = {
theta: 0.67,
phi: 1.13,
radius: 5.65,
target: new THREE.Vector3(0, 0.92, 0),
dragging: false,
lastX: 0,
lastY: 0
};
function applyCamera() {
const sinPhi = Math.sin(orbit.phi);
const cosPhi = Math.cos(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.cos(orbit.theta),
orbit.target.y + orbit.radius * cosPhi,
orbit.target.z + orbit.radius * sinPhi * Math.sin(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.theta = 0.67;
orbit.phi = 1.13;
orbit.radius = 5.65;
applyCamera();
}
document.getElementById("resetCamera").addEventListener("click", resetCamera);
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
orbit.dragging = true;
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
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 = clamp(orbit.phi - dy * 0.005, 0.48, 1.48);
applyCamera();
});
function endCameraDrag(event) {
orbit.dragging = false;
renderer.domElement.classList.remove("dragging");
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endCameraDrag);
renderer.domElement.addEventListener("pointercancel", endCameraDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
4.1,
8.2
);
applyCamera();
},
{ passive: false }
);
/* ---------------------------------------------------------------
Resize and animation
---------------------------------------------------------------- */
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
resize();
applyCamera();
syncUI();
updatePlayButton();
const clock = new THREE.Clock();
function updateLiquidGeometry(time, intensity) {
const position = liquidGeometry.attributes.position;
const amplitude = 0.018 + intensity * 0.018;
for (let i = 0; i < position.count; i++) {
const bx = liquidBasePositions[i * 3];
const by = liquidBasePositions[i * 3 + 1];
const bz = liquidBasePositions[i * 3 + 2];
const angle = Math.atan2(bz, bx);
const horizontalWobble =
1 +
amplitude * Math.sin(angle * 3 + time * 1.25) +
amplitude * 0.55 * Math.sin(by * 5 - time * 0.9);
const verticalWobble =
1 + amplitude * 0.8 * Math.cos(angle * 4 - time * 1.1);
position.setXYZ(
i,
bx * horizontalWobble,
by * verticalWobble,
bz * horizontalWobble
);
}
position.needsUpdate = true;
liquidGeometry.computeVertexNormals();
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
if (state.playing) {
state.energy = Math.min(1, state.energy + dt / 18);
if (state.energy >= 1) {
state.playing = false;
updatePlayButton();
}
syncUI();
}
const thermal = thermalFromEnergy(state.energy);
const melt = thermal.melt;
const warmProgress = clamp(state.energy / 0.32, 0, 1);
const hotProgress = clamp((state.energy - 0.56) / 0.44, 0, 1);
const overallHeat = state.energy;
// Solid specimen color and form
solidMaterial.color
.copy(solidCold)
.lerp(solidWarm, warmProgress);
solidMaterial.emissive
.copy(solidMaterial.color)
.multiplyScalar(0.16);
solidMaterial.opacity = 1 - melt;
edgeMaterial.opacity = 0.28 * (1 - melt);
solidMesh.visible = melt < 0.999;
solidMesh.scale.setScalar(0.9 - melt * 0.08);
solidMesh.position.y = 1.12 + melt * 0.03;
// Molten specimen color and form
liquidMaterial.color
.copy(liquidCool)
.lerp(liquidHot, hotProgress);
liquidMaterial.emissive
.copy(liquidMaterial.color)
.multiplyScalar(0.18);
liquidMaterial.emissiveIntensity = 0.35 + overallHeat * 0.72;
liquidMaterial.opacity = melt;
liquidMesh.visible = melt > 0.001;
liquidMesh.rotation.y = time * 0.12;
const blobScale = 0.72 + melt * 0.28;
liquidMesh.scale.set(
1.36 * blobScale,
0.87 * blobScale,
1.28 * blobScale
);
liquidMesh.position.y = 0.98 + Math.sin(time * 1.4) * 0.012;
updateLiquidGeometry(time, overallHeat);
// Thin melt puddle
puddle.visible = melt > 0.01;
puddleMaterial.color.copy(liquidMaterial.color);
puddleMaterial.opacity = melt * 0.25;
puddle.scale.set(
1.18 * melt,
0.045 * melt,
1.0 * melt
);
// Bubbles rise through the melt
bubbleMaterial.opacity = melt * 0.28;
bubbles.forEach((bubble) => {
bubble.visible = melt > 0.03;
const data = bubble.userData;
const cycle = (time * 0.24 + data.offset / (Math.PI * 2)) % 1;
bubble.position.x =
data.x + Math.sin(time * 0.8 + data.offset) * 0.055;
bubble.position.z =
data.z + Math.cos(time * 0.7 + data.offset) * 0.045;
bubble.position.y =
0.5 + cycle * 0.75 + Math.sin(time * 2 + data.offset) * 0.025;
const pulse = 0.8 + Math.sin(time * 3 + data.offset) * 0.15;
bubble.scale.setScalar(pulse);
});
specimenPivot.rotation.y = time * 0.075;
// Heat lighting and rings
heatLight.color.copy(liquidMaterial.color);
heatLight.intensity = 4 + overallHeat * 31;
heatLight.position.y = 1.35 + overallHeat * 0.45;
ringMaterial.color.copy(liquidMaterial.color);
ringMaterial.opacity = 0.06 + overallHeat * 0.42;
outerRingMaterial.color.copy(liquidMaterial.color);
outerRingMaterial.opacity = 0.025 + overallHeat * 0.16;
const pulse = 1 + Math.sin(time * 2.1) * 0.025;
heatRing.scale.setScalar(pulse);
outerHeatRing.scale.setScalar(2 - pulse);
// Rising heat particles
particleMaterial.color.copy(liquidMaterial.color);
particleMaterial.opacity = Math.max(0, overallHeat - 0.08) * 0.65;
for (let i = 0; i < particleCount; i++) {
const spec = particleSpecs[i];
const angle = spec.angle + time * spec.speed;
const radius = spec.radius + Math.sin(time + spec.phase) * 0.08;
const rise = (time * 0.08 + spec.phase) % 1;
particlePositions[i * 3] = Math.cos(angle) * radius;
particlePositions[i * 3 + 1] =
0.4 + spec.height + rise * 0.55;
particlePositions[i * 3 + 2] =
Math.sin(angle) * radius * 0.78;
}
particleGeometry.attributes.position.needsUpdate = true;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```