Prompt specification
Build or customize the Three.js 3D scene "Warm and Cool Still-Life 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: Warm and Cool Still-Life Comparison
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/warm-and-cool-still-life-comparison-x3286
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: warm and cool still-life comparison. Build two matched fruit still lifes with one lighting parameter changed at a time. Display the chosen condition without claiming a universal emotional response to color. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (warm-and-cool-still-life-comparison-x3286):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Warm / Cool — Controlled Still-Life Lighting Study</title>
<style>
:root {
color-scheme: light;
--ink: #25241f;
--muted: #6f6b61;
--paper: #f3efe6;
--panel: #fbf8f1;
--line: #d8d1c3;
--warm: #e6a76d;
--neutral: #eee6d8;
--cool: #9fc2e4;
--blue: #375e83;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background:
radial-gradient(circle at 12% 0%, rgba(231, 191, 135, 0.16), transparent 31rem),
var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
padding: 32px 24px 56px;
}
main {
width: min(1440px, 100%);
margin: 0 auto;
}
header {
display: grid;
grid-template-columns: 1fr auto;
align-items: end;
gap: 32px;
margin-bottom: 24px;
}
.eyebrow {
margin: 0 0 10px;
color: var(--blue);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(2.4rem, 5vw, 4.8rem);
font-weight: 500;
letter-spacing: -0.045em;
line-height: 0.94;
}
.intro {
max-width: 470px;
margin: 0 0 3px;
color: var(--muted);
font-size: 0.98rem;
line-height: 1.6;
}
.control-card {
display: grid;
grid-template-columns: minmax(220px, 0.8fr) minmax(430px, 1.4fr) minmax(220px, 0.8fr);
align-items: center;
gap: 20px;
margin-bottom: 14px;
padding: 18px 20px;
border: 1px solid var(--line);
border-radius: 18px;
background: rgba(251, 248, 241, 0.9);
box-shadow: 0 8px 35px rgba(52, 44, 30, 0.045);
}
.control-label,
.mini-label {
margin: 0 0 7px;
color: var(--muted);
font-size: 0.67rem;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.reference-value {
display: flex;
align-items: center;
gap: 12px;
font-size: 1rem;
font-weight: 750;
}
.swatch {
width: 32px;
height: 32px;
flex: 0 0 auto;
border: 1px solid rgba(38, 35, 27, 0.13);
border-radius: 50%;
box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.35);
}
.swatch.warm {
background: linear-gradient(135deg, #ffdfb3, #d9904e);
}
.swatch.cool {
background: linear-gradient(135deg, #e2f2ff, #8eb7dd);
}
.segments {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
padding: 5px;
border: 1px solid var(--line);
border-radius: 13px;
background: #eee9df;
}
.segment {
min-height: 46px;
border: 0;
border-radius: 9px;
background: transparent;
color: #656056;
cursor: pointer;
font: inherit;
font-size: 0.83rem;
font-weight: 750;
transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}
.segment:hover {
background: rgba(255, 255, 255, 0.55);
}
.segment[aria-pressed="true"] {
background: var(--panel);
color: var(--ink);
box-shadow: 0 2px 8px rgba(48, 42, 31, 0.1);
}
.condition-readout {
justify-self: end;
text-align: right;
}
.condition-badge {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 12px;
border: 1px solid #b9cede;
border-radius: 999px;
background: #e6f0f8;
color: #294f70;
font-size: 0.76rem;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.condition-badge::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
content: "";
}
.viewer-card {
overflow: hidden;
border: 1px solid var(--line);
border-radius: 22px;
background: #d8d1c4;
box-shadow: 0 20px 60px rgba(58, 48, 32, 0.11);
}
.viewer-toolbar {
display: flex;
align-items: center;
justify-content: space-between;
min-height: 54px;
padding: 10px 16px 10px 20px;
border-bottom: 1px solid var(--line);
background: var(--panel);
}
.toolbar-copy {
display: flex;
align-items: center;
gap: 10px;
color: var(--muted);
font-size: 0.78rem;
}
.variable-pill {
padding: 5px 9px;
border-radius: 999px;
background: #e9eee9;
color: #43614d;
font-size: 0.66rem;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.viewer-actions {
display: flex;
gap: 8px;
}
button.action {
padding: 8px 12px;
border: 1px solid var(--line);
border-radius: 9px;
background: transparent;
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 0.75rem;
font-weight: 750;
}
button.action:hover {
background: #eee8dc;
}
#stage {
position: relative;
height: min(68vh, 690px);
min-height: 540px;
overflow: hidden;
background: #d8d1c4;
isolation: isolate;
}
#stage::after {
position: absolute;
z-index: 2;
inset: 0;
pointer-events: none;
background: radial-gradient(circle at 50% 46%, transparent 55%, rgba(52, 43, 31, 0.08));
content: "";
}
#stage canvas {
position: absolute;
z-index: 0;
inset: 0;
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#stage canvas:active {
cursor: grabbing;
}
.view-label {
position: absolute;
z-index: 3;
top: 0;
left: 0;
display: flex;
align-items: center;
gap: 12px;
padding: 18px;
pointer-events: none;
}
.view-letter {
display: grid;
width: 34px;
height: 34px;
place-items: center;
border: 1px solid rgba(42, 38, 29, 0.18);
border-radius: 50%;
background: rgba(250, 247, 239, 0.84);
color: #343028;
font-family: Georgia, serif;
font-size: 1rem;
backdrop-filter: blur(8px);
}
.view-text {
padding: 8px 10px;
border-radius: 8px;
background: rgba(250, 247, 239, 0.84);
box-shadow: 0 3px 16px rgba(40, 34, 24, 0.05);
backdrop-filter: blur(8px);
}
.view-text strong,
.view-text span {
display: block;
}
.view-text strong {
color: #302d26;
font-size: 0.82rem;
letter-spacing: 0.02em;
}
.view-text span {
margin-top: 2px;
color: #736d62;
font-size: 0.68rem;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.split-divider {
position: absolute;
z-index: 3;
top: 0;
left: 50%;
width: 1px;
height: 100%;
pointer-events: none;
background: rgba(61, 55, 44, 0.22);
}
.stage-hint {
position: absolute;
z-index: 3;
right: 16px;
bottom: 14px;
padding: 7px 10px;
border-radius: 999px;
background: rgba(250, 247, 239, 0.76);
color: #6d675d;
font-size: 0.67rem;
font-weight: 700;
pointer-events: none;
backdrop-filter: blur(8px);
}
.details {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 14px;
margin-top: 14px;
}
.detail-card {
min-height: 150px;
padding: 20px;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(251, 248, 241, 0.78);
}
.detail-number {
display: inline-block;
margin-bottom: 20px;
color: #8b8173;
font-family: Georgia, serif;
font-size: 0.9rem;
}
.detail-card h2 {
margin: 0 0 8px;
font-size: 0.93rem;
letter-spacing: -0.01em;
}
.detail-card p {
margin: 0;
color: var(--muted);
font-size: 0.82rem;
line-height: 1.55;
}
.footer-note {
max-width: 900px;
margin: 22px auto 0;
color: #7a7469;
font-size: 0.76rem;
line-height: 1.6;
text-align: center;
}
@media (max-width: 980px) {
header {
grid-template-columns: 1fr;
gap: 16px;
}
.intro {
max-width: 680px;
}
.control-card {
grid-template-columns: 1fr 1.5fr;
}
.condition-readout {
grid-column: 1 / -1;
justify-self: start;
text-align: left;
}
.details {
grid-template-columns: 1fr;
}
.detail-card {
min-height: auto;
}
.detail-number {
margin-bottom: 10px;
}
}
@media (max-width: 680px) {
body {
padding: 22px 12px 40px;
}
.control-card {
grid-template-columns: 1fr;
padding: 16px;
}
.condition-readout {
grid-column: auto;
}
#stage {
height: 820px;
min-height: 0;
}
.viewer-toolbar {
align-items: flex-start;
gap: 10px;
}
.toolbar-copy {
align-items: flex-start;
flex-direction: column;
}
.split-divider {
top: 50%;
left: 0;
width: 100%;
height: 1px;
}
.view-label {
padding: 12px;
}
.stage-hint {
right: 10px;
bottom: 10px;
}
}
</style>
</head>
<body>
<main>
<header>
<div>
<p class="eyebrow">Controlled light study · No. 01</p>
<h1>Warm / Cool</h1>
</div>
<p class="intro">
Two matched low-poly fruit still lifes. The camera, fruit, materials,
exposure, and lighting position remain fixed while the key light’s color
temperature changes.
</p>
</header>
<section class="control-card" aria-label="Lighting condition controls">
<div>
<p class="control-label">Reference A</p>
<div class="reference-value">
<span class="swatch warm" aria-hidden="true"></span>
<span>Warm · 3000 K</span>
</div>
</div>
<div>
<p class="control-label">Test condition B</p>
<div class="segments" role="group" aria-label="Choose key-light color temperature">
<button class="segment" type="button" data-condition="warm" aria-pressed="false">
Warm
</button>
<button class="segment" type="button" data-condition="neutral" aria-pressed="false">
Neutral
</button>
<button class="segment" type="button" data-condition="cool" aria-pressed="true">
Cool
</button>
</div>
</div>
<div class="condition-readout">
<p class="control-label">Selected condition</p>
<span id="conditionBadge" class="condition-badge">Cool · 7500 K</span>
</div>
</section>
<section class="viewer-card" aria-label="Interactive 3D comparison">
<div class="viewer-toolbar">
<div class="toolbar-copy">
<span class="variable-pill">1 variable</span>
<span>Key-light color temperature only</span>
</div>
<div class="viewer-actions">
<button id="resetView" class="action" type="button">Reset view</button>
</div>
</div>
<div id="stage">
<div id="labelA" class="view-label">
<span class="view-letter">A</span>
<div class="view-text">
<strong>Warm reference</strong>
<span>3000 K</span>
</div>
</div>
<div id="labelB" class="view-label">
<span class="view-letter">B</span>
<div class="view-text">
<strong id="testTitle">Cool test</strong>
<span id="testKelvin">7500 K</span>
</div>
</div>
<div id="splitDivider" class="split-divider"></div>
<div class="stage-hint">Drag to orbit · Scroll to zoom · Views stay matched</div>
</div>
</section>
<section class="details" aria-label="Study notes">
<article class="detail-card">
<span class="detail-number">01 / Held constant</span>
<h2>Everything except color</h2>
<p>
Key-light intensity, direction, fill, shadow settings, exposure, camera,
fruit colors, materials, and composition are identical in both views.
</p>
</article>
<article class="detail-card">
<span class="detail-number">02 / Changed variable</span>
<h2>Color temperature</h2>
<p>
Reference A uses a 3000 K warm key. Condition B changes only that
light’s color temperature to the selected value.
</p>
</article>
<article class="detail-card">
<span class="detail-number">03 / Image reading</span>
<h2 id="conditionDescription">Cooler illuminated neutrals</h2>
<p>
The selected condition shifts the appearance of lit surfaces without
changing the scene itself. This is a visual description, not a claim
about a universal emotional response to color.
</p>
</article>
</section>
<p class="footer-note">
Color-temperature labels describe the lighting setup. Perceptual and
emotional responses can vary with culture, context, viewing conditions,
and individual preference; no universal effect is implied.
</p>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const labelA = document.getElementById("labelA");
const labelB = document.getElementById("labelB");
const splitDivider = document.getElementById("splitDivider");
const conditionBadge = document.getElementById("conditionBadge");
const testTitle = document.getElementById("testTitle");
const testKelvin = document.getElementById("testKelvin");
const conditionDescription = document.getElementById("conditionDescription");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.id = "three-canvas";
renderer.domElement.setAttribute("aria-label", "Two matched low-poly fruit still lifes under different key-light colors");
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(36, 1, 0.1, 60);
const orbit = {
radius: 8.4,
theta: 0.24,
phi: 1.08,
target: new THREE.Vector3(0, 0.78, 0)
};
const conditions = {
warm: {
name: "Warm",
kelvin: 3000,
color: new THREE.Color().setRGB(255 / 255, 188 / 255, 121 / 255, THREE.SRGBColorSpace),
description: "Warmer illuminated neutrals"
},
neutral: {
name: "Neutral",
kelvin: 4500,
color: new THREE.Color().setRGB(255 / 255, 245 / 255, 231 / 255, THREE.SRGBColorSpace),
description: "More nearly neutral illuminated surfaces"
},
cool: {
name: "Cool",
kelvin: 7500,
color: new THREE.Color().setRGB(183 / 255, 216 / 255, 255 / 255, THREE.SRGBColorSpace),
description: "Cooler illuminated neutrals"
}
};
const warmReferenceColor = conditions.warm.color.clone();
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0,
flatShading: options.flatShading ?? true,
side: options.side ?? THREE.FrontSide
});
}
function configureMesh(mesh, castShadow = true, receiveShadow = true) {
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
return mesh;
}
function cylinderBetween(start, end, radius, material, radialSegments = 6) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(radius, radius * 1.08, length, radialSegments);
const mesh = configureMesh(new THREE.Mesh(geometry, material));
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function makeLeaf(material, scale = 1) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
0, 0, 0,
0.36, 0.12, 0,
0.72, 0, 0,
0, 0, 0,
0.72, 0, 0,
0.36, -0.12, 0,
0.36, 0.12, 0,
0.36, -0.12, 0,
0.72, 0, 0
], 3)
);
geometry.computeVertexNormals();
const leaf = configureMesh(new THREE.Mesh(geometry, material));
leaf.scale.setScalar(scale);
return leaf;
}
function addStem(parent, height, material, x = 0, z = 0) {
const stem = configureMesh(
new THREE.Mesh(new THREE.CylinderGeometry(0.035, 0.055, height, 6), material)
);
stem.position.set(x, height * 0.5, z);
stem.rotation.z = -0.1;
parent.add(stem);
return stem;
}
function makeOrange(materials, size = 1) {
const group = new THREE.Group();
const fruit = configureMesh(
new THREE.Mesh(new THREE.IcosahedronGeometry(0.58, 1), materials.orange)
);
fruit.scale.set(1, 0.96, 1);
group.add(fruit);
const navel = configureMesh(
new THREE.Mesh(new THREE.IcosahedronGeometry(0.075, 0), materials.stem)
);
navel.position.set(0, 0.54, 0);
navel.scale.y = 0.42;
group.add(navel);
const leaf = makeLeaf(materials.leaf, 0.65);
leaf.position.set(0.02, 0.56, 0.01);
leaf.rotation.set(-0.7, 0.4, -0.2);
group.add(leaf);
group.scale.setScalar(size);
return group;
}
function makeApple(materials) {
const group = new THREE.Group();
const fruit = configureMesh(
new THREE.Mesh(new THREE.IcosahedronGeometry(0.62, 1), materials.apple)
);
fruit.scale.set(1, 0.91, 0.97);
group.add(fruit);
const stem = addStem(group, 0.34, materials.stem, 0.03, 0);
stem.rotation.z = -0.16;
const leaf = makeLeaf(materials.leaf, 0.72);
leaf.position.set(0.02, 0.36, 0.01);
leaf.rotation.set(-0.85, -0.15, -0.2);
group.add(leaf);
return group;
}
function makePear(materials) {
const group = new THREE.Group();
const points = [
new THREE.Vector2(0.02, -0.92),
new THREE.Vector2(0.34, -0.79),
new THREE.Vector2(0.61, -0.42),
new THREE.Vector2(0.63, -0.03),
new THREE.Vector2(0.51, 0.36),
new THREE.Vector2(0.32, 0.64),
new THREE.Vector2(0.17, 0.89),
new THREE.Vector2(0.02, 1.00)
];
const fruit = configureMesh(
new THREE.Mesh(new THREE.LatheGeometry(points, 10), materials.pear)
);
fruit.scale.setScalar(0.88);
group.add(fruit);
const stem = addStem(group, 0.34, materials.stem, 0.015, 0);
stem.rotation.z = -0.12;
const leaf = makeLeaf(materials.leaf, 0.58);
leaf.position.set(0.03, 0.52, 0);
leaf.rotation.set(-0.72, 0.5, -0.18);
group.add(leaf);
return group;
}
function makeLemon(materials) {
const group = new THREE.Group();
const fruit = configureMesh(
new THREE.Mesh(new THREE.SphereGeometry(0.47, 10, 6), materials.lemon)
);
fruit.scale.set(1.32, 0.78, 0.83);
fruit.rotation.z = -0.32;
group.add(fruit);
return group;
}
function makeGrapes(materials) {
const group = new THREE.Group();
const positions = [
[-0.25, 0.15, 0.02], [0.02, 0.20, 0.02], [0.27, 0.12, 0.04],
[-0.15, -0.10, 0.05], [0.12, -0.08, 0.08], [0.00, -0.34, 0.06],
[-0.34, -0.28, 0.0], [0.30, -0.28, 0.0], [-0.14, -0.56, 0.03],
[0.12, -0.58, 0.01]
];
for (const [x, y, z] of positions) {
const grape = configureMesh(
new THREE.Mesh(new THREE.IcosahedronGeometry(0.18, 0), materials.grape)
);
grape.position.set(x, y, z);
grape.scale.set(1, 0.92, 0.95);
group.add(grape);
}
const stem = cylinderBetween(
new THREE.Vector3(0.02, 0.18, 0),
new THREE.Vector3(0.12, 0.75, -0.02),
0.035,
materials.stem
);
group.add(stem);
const leaf = makeLeaf(materials.leaf, 0.6);
leaf.position.set(0.09, 0.65, 0);
leaf.rotation.set(-0.8, 0.2, -0.2);
group.add(leaf);
return group;
}
function createStillLife(keyColor) {
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d1c4);
scene.fog = new THREE.Fog(0xd8d1c4, 14, 27);
const materials = {
orange: standardMaterial(0xe46f2d, { roughness: 0.76 }),
apple: standardMaterial(0xc9453f, { roughness: 0.68 }),
pear: standardMaterial(0xaeb957, { roughness: 0.78 }),
lemon: standardMaterial(0xe4c842, { roughness: 0.74 }),
grape: standardMaterial(0x704478, { roughness: 0.68 }),
stem: standardMaterial(0x65442d, { roughness: 0.95 }),
leaf: standardMaterial(0x53784b, {
roughness: 0.9,
side: THREE.DoubleSide
}),
ceramic: standardMaterial(0xe8dfcd, { roughness: 0.72 }),
table: standardMaterial(0xb88b61, { roughness: 0.9 }),
floor: standardMaterial(0xcac2b4, { roughness: 1, flatShading: false })
};
const floor = configureMesh(
new THREE.Mesh(new THREE.PlaneGeometry(40, 40), materials.floor),
false,
true
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.47;
scene.add(floor);
const wall = configureMesh(
new THREE.Mesh(new THREE.PlaneGeometry(40, 22), materials.floor),
false,
true
);
wall.position.set(0, 10, -6);
scene.add(wall);
const table = configureMesh(
new THREE.Mesh(new THREE.CylinderGeometry(4.15, 4.25, 0.44, 32), materials.table)
);
table.position.y = -0.22;
scene.add(table);
const tableEdge = configureMesh(
new THREE.Mesh(new THREE.CylinderGeometry(4.16, 4.16, 0.055, 32),
standardMaterial(0x9c714f, { roughness: 0.9 }))
);
tableEdge.position.y = -0.005;
scene.add(tableEdge);
const bowlProfile = [
new THREE.Vector2(0.02, -0.08),
new THREE.Vector2(0.68, -0.07),
new THREE.Vector2(1.12, 0.07),
new THREE.Vector2(1.48, 0.38),
new THREE.Vector2(1.61, 0.77),
new THREE.Vector2(1.66, 0.91),
new THREE.Vector2(1.55, 0.95),
new THREE.Vector2(1.47, 0.73),
new THREE.Vector2(1.25, 0.32),
new THREE.Vector2(0.82, 0.06),
new THREE.Vector2(0.02, 0.04)
];
const bowl = configureMesh(
new THREE.Mesh(new THREE.LatheGeometry(bowlProfile, 18), materials.ceramic)
);
bowl.position.y = 0.04;
scene.add(bowl);
const orange = makeOrange(materials, 1.02);
orange.position.set(-0.58, 0.91, 0.18);
orange.rotation.set(0.1, 0.4, -0.08);
scene.add(orange);
const apple = makeApple(materials);
apple.position.set(0.27, 1.01, 0.34);
apple.rotation.y = 0.35;
scene.add(apple);
const pear = makePear(materials);
pear.position.set(0.98, 0.93, -0.13);
pear.rotation.y = -0.45;
scene.add(pear);
const lemon = makeLemon(materials);
lemon.position.set(-0.95, 1.17, -0.37);
lemon.rotation.y = 0.35;
scene.add(lemon);
const grapes = makeGrapes(materials);
grapes.position.set(0.73, 1.43, 0.11);
grapes.rotation.y = -0.25;
scene.add(grapes);
const looseOrange = makeOrange(materials, 0.9);
looseOrange.position.set(-2.05, 0.51, 0.93);
looseOrange.rotation.y = -0.7;
scene.add(looseOrange);
const tableLeaf = makeLeaf(materials.leaf, 1.1);
tableLeaf.position.set(1.85, 0.04, 0.93);
tableLeaf.rotation.set(-Math.PI / 2, 0.3, 0.55);
scene.add(tableLeaf);
const stemLine = cylinderBetween(
new THREE.Vector3(1.88, 0.05, 0.96),
new THREE.Vector3(2.42, 0.05, 0.58),
0.025,
materials.stem
);
scene.add(stemLine);
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x8d8274, 1.25);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(keyColor.clone(), 3.15);
key.position.set(-3.8, 6.6, 4.4);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -5.5;
key.shadow.camera.right = 5.5;
key.shadow.camera.top = 5.5;
key.shadow.camera.bottom = -5.5;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 20;
key.shadow.bias = -0.00035;
key.shadow.normalBias = 0.025;
key.target.position.set(0, 0.65, 0);
scene.add(key);
scene.add(key.target);
const fill = new THREE.DirectionalLight(0xffffff, 0.48);
fill.position.set(4.8, 3.2, 2.1);
fill.target.position.set(0, 0.8, 0);
scene.add(fill);
scene.add(fill.target);
const rim = new THREE.DirectionalLight(0xffffff, 0.35);
rim.position.set(1.5, 3.8, -4.2);
rim.target.position.set(0, 1, 0);
scene.add(rim);
scene.add(rim.target);
scene.userData.key = key;
return scene;
}
const referenceScene = createStillLife(warmReferenceColor);
const testScene = createStillLife(conditions.cool.color);
let currentCondition = "cool";
let stacked = false;
function setCondition(name) {
currentCondition = name;
const condition = conditions[name];
testScene.userData.key.color.copy(condition.color);
conditionBadge.textContent = `${condition.name} · ${condition.kelvin} K`;
testTitle.textContent = `${condition.name} test`;
testKelvin.textContent = `${condition.kelvin} K`;
conditionDescription.textContent = condition.description;
document.querySelectorAll(".segment").forEach((button) => {
button.setAttribute("aria-pressed", String(button.dataset.condition === name));
});
}
document.querySelectorAll(".segment").forEach((button) => {
button.addEventListener("click", () => setCondition(button.dataset.condition));
});
function resizeRenderer() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
}
function updateCamera() {
const width = stage.clientWidth;
const height = stage.clientHeight;
stacked = width < 680;
const viewHeight = stacked ? height * 0.5 : height;
const aspect = width / viewHeight;
const responsiveScale = aspect < 0.8 ? 1.38 : 1;
const radius = orbit.radius * responsiveScale;
camera.aspect = aspect;
camera.updateProjectionMatrix();
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + radius * Math.cos(orbit.phi),
orbit.target.z + radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
if (stacked) {
labelA.style.left = "0";
labelA.style.top = "0";
labelA.style.width = "100%";
labelA.style.height = "50%";
labelB.style.left = "0";
labelB.style.top = "50%";
labelB.style.width = "100%";
labelB.style.height = "50%";
splitDivider.style.top = "50%";
splitDivider.style.left = "0";
splitDivider.style.width = "100%";
splitDivider.style.height = "1px";
} else {
labelA.style.left = "0";
labelA.style.top = "0";
labelA.style.width = "50%";
labelA.style.height = "100%";
labelB.style.left = "50%";
labelB.style.top = "0";
labelB.style.width = "50%";
labelB.style.height = "100%";
splitDivider.style.top = "0";
splitDivider.style.left = "50%";
splitDivider.style.width = "1px";
splitDivider.style.height = "100%";
}
}
function renderViews() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setScissorTest(true);
if (stacked) {
const halfHeight = Math.floor(height / 2);
renderer.setViewport(0, halfHeight, width, height - halfHeight);
renderer.setScissor(0, halfHeight, width, height - halfHeight);
renderer.render(referenceScene, camera);
renderer.setViewport(0, 0, width, halfHeight);
renderer.setScissor(0, 0, width, halfHeight);
renderer.render(testScene, camera);
} else {
const halfWidth = Math.floor(width / 2);
renderer.setViewport(0, 0, halfWidth, height);
renderer.setScissor(0, 0, halfWidth, height);
renderer.render(referenceScene, camera);
renderer.setViewport(halfWidth, 0, width - halfWidth, height);
renderer.setScissor(halfWidth, 0, width - halfWidth, height);
renderer.render(testScene, camera);
}
}
let dragging = false;
let previousX = 0;
let previousY = 0;
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 deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= deltaX * 0.005;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + deltaY * 0.004, 0.72, 1.32);
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();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.006,
6.1,
11.2
);
updateCamera();
}, { passive: false });
function resetView() {
orbit.radius = 8.4;
orbit.theta = 0.24;
orbit.phi = 1.08;
updateCamera();
}
document.getElementById("resetView").addEventListener("click", resetView);
renderer.domElement.addEventListener("dblclick", resetView);
const resizeObserver = new ResizeObserver(() => {
resizeRenderer();
updateCamera();
});
resizeObserver.observe(stage);
window.addEventListener("resize", () => {
resizeRenderer();
updateCamera();
});
setCondition("cool");
resizeRenderer();
updateCamera();
renderer.setAnimationLoop(() => {
renderViews();
});
</script>
</body>
</html>
```