Prompt specification
Build or customize the Three.js 3D scene "Engine and refrigerator energy-flow 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: Engine and refrigerator energy-flow comparison
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/engine-and-refrigerator-energy-flow-comparison-x1478
Scene Description Prompt:
Compare stylized heat-engine and refrigerator energy flows, including work direction and energy balances. Make one HTML file with Three.js from cdnjs.
Working Three.js Starter (engine-and-refrigerator-energy-flow-comparison-x1478):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Heat Engine vs. Refrigerator</title>
<style>
:root {
--bg: #07111f;
--panel: rgba(10, 22, 38, 0.82);
--line: rgba(164, 202, 235, 0.16);
--text: #eef7ff;
--muted: #91a7bd;
--hot: #ffad5c;
--cold: #50d2ff;
--work-out: #a9f071;
--work-in: #b69cff;
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.header {
position: fixed;
z-index: 5;
top: 22px;
left: 26px;
right: 26px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
pointer-events: none;
}
.intro {
max-width: 650px;
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.65);
}
.eyebrow {
margin-bottom: 7px;
color: #79d7ff;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(26px, 3vw, 43px);
font-weight: 720;
letter-spacing: -0.035em;
line-height: 1.05;
}
.intro p {
max-width: 590px;
margin: 10px 0 0;
color: #a9bdd0;
font-size: 14px;
line-height: 1.5;
}
.controls {
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid rgba(164, 202, 235, 0.2);
border-radius: 10px;
padding: 10px 13px;
background: rgba(10, 22, 38, 0.76);
color: #dceafb;
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(121, 215, 255, 0.55);
background: rgba(18, 39, 61, 0.9);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid #79d7ff;
outline-offset: 2px;
}
.gesture {
position: fixed;
z-index: 4;
top: 132px;
left: 27px;
color: rgba(190, 211, 230, 0.62);
font-size: 11px;
letter-spacing: 0.03em;
pointer-events: none;
}
.comparison {
position: fixed;
z-index: 5;
right: 24px;
bottom: 22px;
left: 24px;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 14px;
pointer-events: none;
}
.card {
position: relative;
overflow: hidden;
padding: 17px 19px 16px;
border: 1px solid var(--line);
border-radius: 17px;
background:
linear-gradient(135deg, rgba(255, 255, 255, 0.035), transparent 45%),
var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(18px);
}
.card::before {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 3px;
content: "";
background: var(--accent);
box-shadow: 0 0 22px var(--accent);
}
.engine {
--accent: var(--hot);
}
.refrigerator {
--accent: var(--cold);
}
.card-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.kind {
color: var(--accent);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.metric {
color: var(--muted);
font-size: 11px;
white-space: nowrap;
}
.card h2 {
margin: 5px 0 11px;
font-size: 21px;
font-weight: 700;
letter-spacing: -0.02em;
}
.directions {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-bottom: 12px;
}
.direction {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border: 1px solid rgba(166, 197, 224, 0.13);
border-radius: 7px;
background: rgba(255, 255, 255, 0.025);
color: #b6c8d9;
font-size: 11px;
}
.dot {
width: 6px;
height: 6px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--dot);
box-shadow: 0 0 8px var(--dot);
}
.hot {
--dot: var(--hot);
color: #ffd3a9;
}
.cold {
--dot: var(--cold);
color: #b4ebff;
}
.green {
--dot: var(--work-out);
color: #d4ffc0;
}
.violet {
--dot: var(--work-in);
color: #ded4ff;
}
.energy-line {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 7px;
min-height: 25px;
color: #d7e6f3;
font-size: 12px;
}
.energy-line .arrow {
color: #607c95;
font-size: 17px;
line-height: 1;
}
.energy-line b {
color: #f6fbff;
font-weight: 720;
}
.balance {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid rgba(164, 202, 235, 0.11);
}
.equation {
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
letter-spacing: 0.01em;
}
.equation .hot-text {
color: var(--hot);
}
.equation .cold-text {
color: var(--cold);
}
.equation .work-out {
color: var(--work-out);
}
.equation .work-in {
color: var(--work-in);
}
.cycle-note {
color: #718ba2;
font-size: 10px;
white-space: nowrap;
}
.footnote {
position: fixed;
z-index: 4;
bottom: 4px;
left: 50%;
color: rgba(154, 177, 198, 0.45);
font-size: 9px;
letter-spacing: 0.06em;
transform: translateX(-50%);
pointer-events: none;
white-space: nowrap;
}
@media (max-width: 760px) {
.header {
top: 15px;
right: 15px;
left: 15px;
}
.intro p {
display: none;
}
.controls {
flex-direction: column;
align-items: stretch;
}
button {
padding: 8px 10px;
font-size: 10px;
}
.gesture {
top: 89px;
left: 16px;
}
.comparison {
right: 10px;
bottom: 12px;
left: 10px;
gap: 7px;
}
.card {
padding: 12px 12px 11px;
border-radius: 13px;
}
.card h2 {
margin-bottom: 8px;
font-size: 17px;
}
.kind,
.metric {
font-size: 8px;
}
.direction {
padding: 4px 5px;
font-size: 9px;
}
.energy-line {
gap: 4px;
font-size: 10px;
}
.balance {
display: block;
margin-top: 8px;
padding-top: 8px;
}
.equation {
font-size: 16px;
}
.cycle-note {
display: none;
}
.footnote {
display: none;
}
}
@media (max-width: 460px) {
h1 {
font-size: 25px;
}
.eyebrow {
font-size: 9px;
}
.directions {
gap: 4px;
}
.direction {
width: 100%;
}
.metric {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive 3D comparison of a heat engine and refrigerator"></div>
<header class="header">
<div class="intro">
<div class="eyebrow">Thermodynamics · Energy Flow Comparison</div>
<h1>Same laws. Opposite jobs.</h1>
<p>
A heat engine converts heat into useful work, while a refrigerator spends work
to move heat from cold space into a hotter environment.
</p>
</div>
<div class="controls">
<button id="pauseButton" type="button" aria-pressed="false">Pause flow</button>
<button id="resetButton" type="button">Reset view</button>
</div>
</header>
<div class="gesture">Drag to orbit · Scroll or pinch to zoom · Double-click to reset</div>
<main class="comparison">
<section class="card engine" aria-label="Heat engine energy balance">
<div class="card-top">
<span class="kind">Heat Engine</span>
<span class="metric">η = W<sub>out</sub> / Q<sub>H</sub></span>
</div>
<h2>Heat → useful work</h2>
<div class="directions">
<span class="direction hot">
<i class="dot"></i>Heat: hot → cold
</span>
<span class="direction green">
<i class="dot"></i>Work: engine → surroundings
</span>
</div>
<div class="energy-line">
<b class="hot">Q<sub>H</sub> enters</b>
<span class="arrow">→</span>
<span>engine</span>
<span class="arrow">→</span>
<b class="green">W<sub>out</sub></b>
+
<b class="cold">Q<sub>C</sub> leaves</b>
</div>
<div class="balance">
<div class="equation">
<span class="hot-text">Q<sub>H</sub></span> =
<span class="work-out">W<sub>out</sub></span> +
<span class="cold-text">Q<sub>C</sub></span>
</div>
<span class="cycle-note">Cyclic device: ΔU = 0</span>
</div>
</section>
<section class="card refrigerator" aria-label="Refrigerator energy balance">
<div class="card-top">
<span class="kind">Refrigerator</span>
<span class="metric">COP = Q<sub>C</sub> / W<sub>in</sub></span>
</div>
<h2>Work → heat pumping</h2>
<div class="directions">
<span class="direction cold">
<i class="dot"></i>Heat: cold → hot
</span>
<span class="direction violet">
<i class="dot"></i>Work: surroundings → refrigerator
</span>
</div>
<div class="energy-line">
<b class="violet">W<sub>in</sub> enters</b>
+
<b class="cold">Q<sub>C</sub> enters</b>
<span class="arrow">→</span>
<span>refrigerator</span>
<span class="arrow">→</span>
<b class="hot">Q<sub>H</sub> leaves</b>
</div>
<div class="balance">
<div class="equation">
<span class="hot-text">Q<sub>H</sub></span> =
<span class="cold-text">Q<sub>C</sub></span> +
<span class="work-in">W<sub>in</sub></span>
</div>
<span class="cycle-note">Cyclic device: ΔU = 0</span>
</div>
</section>
</main>
<div class="footnote">ANIMATED MAGNITUDES ARE SCHEMATIC — DIRECTIONS ARE TO SCALE</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 container = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.FogExp2(0x07111f, 0.018);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
container.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xb8dcff, 0x07101c, 1.75);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(-5, 11, 12);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x6bbdff, 1.7);
rimLight.position.set(9, 4, -9);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffa14d, 18, 9, 2);
warmLight.position.set(-8.4, 3.4, 2);
scene.add(warmLight);
const coolLight = new THREE.PointLight(0x45caff, 17, 9, 2);
coolLight.position.set(8.5, -2.8, 2);
scene.add(coolLight);
const colors = {
hot: 0xffad5c,
cold: 0x50d2ff,
workOut: 0xa9f071,
workIn: 0xb69cff,
steel: 0x263b50,
dark: 0x0c1724,
white: 0xeaf6ff
};
const flowArrows = [];
const pulseMaterials = [];
// -------------------------------------------------------------------------
// Utility functions
// -------------------------------------------------------------------------
function roundedRect(ctx, x, y, w, h, r) {
const radius = Math.min(r, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + w - radius, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + radius);
ctx.lineTo(x + w, y + h - radius);
ctx.quadraticCurveTo(x + w, y + h, x + w - radius, y + h);
ctx.lineTo(x + radius, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
function hex(color) {
return `#${new THREE.Color(color).getHexString()}`;
}
function makeLabel(main, subtitle, accent, worldWidth = 2.2, worldHeight = 0.7) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 8, 752, 176, 30);
ctx.fillStyle = "rgba(6, 15, 27, 0.90)";
ctx.fill();
ctx.lineWidth = 4;
ctx.strokeStyle = hex(accent);
ctx.globalAlpha = 0.82;
ctx.stroke();
ctx.globalAlpha = 1;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
if (subtitle) {
ctx.fillStyle = hex(accent);
ctx.font = "800 49px system-ui, sans-serif";
ctx.fillText(main, 384, 70);
ctx.fillStyle = "rgba(210, 228, 244, 0.76)";
ctx.font = "700 28px system-ui, sans-serif";
ctx.fillText(subtitle, 384, 132);
} else {
ctx.fillStyle = hex(accent);
ctx.font = "800 50px system-ui, sans-serif";
ctx.fillText(main, 384, 97);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldHeight, 1);
sprite.renderOrder = 20;
return sprite;
}
function addEdges(mesh, color = 0x91b8d8, opacity = 0.48) {
const edges = new THREE.EdgesGeometry(mesh.geometry, 28);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
});
const outline = new THREE.LineSegments(edges, material);
mesh.add(outline);
return outline;
}
function makePhysicalMaterial(color, options = {}) {
return new THREE.MeshPhysicalMaterial({
color,
roughness: 0.28,
metalness: 0.45,
clearcoat: 0.35,
clearcoatRoughness: 0.2,
...options
});
}
function addGround() {
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0x081421,
roughness: 0.92,
metalness: 0.08
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -5.5;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(80, 40, 0x26445e, 0x14283b);
grid.position.y = -5.48;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
function addHalo(x, color) {
const fill = new THREE.Mesh(
new THREE.CircleGeometry(6.1, 96),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.025,
side: THREE.DoubleSide,
depthWrite: false
})
);
fill.rotation.x = -Math.PI / 2;
fill.position.set(x, -5.46, 0);
scene.add(fill);
const ring = new THREE.Mesh(
new THREE.RingGeometry(5.55, 5.58, 128),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.18,
side: THREE.DoubleSide,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.set(x, -5.44, 0);
scene.add(ring);
}
addHalo(-5, colors.hot);
addHalo(5, colors.cold);
const dividerGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, -5.3, -0.3),
new THREE.Vector3(0, 5.1, -0.3)
]);
const divider = new THREE.Line(
dividerGeometry,
new THREE.LineDashedMaterial({
color: 0x50718b,
dashSize: 0.18,
gapSize: 0.2,
transparent: true,
opacity: 0.36
})
);
divider.computeLineDistances();
scene.add(divider);
}
// -------------------------------------------------------------------------
// Reservoirs
// -------------------------------------------------------------------------
function makeReservoir(parent, x, y, kind) {
const isHot = kind === "hot";
const color = isHot ? colors.hot : colors.cold;
const group = new THREE.Group();
group.position.set(x, y, 0);
parent.add(group);
const tankMaterial = makePhysicalMaterial(color, {
transparent: true,
opacity: 0.36,
roughness: 0.16,
metalness: 0.12,
transmission: 0.12,
emissive: color,
emissiveIntensity: 0.18,
depthWrite: false
});
pulseMaterials.push({
material: tankMaterial,
base: 0.18,
amplitude: 0.09,
phase: isHot ? 0 : Math.PI
});
const tank = new THREE.Mesh(
new THREE.BoxGeometry(2.65, 1.48, 1.9),
tankMaterial
);
tank.castShadow = true;
group.add(tank);
addEdges(tank, color, 0.75);
const capMaterial = makePhysicalMaterial(color, {
emissive: color,
emissiveIntensity: 0.35,
roughness: 0.2,
metalness: 0.55
});
for (let i = 0; i < 4; i++) {
const bar = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.76, 0.88),
capMaterial
);
bar.position.set(-0.78 + i * 0.52, 0, -0.15);
group.add(bar);
}
const fluid = new THREE.Mesh(
new THREE.BoxGeometry(2.4, 0.13, 1.66),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.58
})
);
fluid.position.y = -0.52;
group.add(fluid);
const light = new THREE.PointLight(color, isHot ? 11 : 10, 5.4, 2);
light.position.set(0, 0, 1.7);
group.add(light);
const label = makeLabel(
isHot ? "HOT" : "COLD",
"RESERVOIR",
color,
1.95,
0.64
);
label.position.set(0, 1.12, 0.8);
group.add(label);
return group;
}
// -------------------------------------------------------------------------
// Heat engine
// -------------------------------------------------------------------------
const engineGroup = new THREE.Group();
engineGroup.position.x = -5;
scene.add(engineGroup);
makeReservoir(engineGroup, -3.45, 2.75, "hot");
makeReservoir(engineGroup, -3.45, -2.75, "cold");
const engineTitle = makeLabel(
"HEAT ENGINE",
"HEAT → WORK",
colors.hot,
3.45,
0.78
);
engineTitle.position.set(0, 4.65, 0.2);
engineGroup.add(engineTitle);
const engineBody = new THREE.Mesh(
new THREE.BoxGeometry(1.95, 2.12, 1.55),
makePhysicalMaterial(0x4a3b31, {
roughness: 0.24,
metalness: 0.68
})
);
engineBody.castShadow = true;
engineGroup.add(engineBody);
addEdges(engineBody, 0xffc184, 0.5);
const upperChamber = new THREE.Mesh(
new THREE.CylinderGeometry(0.28, 0.28, 0.92, 24),
makePhysicalMaterial(colors.hot, {
emissive: colors.hot,
emissiveIntensity: 0.55
})
);
upperChamber.position.set(-0.62, 0.48, 0.94);
engineGroup.add(upperChamber);
const lowerChamber = new THREE.Mesh(
new THREE.CylinderGeometry(0.28, 0.28, 0.92, 24),
makePhysicalMaterial(colors.cold, {
emissive: colors.cold,
emissiveIntensity: 0.42
})
);
lowerChamber.position.set(-0.62, -0.5, 0.94);
engineGroup.add(lowerChamber);
const engineRotor = new THREE.Group();
engineRotor.position.set(0.38, 0, 1.0);
engineGroup.add(engineRotor);
const wheel = new THREE.Mesh(
new THREE.TorusGeometry(0.67, 0.105, 16, 64),
makePhysicalMaterial(colors.hot, {
emissive: colors.hot,
emissiveIntensity: 0.5,
roughness: 0.22,
metalness: 0.72
})
);
engineRotor.add(wheel);
for (let i = 0; i < 4; i++) {
const spoke = new THREE.Mesh(
new THREE.BoxGeometry(1.14, 0.075, 0.075),
makePhysicalMaterial(0xd9a45e, {
emissive: 0x7d4b1e,
emissiveIntensity: 0.18
})
);
spoke.rotation.z = (i * Math.PI) / 4;
engineRotor.add(spoke);
}
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.19, 0.28, 24),
makePhysicalMaterial(0xf0c078, {
emissive: 0x7b4e1d,
emissiveIntensity: 0.3
})
);
hub.rotation.x = Math.PI / 2;
engineRotor.add(hub);
const engineLamp = new THREE.PointLight(colors.hot, 7, 4.5, 2);
engineLamp.position.set(0.35, 0, 1.8);
engineGroup.add(engineLamp);
const generator = new THREE.Mesh(
new THREE.CylinderGeometry(0.58, 0.68, 0.42, 32),
makePhysicalMaterial(colors.workOut, {
emissive: colors.workOut,
emissiveIntensity: 0.4,
roughness: 0.25
})
);
generator.position.set(0, -4.52, 1.0);
engineGroup.add(generator);
const generatorCap = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.055, 12, 40),
new THREE.MeshBasicMaterial({ color: colors.workOut })
);
generatorCap.rotation.x = Math.PI / 2;
generatorCap.position.set(0, -4.28, 1.0);
engineGroup.add(generatorCap);
// -------------------------------------------------------------------------
// Refrigerator
// -------------------------------------------------------------------------
const fridgeGroup = new THREE.Group();
fridgeGroup.position.x = 5;
scene.add(fridgeGroup);
makeReservoir(fridgeGroup, 3.45, 2.75, "hot");
makeReservoir(fridgeGroup, 3.45, -2.75, "cold");
const fridgeTitle = makeLabel(
"REFRIGERATOR",
"WORK → HEAT PUMP",
colors.cold,
3.65,
0.78
);
fridgeTitle.position.set(0, 4.65, 0.2);
fridgeGroup.add(fridgeTitle);
const fridgeBody = new THREE.Mesh(
new THREE.BoxGeometry(2.18, 2.25, 1.65),
makePhysicalMaterial(0x24465c, {
roughness: 0.27,
metalness: 0.62,
emissive: 0x0b2737,
emissiveIntensity: 0.2
})
);
fridgeBody.castShadow = true;
fridgeGroup.add(fridgeBody);
addEdges(fridgeBody, 0x78dcff, 0.7);
const door = new THREE.Mesh(
new THREE.BoxGeometry(1.88, 1.95, 0.07),
makePhysicalMaterial(colors.cold, {
transparent: true,
opacity: 0.2,
roughness: 0.12,
transmission: 0.15,
emissive: colors.cold,
emissiveIntensity: 0.28,
depthWrite: false
})
);
door.position.z = 0.88;
fridgeGroup.add(door);
addEdges(door, 0x9ceaff, 0.85);
for (let i = 0; i < 3; i++) {
const shelf = new THREE.Mesh(
new THREE.BoxGeometry(1.57, 0.045, 0.075),
new THREE.MeshStandardMaterial({
color: 0xbbefff,
emissive: colors.cold,
emissiveIntensity: 0.55,
metalness: 0.25,
roughness: 0.3
})
);
shelf.position.set(0, 0.6 - i * 0.57, 0.98);
fridgeGroup.add(shelf);
}
const handle = new THREE.Mesh(
new THREE.BoxGeometry(0.08, 0.76, 0.08),
makePhysicalMaterial(0xd7f3ff, {
emissive: 0x5bc7ef,
emissiveIntensity: 0.3
})
);
handle.position.set(0.76, 0, 1.03);
fridgeGroup.add(handle);
const compressor = new THREE.Mesh(
new THREE.CylinderGeometry(0.43, 0.49, 0.58, 28),
makePhysicalMaterial(0x34485b, {
roughness: 0.3,
metalness: 0.7
})
);
compressor.position.set(0, -1.38, 0.1);
fridgeGroup.add(compressor);
addEdges(compressor, 0x86dfff, 0.42);
const fridgeLamp = new THREE.PointLight(colors.cold, 8, 4.8, 2);
fridgeLamp.position.set(0, 0.2, 1.8);
fridgeGroup.add(fridgeLamp);
const workSource = new THREE.Mesh(
new THREE.BoxGeometry(1.45, 0.62, 1.05),
makePhysicalMaterial(colors.workIn, {
emissive: colors.workIn,
emissiveIntensity: 0.42,
roughness: 0.25,
metalness: 0.5
})
);
workSource.position.set(0, -4.55, 1.0);
fridgeGroup.add(workSource);
addEdges(workSource, colors.workIn, 0.8);
const batteryMark = makeLabel(
"W",
"WORK SOURCE",
colors.workIn,
1.45,
0.5
);
batteryMark.position.set(0, -4.48, 1.63);
fridgeGroup.add(batteryMark);
// -------------------------------------------------------------------------
// Animated energy arrows
// -------------------------------------------------------------------------
function createFlowArrow(parent, curve, color, main, subtitle, labelOffset, phase = 0) {
const tubeGeometry = new THREE.TubeGeometry(curve, 72, 0.046, 10, false);
const tubeMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 1.25,
roughness: 0.28,
metalness: 0.2,
transparent: true,
opacity: 0.92
});
const tube = new THREE.Mesh(tubeGeometry, tubeMaterial);
parent.add(tube);
const glow = new THREE.Mesh(
new THREE.TubeGeometry(curve, 72, 0.12, 10, false),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.08,
depthWrite: false
})
);
parent.add(glow);
const tangent = curve.getTangent(1).normalize();
const arrowhead = new THREE.Mesh(
new THREE.ConeGeometry(0.16, 0.42, 18),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 1.0,
roughness: 0.25,
metalness: 0.3
})
);
arrowhead.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
arrowhead.position.copy(curve.getPoint(1)).addScaledVector(tangent, -0.18);
parent.add(arrowhead);
const particleGeometry = new THREE.SphereGeometry(0.105, 12, 12);
const particleMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.95
});
const particles = [];
for (let i = 0; i < 5; i++) {
const particle = new THREE.Mesh(particleGeometry, particleMaterial);
parent.add(particle);
particles.push(particle);
}
const labelPosition = curve.getPoint(0.5).add(labelOffset);
const label = makeLabel(main, subtitle, color, 1.5, 0.62);
label.position.copy(labelPosition);
parent.add(label);
const arrow = {
curve,
particles,
phase,
particleMaterial
};
flowArrows.push(arrow);
return arrow;
}
function cubic(a, b, c, d) {
return new THREE.CubicBezierCurve3(
a.clone(),
b.clone(),
c.clone(),
d.clone()
);
}
const v = (x, y, z = 0) => new THREE.Vector3(x, y, z);
// Heat-engine flows
createFlowArrow(
engineGroup,
cubic(
v(-2.1, 2.75, 1.15),
v(-1.78, 2.7, 1.15),
v(-1.3, 1.9, 1.15),
v(-1.03, 1.18, 1.15)
),
colors.hot,
"Q_H",
"HEAT IN",
v(-0.12, 0.32, 0.16),
0.05
);
createFlowArrow(
engineGroup,
cubic(
v(-1.03, -1.18, 1.15),
v(-1.3, -1.9, 1.15),
v(-1.78, -2.7, 1.15),
v(-2.1, -2.75, 1.15)
),
colors.cold,
"Q_C",
"HEAT OUT",
v(-0.12, -0.32, 0.16),
0.35
);
createFlowArrow(
engineGroup,
cubic(
v(0, -1.15, 1.16),
v(0, -2.0, 1.16),
v(0, -3.35, 1.16),
v(0, -4.22, 1.16)
),
colors.workOut,
"W_out",
"WORK OUT",
v(0.78, 0, 0.12),
0.62
);
// Refrigerator flows
createFlowArrow(
fridgeGroup,
cubic(
v(1.03, 1.18, 1.15),
v(1.3, 1.9, 1.15),
v(1.78, 2.7, 1.15),
v(2.1, 2.75, 1.15)
),
colors.hot,
"Q_H",
"HEAT OUT",
v(0.12, 0.32, 0.16),
0.22
);
createFlowArrow(
fridgeGroup,
cubic(
v(2.1, -2.75, 1.15),
v(1.78, -2.7, 1.15),
v(1.3, -1.9, 1.15),
v(1.03, -1.18, 1.15)
),
colors.cold,
"Q_C",
"HEAT IN",
v(0.12, -0.32, 0.16),
0.5
);
createFlowArrow(
fridgeGroup,
cubic(
v(0, -4.22, 1.16),
v(0, -3.35, 1.16),
v(0, -2.0, 1.16),
v(0, -1.15, 1.16)
),
colors.workIn,
"W_in",
"WORK IN",
v(-0.8, 0, 0.12),
0.78
);
// -------------------------------------------------------------------------
// Camera controls implemented directly, without addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.45, 0);
let yaw = 0;
let pitch = 0.19;
let distance = 22;
let dragging = false;
let previousX = 0;
let previousY = 0;
function defaultDistance() {
const aspect = window.innerWidth / window.innerHeight;
return aspect < 0.8 ? 38 : aspect < 1.2 ? 29 : 22;
}
function updateCamera() {
const horizontal = Math.cos(pitch) * distance;
camera.position.set(
cameraTarget.x + Math.sin(yaw) * horizontal,
cameraTarget.y + Math.sin(pitch) * distance,
cameraTarget.z + Math.cos(yaw) * horizontal
);
camera.lookAt(cameraTarget);
}
function resetView() {
yaw = 0;
pitch = 0.19;
distance = defaultDistance();
cameraTarget.y = window.innerWidth / window.innerHeight < 0.8 ? 1.55 : 0.45;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.005, 0.04, 0.72);
updateCamera();
});
function endDrag(event) {
dragging = false;
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();
distance = THREE.MathUtils.clamp(
distance + event.deltaY * 0.015,
17,
52
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
document.getElementById("resetButton").addEventListener("click", resetView);
let playing = true;
const pauseButton = document.getElementById("pauseButton");
pauseButton.addEventListener("click", () => {
playing = !playing;
pauseButton.textContent = playing ? "Pause flow" : "Resume flow";
pauseButton.setAttribute("aria-pressed", String(!playing));
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
if (window.innerWidth / window.innerHeight < 0.8) {
cameraTarget.y = 1.55;
distance = Math.max(distance, 35);
} else {
cameraTarget.y = 0.45;
}
updateCamera();
});
resetView();
addGround();
const clock = new THREE.Clock();
let flowTime = 0;
let elapsed = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
if (playing) {
flowTime += delta;
engineRotor.rotation.z -= delta * 1.6;
generatorCap.rotation.z += delta * 1.8;
}
flowArrows.forEach((arrow) => {
arrow.particles.forEach((particle, index) => {
const offset = index / arrow.particles.length;
const u = (flowTime * 0.135 + offset + arrow.phase) % 1;
particle.position.copy(arrow.curve.getPointAt(u));
const pulse = 0.88 + Math.sin((u + arrow.phase) * Math.PI * 4) * 0.16;
particle.scale.setScalar(pulse);
});
});
pulseMaterials.forEach((entry) => {
entry.material.emissiveIntensity =
entry.base +
Math.sin(elapsed * 1.8 + entry.phase) * entry.amplitude;
});
engineLamp.intensity = 6.5 + Math.sin(elapsed * 2.1) * 1.2;
fridgeLamp.intensity = 7.2 + Math.sin(elapsed * 2.1 + 1.4) * 1.2;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```