Prompt specification
Build or customize the Three.js 3D scene "Penumbra size exploration tool" 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: Penumbra size exploration tool
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/penumbra-size-exploration-tool-x1584
Scene Description Prompt:
Allow changing source diameter and blocker-to-screen distance; update the constructed shadow regions and explain why softness depends on geometry rather than only material darkness. Build this with Three.js from cdnjs as a low-poly scene in one self-contained HTML file.
Working Three.js Starter (penumbra-size-exploration-tool-x1584):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Extended-Source Shadow Lab</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(9, 15, 23, 0.88);
--border: rgba(154, 196, 220, 0.2);
--text: #e8f1f7;
--muted: #9db0bf;
--cyan: #58dcff;
--pink: #ff69c7;
--amber: #ffd166;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #081018;
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
#panel {
position: fixed;
z-index: 10;
top: 16px;
left: 16px;
width: min(370px, calc(100vw - 32px));
max-height: calc(100vh - 32px);
overflow: auto;
padding: 18px;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
backdrop-filter: blur(16px);
}
h1 {
margin: 0 0 6px;
font-size: 1.28rem;
letter-spacing: 0.01em;
}
.subtitle {
margin: 0 0 18px;
color: var(--muted);
font-size: 0.88rem;
line-height: 1.45;
}
.control {
margin: 15px 0;
}
.control label {
display: flex;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
font-size: 0.88rem;
font-weight: 650;
}
output {
color: var(--cyan);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
accent-color: var(--cyan);
cursor: pointer;
}
.toggle-row {
display: flex;
flex-wrap: wrap;
gap: 14px;
margin: 14px 0 17px;
color: var(--muted);
font-size: 0.83rem;
}
.toggle-row label {
display: flex;
align-items: center;
gap: 6px;
cursor: pointer;
}
.toggle-row input {
accent-color: var(--cyan);
}
button {
border: 1px solid var(--border);
border-radius: 8px;
padding: 7px 10px;
color: var(--text);
background: rgba(255, 255, 255, 0.06);
cursor: pointer;
font: inherit;
font-size: 0.8rem;
}
button:hover {
background: rgba(255, 255, 255, 0.11);
}
.stats {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 8px;
margin: 16px 0;
}
.stat {
min-height: 64px;
padding: 10px;
border: 1px solid rgba(154, 196, 220, 0.13);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
}
.stat span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 0.72rem;
}
.stat strong {
font-size: 1rem;
font-variant-numeric: tabular-nums;
}
.callout {
margin: 14px 0;
padding: 12px;
border-left: 3px solid var(--cyan);
border-radius: 7px;
color: #c9d7e0;
background: rgba(88, 220, 255, 0.075);
font-size: 0.82rem;
line-height: 1.5;
}
.explanation {
color: #c3d0d9;
font-size: 0.82rem;
line-height: 1.52;
}
.explanation strong {
color: #ffffff;
}
details {
margin-top: 14px;
color: var(--muted);
font-size: 0.8rem;
line-height: 1.5;
}
summary {
color: var(--text);
cursor: pointer;
font-weight: 650;
}
.equation {
display: block;
overflow-x: auto;
margin: 10px 0;
padding: 9px;
border-radius: 7px;
color: #dce9f1;
background: rgba(0, 0, 0, 0.28);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
white-space: nowrap;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 10px 14px;
margin-top: 14px;
color: var(--muted);
font-size: 0.75rem;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 17px;
height: 3px;
border-radius: 2px;
}
.swatch.outer {
background: var(--cyan);
}
.swatch.inner {
background: var(--pink);
}
.swatch.boundary {
background: var(--amber);
}
.hint {
margin-top: 15px;
color: #7f94a3;
font-size: 0.73rem;
}
#labels {
position: fixed;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
left: 0;
top: 0;
padding: 4px 7px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 5px;
color: #eaf5fb;
background: rgba(5, 10, 16, 0.72);
font-size: 0.68rem;
font-weight: 700;
letter-spacing: 0.055em;
white-space: nowrap;
transform: translate(-50%, -50%);
}
@media (max-width: 700px) {
#panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 44vh;
padding: 14px;
}
h1 {
font-size: 1.05rem;
}
.subtitle {
margin-bottom: 10px;
}
.stats {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.stat {
min-height: 56px;
padding: 8px;
}
.stat strong {
font-size: 0.82rem;
}
.world-label {
font-size: 0.58rem;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive extended-source shadow geometry"></canvas>
<div id="labels" aria-hidden="true">
<div class="world-label" id="sourceLabel">AREA SOURCE</div>
<div class="world-label" id="blockerLabel">OPAQUE BLOCKER</div>
<div class="world-label" id="screenLabel">SCREEN</div>
<div class="world-label" id="distanceLabel">L = 3.50</div>
</div>
<aside id="panel">
<h1>Extended-Source Shadow Lab</h1>
<p class="subtitle">
A finite luminous source produces overlapping ray bundles. Explore how
source size and blocker-to-screen distance construct the umbra and penumbra.
</p>
<div class="control">
<label for="sourceDiameter">
<span>Source diameter</span>
<output id="sourceOutput" for="sourceDiameter">0.75 units</output>
</label>
<input
id="sourceDiameter"
type="range"
min="0.15"
max="2.40"
step="0.01"
value="0.75"
>
</div>
<div class="control">
<label for="screenDistance">
<span>Blocker-to-screen distance</span>
<output id="distanceOutput" for="screenDistance">3.50 units</output>
</label>
<input
id="screenDistance"
type="range"
min="1"
max="8"
step="0.05"
value="3.50"
>
</div>
<div class="toggle-row">
<label>
<input id="showRays" type="checkbox" checked>
Construction rays
</label>
<label>
<input id="showZones" type="checkbox" checked>
Shadow zones
</label>
<button id="resetCamera" type="button">Reset camera</button>
</div>
<div class="stats" aria-live="polite">
<div class="stat">
<span>Umbra diameter</span>
<strong id="umbraMetric">—</strong>
</div>
<div class="stat">
<span>Penumbra edge width</span>
<strong id="penumbraMetric">—</strong>
</div>
<div class="stat">
<span>Outer shadow diameter</span>
<strong id="outerMetric">—</strong>
</div>
<div class="stat">
<span>Source-to-blocker distance</span>
<strong>4.00 units</strong>
</div>
</div>
<div class="callout" id="dynamicNote"></div>
<p class="explanation">
<strong>Why is softness geometric?</strong>
Darkness describes how much light is blocked. Softness describes the
distance over which the illumination changes from fully blocked to
unblocked. Rays emitted from different points of the finite source hit
slightly different places behind the blocker. Their overlap creates the
penumbra. Increasing the source diameter or moving the screen farther away
enlarges that transition. Making the blocker darker changes contrast,
but it does not move the geometric shadow edges.
</p>
<details>
<summary>Geometric construction</summary>
<p>
Let <strong>A</strong> be the fixed source-to-blocker distance,
<strong>L</strong> the blocker-to-screen distance,
<strong>S</strong> the source diameter, and
<strong>B</strong> the fixed blocker diameter.
</p>
<code class="equation">
projected blocker = B(A + L) / A<br>
source spread = S L / A<br>
umbra diameter = max(0, projected blocker − source spread)<br>
outer diameter = projected blocker + source spread
</code>
<p>
Cyan rays construct the outer penumbra boundary. Pink rays construct
the inner umbra boundary when an umbra exists.
</p>
</details>
<div class="legend">
<span><i class="swatch outer"></i> Outer tangents</span>
<span><i class="swatch inner"></i> Inner tangents</span>
<span><i class="swatch boundary"></i> Outer shadow edge</span>
</div>
<div class="hint">
Drag the scene to orbit. Use the mouse wheel to zoom. Double-click the
scene to reset the camera.
</div>
</aside>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Constants and state
// ---------------------------------------------------------------------
const SOURCE_X = -4.0;
const SOURCE_TO_BLOCKER = 4.0;
const BLOCKER_DIAMETER = 1.2;
const state = {
sourceDiameter: 0.75,
screenDistance: 3.5,
showRays: true,
showZones: true
};
const ui = {
sourceInput: document.querySelector("#sourceDiameter"),
distanceInput: document.querySelector("#screenDistance"),
sourceOutput: document.querySelector("#sourceOutput"),
distanceOutput: document.querySelector("#distanceOutput"),
showRays: document.querySelector("#showRays"),
showZones: document.querySelector("#showZones"),
resetCamera: document.querySelector("#resetCamera"),
umbraMetric: document.querySelector("#umbraMetric"),
penumbraMetric: document.querySelector("#penumbraMetric"),
outerMetric: document.querySelector("#outerMetric"),
dynamicNote: document.querySelector("#dynamicNote"),
sourceLabel: document.querySelector("#sourceLabel"),
blockerLabel: document.querySelector("#blockerLabel"),
screenLabel: document.querySelector("#screenLabel"),
distanceLabel: document.querySelector("#distanceLabel")
};
// ---------------------------------------------------------------------
// Renderer, scene, and camera
// ---------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x081018);
scene.fog = new THREE.Fog(0x081018, 28, 52);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const cameraTarget = new THREE.Vector3();
let cameraRadius = 18.5;
let cameraAzimuth = 0.72;
let cameraPolar = 1.12;
function updateCamera() {
cameraTarget.set(
(SOURCE_X + state.screenDistance) * 0.5,
0,
0
);
const sinPolar = Math.sin(cameraPolar);
camera.position.set(
cameraTarget.x + cameraRadius * sinPolar * Math.cos(cameraAzimuth),
cameraRadius * Math.cos(cameraPolar),
cameraTarget.z + cameraRadius * sinPolar * Math.sin(cameraAzimuth)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Preserve a useful horizontal view on narrow displays.
const viewHeight = Math.max(12, 15 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
updateCamera();
}
window.addEventListener("resize", resize);
// ---------------------------------------------------------------------
// Lighting and low-poly set dressing
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xb9dcff, 0x17202b, 2.0));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.3);
keyLight.position.set(6, 10, 9);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x6fc9ff, 1.0);
rimLight.position.set(-8, 3, -7);
scene.add(rimLight);
const grid = new THREE.GridHelper(32, 32, 0x30475a, 0x182a38);
grid.position.y = -5.08;
scene.add(grid);
// ---------------------------------------------------------------------
// Area source
// ---------------------------------------------------------------------
const sourceMaterial = new THREE.MeshStandardMaterial({
color: 0xffd36b,
emissive: 0xff9f2d,
emissiveIntensity: 2.1,
roughness: 0.48,
metalness: 0.02,
flatShading: true
});
const sourceBody = new THREE.Mesh(
new THREE.CylinderGeometry(1, 1, 0.16, 16),
sourceMaterial
);
// The cylinder's local Y axis is its thickness axis. Rotating it makes
// the disk face the blocker while local scale controls only its radius.
sourceBody.rotation.z = Math.PI / 2;
sourceBody.position.x = SOURCE_X;
scene.add(sourceBody);
const sourceHaloMaterial = new THREE.MeshBasicMaterial({
color: 0xffb84d,
transparent: true,
opacity: 0.12,
depthWrite: false,
side: THREE.DoubleSide
});
const sourceHalo = new THREE.Mesh(
new THREE.CylinderGeometry(1.12, 1.12, 0.13, 16),
sourceHaloMaterial
);
sourceHalo.rotation.z = Math.PI / 2;
sourceHalo.position.x = SOURCE_X - 0.025;
sourceHalo.renderOrder = 1;
scene.add(sourceHalo);
// ---------------------------------------------------------------------
// Opaque blocker
// ---------------------------------------------------------------------
const blocker = new THREE.Mesh(
new THREE.CylinderGeometry(
BLOCKER_DIAMETER * 0.5,
BLOCKER_DIAMETER * 0.5,
0.20,
12
),
new THREE.MeshStandardMaterial({
color: 0x18212b,
roughness: 0.94,
metalness: 0.03,
flatShading: true
})
);
blocker.rotation.z = Math.PI / 2;
blocker.position.x = 0;
scene.add(blocker);
const blockerRim = new THREE.Mesh(
new THREE.TorusGeometry(BLOCKER_DIAMETER * 0.5, 0.022, 6, 28),
new THREE.MeshStandardMaterial({
color: 0x6d8190,
roughness: 0.7,
metalness: 0.2
})
);
blockerRim.rotation.y = Math.PI / 2;
scene.add(blockerRim);
// ---------------------------------------------------------------------
// Screen and constructed shadow zones
// ---------------------------------------------------------------------
function createScreenTexture() {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = 512;
textureCanvas.height = 512;
const context = textureCanvas.getContext("2d");
context.fillStyle = "#dbe5e9";
context.fillRect(0, 0, 512, 512);
context.strokeStyle = "rgba(60, 90, 105, 0.13)";
context.lineWidth = 1;
for (let p = 0; p <= 512; p += 64) {
context.beginPath();
context.moveTo(p, 0);
context.lineTo(p, 512);
context.stroke();
context.beginPath();
context.moveTo(0, p);
context.lineTo(512, p);
context.stroke();
}
context.strokeStyle = "rgba(60, 90, 105, 0.20)";
context.beginPath();
context.arc(256, 256, 150, 0, Math.PI * 2);
context.stroke();
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const screenAssembly = new THREE.Group();
scene.add(screenAssembly);
const screenBacking = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 10, 10),
new THREE.MeshStandardMaterial({
color: 0x14212c,
roughness: 0.9,
metalness: 0.05
})
);
screenAssembly.add(screenBacking);
const screenFrame = new THREE.LineSegments(
new THREE.EdgesGeometry(screenBacking.geometry),
new THREE.LineBasicMaterial({
color: 0x7892a5,
transparent: true,
opacity: 0.75
})
);
screenAssembly.add(screenFrame);
const screenFace = new THREE.Mesh(
new THREE.PlaneGeometry(9.94, 9.94),
new THREE.MeshBasicMaterial({
map: createScreenTexture()
})
);
screenFace.rotation.y = Math.PI / 2;
screenFace.position.x = 0.065;
screenAssembly.add(screenFace);
const shadowZones = new THREE.Group();
screenAssembly.add(shadowZones);
const penumbraMaterial = new THREE.MeshBasicMaterial({
color: 0x34414c,
transparent: true,
opacity: 0.52,
depthWrite: false,
side: THREE.DoubleSide
});
const umbraMaterial = new THREE.MeshBasicMaterial({
color: 0x050910,
transparent: true,
opacity: 0.96,
depthWrite: false,
side: THREE.DoubleSide
});
const penumbraRing = new THREE.Mesh(
new THREE.RingGeometry(0.001, 1, 48, 1),
penumbraMaterial
);
penumbraRing.rotation.y = Math.PI / 2;
penumbraRing.position.x = 0.070;
penumbraRing.renderOrder = 3;
shadowZones.add(penumbraRing);
const umbraDisk = new THREE.Mesh(
new THREE.CircleGeometry(1, 48),
umbraMaterial
);
umbraDisk.rotation.y = Math.PI / 2;
umbraDisk.position.x = 0.073;
umbraDisk.renderOrder = 4;
shadowZones.add(umbraDisk);
function circleLoopGeometry(radius) {
const points = [];
const segments = 72;
for (let i = 0; i < segments; i++) {
const angle = (i / segments) * Math.PI * 2;
points.push(
new THREE.Vector3(
0,
radius * Math.cos(angle),
radius * Math.sin(angle)
)
);
}
return new THREE.BufferGeometry().setFromPoints(points);
}
const outerBoundary = new THREE.LineLoop(
circleLoopGeometry(1),
new THREE.LineBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.9
})
);
outerBoundary.position.x = 0.077;
outerBoundary.renderOrder = 5;
shadowZones.add(outerBoundary);
const umbraBoundary = new THREE.LineLoop(
circleLoopGeometry(1),
new THREE.LineBasicMaterial({
color: 0xff69c7,
transparent: true,
opacity: 0.9
})
);
umbraBoundary.position.x = 0.078;
umbraBoundary.renderOrder = 6;
shadowZones.add(umbraBoundary);
// ---------------------------------------------------------------------
// Tangent construction rays
// ---------------------------------------------------------------------
const rayGroup = new THREE.Group();
scene.add(rayGroup);
function createRay(color) {
const line = new THREE.Line(
new THREE.BufferGeometry(),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.92,
depthTest: false,
depthWrite: false
})
);
line.renderOrder = 10;
rayGroup.add(line);
return line;
}
const outerTopRay = createRay(0x58dcff);
const outerBottomRay = createRay(0x58dcff);
const innerTopRay = createRay(0xff69c7);
const innerBottomRay = createRay(0xff69c7);
function replaceLinePoints(line, points) {
line.geometry.dispose();
line.geometry = new THREE.BufferGeometry().setFromPoints(points);
}
// Distance dimension line
const distanceLine = new THREE.Line(
new THREE.BufferGeometry(),
new THREE.LineBasicMaterial({
color: 0xa6bdcc,
transparent: true,
opacity: 0.8,
depthTest: false
})
);
distanceLine.renderOrder = 8;
scene.add(distanceLine);
const distanceTicks = new THREE.LineSegments(
new THREE.BufferGeometry(),
new THREE.LineBasicMaterial({
color: 0xa6bdcc,
transparent: true,
opacity: 0.8,
depthTest: false
})
);
distanceTicks.renderOrder = 8;
scene.add(distanceTicks);
// ---------------------------------------------------------------------
// Shadow calculation and geometry updates
// ---------------------------------------------------------------------
function updateSimulation() {
const S = state.sourceDiameter;
const L = state.screenDistance;
const A = SOURCE_TO_BLOCKER;
const B = BLOCKER_DIAMETER;
const sourceRadius = S * 0.5;
const blockerRadius = B * 0.5;
// Similar-triangle construction:
// 1. The blocker projects to a larger diameter on the screen.
// 2. The finite source adds an angular spread to that projection.
const projectedBlockerDiameter = B * ((A + L) / A);
const sourceSpread = S * (L / A);
const umbraDiameter = Math.max(
0,
projectedBlockerDiameter - sourceSpread
);
const outerShadowDiameter =
projectedBlockerDiameter + sourceSpread;
const umbraRadius = umbraDiameter * 0.5;
const outerRadius = outerShadowDiameter * 0.5;
// Update the physical source disk.
sourceBody.scale.set(sourceRadius, 1, sourceRadius);
sourceHalo.scale.set(sourceRadius, 1, sourceRadius);
// Move the screen.
screenAssembly.position.x = L;
shadowZones.visible = state.showZones;
rayGroup.visible = state.showRays;
// Rebuild the penumbra annulus.
penumbraRing.geometry.dispose();
penumbraRing.geometry = new THREE.RingGeometry(
Math.max(umbraRadius, 0.001),
outerRadius,
48,
1
);
// Rebuild the central umbra disk.
umbraDisk.scale.set(umbraRadius, umbraRadius, 1);
umbraDisk.visible = umbraDiameter > 0.001;
// Rebuild circular boundaries.
outerBoundary.geometry.dispose();
outerBoundary.geometry = circleLoopGeometry(outerRadius);
umbraBoundary.geometry.dispose();
umbraBoundary.geometry = circleLoopGeometry(umbraRadius);
umbraBoundary.visible = umbraDiameter > 0.001;
/*
* Outer boundary:
* Lower source edge -> upper blocker edge -> upper outer screen edge.
* Upper source edge -> lower blocker edge -> lower outer screen edge.
*
* Inner boundary:
* Upper source edge -> upper blocker edge -> upper umbra edge.
* Lower source edge -> lower blocker edge -> lower umbra edge.
*/
replaceLinePoints(
outerTopRay,
[
new THREE.Vector3(SOURCE_X, -sourceRadius, 0),
new THREE.Vector3(0, blockerRadius, 0),
new THREE.Vector3(L, outerRadius, 0)
]
);
replaceLinePoints(
outerBottomRay,
[
new THREE.Vector3(SOURCE_X, sourceRadius, 0),
new THREE.Vector3(0, -blockerRadius, 0),
new THREE.Vector3(L, -outerRadius, 0)
]
);
replaceLinePoints(
innerTopRay,
[
new THREE.Vector3(SOURCE_X, sourceRadius, 0),
new THREE.Vector3(0, blockerRadius, 0),
new THREE.Vector3(L, umbraRadius, 0)
]
);
replaceLinePoints(
innerBottomRay,
[
new THREE.Vector3(SOURCE_X, -sourceRadius, 0),
new THREE.Vector3(0, -blockerRadius, 0),
new THREE.Vector3(L, -umbraRadius, 0)
]
);
innerTopRay.visible = umbraDiameter > 0.001;
innerBottomRay.visible = umbraDiameter > 0.001;
// Update the blocker-to-screen dimension line.
replaceLinePoints(
distanceLine,
[
new THREE.Vector3(0, -5.28, 0),
new THREE.Vector3(L, -5.28, 0)
]
);
distanceTicks.geometry.dispose();
distanceTicks.geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, -5.44, 0),
new THREE.Vector3(0, -5.12, 0),
new THREE.Vector3(L, -5.44, 0),
new THREE.Vector3(L, -5.12, 0)
]);
// Update the numerical readouts.
ui.sourceOutput.textContent = `${S.toFixed(2)} units`;
ui.distanceOutput.textContent = `${L.toFixed(2)} units`;
ui.umbraMetric.textContent =
umbraDiameter > 0.001
? `${umbraDiameter.toFixed(2)} units`
: "None";
ui.penumbraMetric.textContent = `${sourceSpread.toFixed(2)} units`;
ui.outerMetric.textContent = `${outerShadowDiameter.toFixed(2)} units`;
if (umbraDiameter > 0.001) {
ui.dynamicNote.textContent =
`The center is fully blocked, forming a ${umbraDiameter.toFixed(2)}-unit ` +
`umbra. Each edge has a geometric penumbra approximately ` +
`${sourceSpread.toFixed(2)} unit wide. Moving the screen farther away ` +
`widens this transition without changing blocker darkness.`;
} else {
ui.dynamicNote.textContent =
`There is no full umbra at this geometry. Different points of the ` +
`large source produce overlapping partial shadows, so the shadow ` +
`disk is penumbra throughout.`;
}
ui.screenLabel.textContent = `SCREEN · L = ${L.toFixed(2)}`;
ui.distanceLabel.textContent = `L = ${L.toFixed(2)}`;
updateCamera();
}
// ---------------------------------------------------------------------
// World-space HTML labels
// ---------------------------------------------------------------------
const sourceAnchor = new THREE.Vector3();
const blockerAnchor = new THREE.Vector3();
const screenAnchor = new THREE.Vector3();
const distanceAnchor = new THREE.Vector3();
function positionWorldLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z >= -1 &&
projected.z <= 1 &&
projected.x >= -1.15 &&
projected.x <= 1.15 &&
projected.y >= -1.15 &&
projected.y <= 1.15;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.transform =
`translate(-50%, -50%) translate(${x}px, ${y}px)`;
}
function updateWorldLabels() {
sourceAnchor.set(
SOURCE_X,
state.sourceDiameter * 0.5 + 0.42,
0
);
blockerAnchor.set(
0,
BLOCKER_DIAMETER * 0.5 + 0.35,
0
);
screenAnchor.set(
state.screenDistance,
5.28,
0
);
distanceAnchor.set(
state.screenDistance * 0.5,
-5.66,
0
);
positionWorldLabel(ui.sourceLabel, sourceAnchor);
positionWorldLabel(ui.blockerLabel, blockerAnchor);
positionWorldLabel(ui.screenLabel, screenAnchor);
positionWorldLabel(ui.distanceLabel, distanceAnchor);
}
// ---------------------------------------------------------------------
// Direct camera controls: orbit, zoom, and reset
// ---------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraAzimuth -= deltaX * 0.006;
cameraPolar = THREE.MathUtils.clamp(
cameraPolar - deltaY * 0.006,
0.38,
1.46
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
canvas.hasPointerCapture(event.pointerId)
) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
12,
30
);
updateCamera();
},
{ passive: false }
);
function resetCamera() {
cameraRadius = 18.5;
cameraAzimuth = 0.72;
cameraPolar = 1.12;
updateCamera();
}
ui.resetCamera.addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
// ---------------------------------------------------------------------
// UI events
// ---------------------------------------------------------------------
ui.sourceInput.addEventListener("input", () => {
state.sourceDiameter = Number(ui.sourceInput.value);
updateSimulation();
});
ui.distanceInput.addEventListener("input", () => {
state.screenDistance = Number(ui.distanceInput.value);
updateSimulation();
});
ui.showRays.addEventListener("change", () => {
state.showRays = ui.showRays.checked;
updateSimulation();
});
ui.showZones.addEventListener("change", () => {
state.showZones = ui.showZones.checked;
updateSimulation();
});
// ---------------------------------------------------------------------
// Initialize and render
// ---------------------------------------------------------------------
resize();
updateSimulation();
function animate(time) {
requestAnimationFrame(animate);
sourceHaloMaterial.opacity =
0.105 + 0.025 * (0.5 + 0.5 * Math.sin(time * 0.0022));
camera.updateMatrixWorld();
updateWorldLabels();
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```