Prompt specification
Build or customize the Three.js 3D scene "Bootstrap sample-with-replacement tray" 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: Bootstrap sample-with-replacement tray
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/bootstrap-sample-with-replacement-tray-x1773
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a low-poly bootstrap sampling tray. Place six labeled observation tokens in a source rack and six empty positions in a resample tray. Drawing an observation copies its label into the tray while the source token remains available, so repeated labels can appear in one resample. Show one completed resample beside the original dataset and make their equal sizes clear. A draw button advances one selection at a time; a new-sample button clears only the resample tray. Use a small fictional numeric dataset with easily distinguished tokens, and keep the mechanics of sampling with replacement more prominent than statistical summaries.
Working Three.js Starter (bootstrap-sample-with-replacement-tray-x1773):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Bootstrap Bench — Sampling with Replacement</title>
<style>
:root {
--ink: #20342f;
--muted: #68736d;
--paper: #f4efe5;
--card: #fffdf8;
--line: #ded8ca;
--green: #245b50;
--green-dark: #183f38;
--coral: #e66f55;
--gold: #e4b85b;
--blue: #4e788c;
--shadow: 0 18px 50px rgba(54, 65, 55, 0.12);
}
* { box-sizing: border-box; }
body {
margin: 0;
min-height: 100vh;
color: var(--ink);
background:
radial-gradient(circle at 10% 5%, rgba(228,184,91,.18), transparent 28rem),
radial-gradient(circle at 92% 12%, rgba(78,120,140,.13), transparent 30rem),
var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
.page {
width: min(1380px, calc(100% - 32px));
margin: 0 auto;
padding: 34px 0 48px;
}
header {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 28px;
margin-bottom: 24px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--green);
font-size: 12px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 5vw, 66px);
font-weight: 500;
line-height: .98;
letter-spacing: -.045em;
}
.intro {
max-width: 580px;
margin: 14px 0 0;
color: var(--muted);
font-size: 17px;
line-height: 1.55;
}
.header-badge {
flex: 0 0 auto;
padding: 13px 17px;
border: 1px solid rgba(36,91,80,.22);
border-radius: 999px;
color: var(--green);
background: rgba(255,255,255,.48);
font-size: 13px;
font-weight: 750;
}
.workspace {
display: grid;
grid-template-columns: minmax(0, 1fr) 340px;
gap: 18px;
align-items: stretch;
}
.scene-card,
.control-card,
.dataset-card {
border: 1px solid rgba(81,91,77,.16);
background: var(--card);
box-shadow: var(--shadow);
}
.scene-card {
position: relative;
min-width: 0;
min-height: 640px;
overflow: hidden;
border-radius: 26px;
background: #eee8dc;
}
#scene {
position: absolute;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.scene-top {
position: absolute;
z-index: 2;
top: 18px;
left: 18px;
right: 18px;
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
pointer-events: none;
}
.scene-label,
.scene-count {
padding: 9px 12px;
border: 1px solid rgba(47,61,55,.12);
border-radius: 12px;
background: rgba(255,253,248,.83);
box-shadow: 0 8px 22px rgba(40,48,40,.08);
backdrop-filter: blur(8px);
font-size: 11px;
font-weight: 850;
letter-spacing: .1em;
text-transform: uppercase;
}
.scene-label { color: var(--green); }
.scene-count { color: #735f3a; }
.scene-bottom {
position: absolute;
z-index: 2;
right: 18px;
bottom: 16px;
left: 18px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
pointer-events: none;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px;
padding: 9px 11px;
border: 1px solid rgba(47,61,55,.12);
border-radius: 12px;
background: rgba(255,253,248,.84);
backdrop-filter: blur(8px);
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.legend i {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 3px;
}
.legend .source { background: #e29a59; }
.legend .copy { background: #e66f55; }
.legend .slot { border: 2px solid #748b92; background: #d9e0dc; }
.camera-help {
padding: 9px 11px;
border-radius: 12px;
background: rgba(32,52,47,.82);
color: #f8f3e8;
font-size: 11px;
line-height: 1.35;
text-align: right;
}
.control-card {
display: flex;
flex-direction: column;
padding: 22px;
border-radius: 26px;
}
.control-card h2,
.comparison h2,
.dataset-card h3 {
margin: 0;
}
.control-card h2 {
font-family: Georgia, "Times New Roman", serif;
font-size: 27px;
font-weight: 500;
letter-spacing: -.025em;
}
.control-sub {
margin: 7px 0 18px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.progress-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
color: var(--muted);
font-size: 12px;
font-weight: 750;
}
.progress-row strong {
color: var(--ink);
font-size: 14px;
}
.pips {
display: grid;
grid-template-columns: repeat(6, 1fr);
gap: 7px;
margin-bottom: 18px;
}
.pip {
height: 9px;
border-radius: 999px;
background: #e5e2d9;
transition: background .25s, transform .25s;
}
.pip.filled {
background: var(--coral);
transform: scaleY(1.25);
}
.status {
min-height: 58px;
margin-bottom: 16px;
padding: 12px 13px;
border-left: 4px solid var(--gold);
border-radius: 8px 12px 12px 8px;
background: #f5f0e4;
color: #5d625a;
font-size: 13px;
line-height: 1.45;
}
.status.complete {
border-left-color: var(--green);
background: #edf3ed;
}
.button-stack {
display: grid;
gap: 10px;
}
.primary,
.secondary {
width: 100%;
min-height: 49px;
padding: 12px 16px;
border-radius: 13px;
cursor: pointer;
font-weight: 800;
transition: transform .15s, box-shadow .15s, opacity .15s, background .15s;
}
.primary {
border: 1px solid var(--green);
background: var(--green);
color: white;
box-shadow: 0 9px 18px rgba(36,91,80,.18);
}
.primary:hover:not(:disabled) {
transform: translateY(-1px);
background: var(--green-dark);
box-shadow: 0 12px 24px rgba(36,91,80,.24);
}
.secondary {
border: 1px solid #d4cec0;
background: #fffdf8;
color: var(--ink);
}
.secondary:hover:not(:disabled) {
transform: translateY(-1px);
background: #f7f2e8;
}
button:disabled {
cursor: not-allowed;
opacity: .44;
box-shadow: none;
}
.button-note {
margin: 7px 0 0;
color: #858b84;
font-size: 11px;
line-height: 1.4;
text-align: center;
}
.rule {
height: 1px;
margin: 21px 0 18px;
background: var(--line);
}
.choose-title {
margin: 0 0 11px;
font-size: 12px;
font-weight: 850;
letter-spacing: .08em;
text-transform: uppercase;
}
.source-buttons {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.source-button {
display: flex;
align-items: center;
justify-content: center;
gap: 7px;
min-height: 42px;
padding: 8px;
border: 1px solid #ded8cb;
border-radius: 11px;
background: #fffdf8;
color: var(--ink);
cursor: pointer;
transition: transform .15s, border-color .15s, box-shadow .15s;
}
.source-button:hover:not(:disabled) {
transform: translateY(-1px);
border-color: var(--button-color);
box-shadow: 0 5px 12px rgba(48,56,48,.09);
}
.source-button .swatch {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--button-color);
}
.source-button strong { font-size: 13px; }
.source-button span { color: var(--muted); font-size: 12px; }
.replacement-note {
margin-top: auto;
padding: 15px;
border-radius: 14px;
background: #f3eee3;
color: #5d655e;
font-size: 12px;
line-height: 1.55;
}
.replacement-note strong {
display: block;
margin-bottom: 3px;
color: var(--ink);
font-size: 13px;
}
.comparison {
margin-top: 30px;
}
.comparison-heading {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 24px;
margin-bottom: 15px;
}
.comparison h2 {
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3.5vw, 40px);
font-weight: 500;
letter-spacing: -.035em;
}
.comparison-heading p {
max-width: 540px;
margin: 0;
color: var(--muted);
font-size: 14px;
line-height: 1.5;
text-align: right;
}
.dataset-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
}
.dataset-card {
overflow: hidden;
border-radius: 20px;
}
.dataset-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 16px 18px;
border-bottom: 1px solid var(--line);
background: #faf7ef;
}
.dataset-header h3 {
font-size: 15px;
letter-spacing: -.01em;
}
.sample-size {
flex: 0 0 auto;
padding: 6px 10px;
border-radius: 999px;
background: #e8efe8;
color: var(--green);
font-size: 12px;
font-weight: 850;
}
.chip-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
padding: 18px;
}
.token-chip {
display: flex;
align-items: center;
justify-content: center;
gap: 9px;
min-height: 55px;
padding: 10px;
border: 1px solid rgba(42,55,47,.12);
border-radius: 13px;
background: var(--chip-bg);
color: #25332d;
}
.token-chip .swatch {
width: 13px;
height: 13px;
flex: 0 0 auto;
border-radius: 4px;
background: var(--chip-color);
box-shadow: inset 0 0 0 1px rgba(0,0,0,.09);
}
.token-chip strong {
font-size: 16px;
}
.token-chip span {
color: #58625c;
font-size: 14px;
font-weight: 650;
}
.dataset-foot {
padding: 0 18px 17px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.size-callout {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
margin-top: 15px;
padding: 16px 19px;
border: 1px solid rgba(36,91,80,.18);
border-radius: 16px;
background: rgba(237,243,237,.74);
color: #4f5e55;
font-size: 14px;
}
.size-callout strong {
color: var(--green);
white-space: nowrap;
}
@media (max-width: 980px) {
.workspace { grid-template-columns: 1fr; }
.control-card { min-height: auto; }
.replacement-note { margin-top: 20px; }
.source-buttons { grid-template-columns: repeat(6, 1fr); }
}
@media (max-width: 700px) {
.page {
width: min(100% - 20px, 1380px);
padding-top: 22px;
}
header {
align-items: flex-start;
flex-direction: column;
gap: 14px;
}
.header-badge { display: none; }
.scene-card { min-height: 560px; border-radius: 20px; }
.scene-bottom { align-items: stretch; flex-direction: column; }
.camera-help { text-align: left; }
.source-buttons { grid-template-columns: repeat(3, 1fr); }
.dataset-grid { grid-template-columns: 1fr; }
.comparison-heading { align-items: flex-start; flex-direction: column; }
.comparison-heading p { text-align: left; }
.chip-grid { grid-template-columns: repeat(2, 1fr); }
.size-callout { align-items: flex-start; flex-direction: column; }
}
</style>
</head>
<body>
<main class="page">
<header>
<div>
<div class="eyebrow">Sampling, made tangible</div>
<h1>Bootstrap bench</h1>
<p class="intro">
Draw observations from a six-item source rack. Every draw copies a label,
so the same observation can appear again while the original stays in place.
</p>
</div>
<div class="header-badge">With replacement · equal sample sizes</div>
</header>
<section class="workspace">
<div class="scene-card" id="scene-card">
<div id="scene" aria-label="Interactive three-dimensional bootstrap sampling tray"></div>
<div class="scene-top">
<div class="scene-label">Live sampling tray</div>
<div class="scene-count" id="scene-count">0 of 6 positions filled</div>
</div>
<div class="scene-bottom">
<div class="legend" aria-hidden="true">
<span><i class="source"></i> Source token</span>
<span><i class="copy"></i> Copied label</span>
<span><i class="slot"></i> Empty position</span>
</div>
<div class="camera-help">
Drag to orbit · wheel to zoom<br />
Click a source token to draw it
</div>
</div>
</div>
<aside class="control-card">
<h2>Sampling controls</h2>
<p class="control-sub">
Each draw makes one copy and advances the live tray by exactly one position.
</p>
<div class="progress-row">
<span>Live resample</span>
<strong id="progress-number">0 / 6</strong>
</div>
<div class="pips" id="pips" aria-hidden="true"></div>
<div class="status" id="status" aria-live="polite">
The live tray is empty. Make six draws to complete this resample.
</div>
<div class="button-stack">
<button class="primary" id="draw-button" type="button">Draw one observation</button>
<button class="secondary" id="new-button" type="button" disabled>New sample</button>
<p class="button-note">“New sample” clears only the live resample tray.</p>
</div>
<div class="rule"></div>
<h3 class="choose-title">Choose an exact source token</h3>
<div class="source-buttons" id="source-buttons"></div>
<div class="replacement-note">
<strong>Why can a label repeat?</strong>
Drawing copies an observation rather than moving it. The source rack always
retains all six original observations.
</div>
</aside>
</section>
<section class="comparison">
<div class="comparison-heading">
<h2>Replacement, side by side</h2>
<p>
A complete example of sampling with replacement. The order changes, the
sample size does not, and one source label may be copied more than once.
</p>
</div>
<div class="dataset-grid">
<article class="dataset-card">
<div class="dataset-header">
<h3>Original dataset</h3>
<span class="sample-size">n = 6</span>
</div>
<div class="chip-grid" id="original-chips"></div>
<div class="dataset-foot">The six observations that remain in the source rack.</div>
</article>
<article class="dataset-card">
<div class="dataset-header">
<h3>One completed resample</h3>
<span class="sample-size">n = 6</span>
</div>
<div class="chip-grid" id="resample-chips"></div>
<div class="dataset-foot">
A is copied three times. Its original token is still available in the source.
</div>
</article>
</div>
<div class="size-callout">
<span>Both samples contain exactly six observations, even though some labels repeat.</span>
<strong>6 observations = 6 observations</strong>
</div>
</section>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const DATA = [
{ id: "A", value: 2, color: 0xE99B59 },
{ id: "B", value: 5, color: 0x4AA59D },
{ id: "C", value: 8, color: 0xE3C85B },
{ id: "D", value: 11, color: 0xE66F59 },
{ id: "E", value: 14, color: 0x6F8FC8 },
{ id: "F", value: 17, color: 0x9B78B4 }
];
const EXAMPLE_RESAMPLE = [0, 2, 0, 5, 1, 0];
const sceneHost = document.querySelector("#scene");
const drawButton = document.querySelector("#draw-button");
const newButton = document.querySelector("#new-button");
const statusElement = document.querySelector("#status");
const progressNumber = document.querySelector("#progress-number");
const sceneCount = document.querySelector("#scene-count");
const pipsElement = document.querySelector("#pips");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xEEE8DC);
scene.fog = new THREE.Fog(0xEEE8DC, 16, 28);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
sceneHost.appendChild(renderer.domElement);
renderer.domElement.setAttribute("aria-label", "Three-dimensional sampling scene");
renderer.domElement.tabIndex = 0;
const camera = new THREE.PerspectiveCamera(39, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.2, 0.45);
let cameraYaw = 0;
let cameraPitch = 0.69;
let cameraRadius = 13.2;
function updateCamera() {
const horizontal = cameraRadius * Math.cos(cameraPitch);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraYaw),
cameraTarget.y + cameraRadius * Math.sin(cameraPitch),
cameraTarget.z + horizontal * Math.cos(cameraYaw)
);
camera.lookAt(cameraTarget);
}
function resizeScene() {
const width = sceneHost.clientWidth;
const height = sceneHost.clientHeight;
if (!width || !height) return;
camera.aspect = width / height;
camera.fov = camera.aspect < 1 ? 52 : 39;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
new ResizeObserver(resizeScene).observe(sceneHost);
resizeScene();
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xFFFDF4, 0x58675E, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xFFF1D8, 3.2);
sun.position.set(-5, 9, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -9;
sun.shadow.camera.right = 9;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xC8E4F0, 1.15);
fill.position.set(7, 5, -4);
scene.add(fill);
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeTextTexture(text, options = {}) {
const width = options.width || 1024;
const height = options.height || 256;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
if (options.background) {
ctx.fillStyle = options.background;
roundedRect(ctx, 4, 4, width - 8, height - 8, options.radius || 40);
ctx.fill();
}
const entries = (Array.isArray(text) ? text : [text]).map((entry) =>
typeof entry === "string"
? { text: entry }
: entry
);
let totalHeight = 0;
for (const entry of entries) {
totalHeight += entry.size || options.size || 64;
}
let y = height / 2 - totalHeight / 2;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
for (const entry of entries) {
const size = entry.size || options.size || 64;
ctx.font = `${entry.weight || options.weight || 800} ${size}px ${options.font || "Arial, sans-serif"}`;
ctx.fillStyle = entry.color || options.color || "#FFFFFF";
y += size / 2;
ctx.fillText(entry.text, width / 2, y);
y += size / 2 + (entry.gap || 4);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.needsUpdate = true;
return texture;
}
function makeTokenTexture(id, value) {
const canvas = document.createElement("canvas");
canvas.width = 320;
canvas.height = 240;
const ctx = canvas.getContext("2d");
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#20342F";
ctx.font = "800 54px Arial, sans-serif";
ctx.fillText(id, 160, 66);
ctx.fillStyle = "#20342F";
ctx.font = "900 104px Arial, sans-serif";
ctx.fillText(String(value), 160, 158);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
return texture;
}
function makeBillboard(entries, width, height, position) {
const texture = makeTextTexture(entries, {
width: 1024,
height: 256,
background: "rgba(31, 67, 59, 0.94)",
radius: 48
});
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.position.copy(position);
sprite.scale.set(width, height, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
function makeBox(width, height, depth, color, x, y, z, castShadow = true) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// Tabletop.
makeBox(13.4, 0.28, 8.4, 0xD9CBB2, 0, -0.18, 0.5);
makeBox(13.0, 0.06, 8.0, 0xE6DBC6, 0, -0.01, 0.5, false);
function buildRack(centerX, isSample) {
const centerZ = 0.45;
const railColor = isSample ? 0x577C89 : 0x42685C;
const insetColor = isSample ? 0xDCE5E2 : 0xD5DFD7;
makeBox(3.45, 0.18, 4.15, railColor, centerX, 0.08, centerZ);
makeBox(3.22, 0.08, 3.92, insetColor, centerX, 0.20, centerZ);
// Low-poly perimeter rails.
makeBox(3.45, 0.18, 0.10, railColor, centerX, 0.29, centerZ - 2.02);
makeBox(3.45, 0.18, 0.10, railColor, centerX, 0.29, centerZ + 2.02);
makeBox(0.10, 0.18, 4.05, railColor, centerX - 1.68, 0.29, centerZ);
makeBox(0.10, 0.18, 4.05, railColor, centerX + 1.68, 0.29, centerZ);
// Four simple corner fasteners.
for (const dx of [-1.52, 1.52]) {
for (const dz of [-1.85, 1.85]) {
const screw = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.025, 8),
new THREE.MeshStandardMaterial({
color: isSample ? 0xD4E4E7 : 0xDCE8DD,
roughness: 0.45,
metalness: 0.35
})
);
screw.position.set(centerX + dx, 0.39, centerZ + dz);
scene.add(screw);
}
}
}
buildRack(-2.25, false);
buildRack(2.25, true);
makeBillboard(
[
{ text: "ORIGINAL DATASET", size: 62, color: "#FFFFFF" },
{ text: "6 SOURCE OBSERVATIONS", size: 34, color: "#CDE2D7" }
],
2.65,
0.66,
new THREE.Vector3(-2.25, 1.08, -1.25)
);
makeBillboard(
[
{ text: "RESAMPLE TRAY", size: 62, color: "#FFFFFF" },
{ text: "6 DRAW POSITIONS", size: 34, color: "#D5E7EC" }
],
2.65,
0.66,
new THREE.Vector3(2.25, 1.08, -1.25)
);
// A chunky arrow between the racks.
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0xE1B454,
roughness: 0.68,
flatShading: true
});
const arrowShaft = new THREE.Mesh(
new THREE.BoxGeometry(0.85, 0.09, 0.16),
arrowMaterial
);
arrowShaft.position.set(-0.05, 0.35, 0.55);
arrowShaft.castShadow = true;
scene.add(arrowShaft);
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.25, 0.48, 4),
arrowMaterial
);
arrowHead.rotation.z = -Math.PI / 2;
arrowHead.position.set(0.58, 0.35, 0.55);
arrowHead.castShadow = true;
scene.add(arrowHead);
makeBillboard(
[
{ text: "COPY", size: 58, color: "#FFFFFF" },
{ text: "SOURCE STAYS", size: 31, color: "#F1D695" }
],
1.75,
0.58,
new THREE.Vector3(0, 0.95, 0.55)
);
const sourcePositions = [];
const slotPositions = [];
const sourceGroups = [];
const copiedGroups = [];
const pickables = [];
const sourceMaterials = [];
function buildToken(index) {
const group = new THREE.Group();
const item = DATA[index];
const bodyMaterial = new THREE.MeshStandardMaterial({
color: item.color,
roughness: 0.56,
metalness: 0.04,
flatShading: true,
emissive: 0xFFFFFF,
emissiveIntensity: 0
});
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.46, 0.43, 0.28, 6, 1, false),
bodyMaterial
);
body.position.y = 0.14;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const edge = new THREE.Mesh(
new THREE.TorusGeometry(0.39, 0.027, 4, 6),
new THREE.MeshBasicMaterial({
color: 0xFFFFFF,
transparent: true,
opacity: 0.62
})
);
edge.rotation.x = Math.PI / 2;
edge.position.y = 0.286;
group.add(edge);
const labelTexture = makeTokenTexture(item.id, item.value);
const label = new THREE.Mesh(
new THREE.PlaneGeometry(0.72, 0.50),
new THREE.MeshBasicMaterial({
map: labelTexture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
label.rotation.x = -Math.PI / 2;
label.position.y = 0.298;
group.add(label);
return { group, body, bodyMaterial, labelTexture };
}
const sourceX = [-3.05, -1.45];
const rowZ = [-0.45, 0.55, 1.55];
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 2; col++) {
const index = row * 2 + col;
const position = new THREE.Vector3(sourceX[col], 0.30, rowZ[row]);
sourcePositions.push(position);
const token = buildToken(index);
token.group.position.copy(position);
token.body.userData.sourceIndex = index;
token.group.userData.sourceIndex = index;
scene.add(token.group);
sourceGroups.push(token.group);
sourceMaterials.push(token.bodyMaterial);
pickables.push(token.body);
}
}
const slotX = [1.45, 3.05];
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 2; col++) {
const position = new THREE.Vector3(slotX[col], 0.26, rowZ[row]);
slotPositions.push(position);
const recess = new THREE.Mesh(
new THREE.CylinderGeometry(0.51, 0.51, 0.06, 6),
new THREE.MeshStandardMaterial({
color: 0xAEBBB6,
roughness: 0.92,
flatShading: true
})
);
recess.position.set(position.x, 0.235, position.z);
recess.receiveShadow = true;
scene.add(recess);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.49, 0.035, 4, 6),
new THREE.MeshStandardMaterial({
color: 0x6C858A,
roughness: 0.62,
metalness: 0.08,
flatShading: true
})
);
ring.rotation.x = Math.PI / 2;
ring.position.set(position.x, 0.272, position.z);
ring.castShadow = true;
scene.add(ring);
const numberTexture = makeTextTexture(String(slotPositions.length), {
width: 256,
height: 256,
size: 100,
color: "#546A6B",
weight: 800
});
const numberLabel = new THREE.Mesh(
new THREE.PlaneGeometry(0.30, 0.24),
new THREE.MeshBasicMaterial({
map: numberTexture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
numberLabel.rotation.x = -Math.PI / 2;
numberLabel.position.set(position.x, 0.265, position.z + 0.63);
scene.add(numberLabel);
}
}
// Small decorative blocks make the tabletop read as a low-poly workbench.
const decorativeColors = [0xC8B58E, 0xB8C3B6, 0xC6B3B0];
for (let i = 0; i < 3; i++) {
makeBox(
0.38,
0.22 + i * 0.08,
0.48,
decorativeColors[i],
-5.65,
0.1 + i * 0.04,
-1.45 + i * 0.85
);
}
let draws = [];
let animating = false;
let animation = null;
let hoveredSource = -1;
function hexToRgba(hex, alpha) {
const r = (hex >> 16) & 255;
const g = (hex >> 8) & 255;
const b = hex & 255;
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
}
function tokenChip(index) {
const item = DATA[index];
return `
<div class="token-chip"
style="--chip-color:#${item.color.toString(16).padStart(6, "0")};
--chip-bg:${hexToRgba(item.color, 0.20)}">
<i class="swatch"></i>
<strong>${item.id}</strong>
<span>${item.value}</span>
</div>
`;
}
document.querySelector("#original-chips").innerHTML =
DATA.map((_, index) => tokenChip(index)).join("");
document.querySelector("#resample-chips").innerHTML =
EXAMPLE_RESAMPLE.map(index => tokenChip(index)).join("");
const sourceButtonsElement = document.querySelector("#source-buttons");
sourceButtonsElement.innerHTML = DATA.map((item, index) => `
<button
class="source-button"
type="button"
data-index="${index}"
style="--button-color:#${item.color.toString(16).padStart(6, "0")}"
aria-label="Draw observation ${item.id}, value ${item.value}">
<i class="swatch"></i>
<strong>${item.id}</strong>
<span>${item.value}</span>
</button>
`).join("");
sourceButtonsElement.addEventListener("click", (event) => {
const button = event.target.closest("button[data-index]");
if (!button) return;
drawSource(Number(button.dataset.index));
});
function makePips() {
pipsElement.innerHTML = "";
for (let i = 0; i < 6; i++) {
const pip = document.createElement("span");
pip.className = "pip";
pipsElement.appendChild(pip);
}
}
function updateHUD() {
const count = draws.length;
progressNumber.textContent = `${count} / 6`;
sceneCount.textContent = `${count} of 6 positions filled`;
[...pipsElement.children].forEach((pip, index) => {
pip.classList.toggle("filled", index < count);
});
const complete = count === 6;
drawButton.disabled = complete || animating;
newButton.disabled = count === 0 || animating;
[...sourceButtonsElement.children].forEach((button) => {
button.disabled = complete || animating;
});
if (complete) {
statusElement.classList.add("complete");
statusElement.textContent =
"Resample complete: six copied observations. The original dataset is unchanged.";
} else if (count > 0) {
const latest = DATA[draws[count - 1]];
statusElement.classList.remove("complete");
statusElement.textContent =
`${latest.id} · ${latest.value} copied into position ${count}. ` +
`Its source token remains available.`;
} else {
statusElement.classList.remove("complete");
statusElement.textContent =
"The live tray is empty. Make six draws to complete this resample.";
}
}
makePips();
updateHUD();
function disposeGroup(group) {
group.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
materials.forEach((material) => {
if (material.map) material.map.dispose();
material.dispose();
});
}
});
}
function drawSource(index) {
if (animating || draws.length >= 6) return;
animating = true;
updateHUD();
const slotIndex = draws.length;
const target = slotPositions[slotIndex].clone();
const token = buildToken(index);
const start = sourcePositions[index].clone();
start.y += 0.10;
token.group.position.copy(start);
token.group.scale.setScalar(0.02);
scene.add(token.group);
copiedGroups.push(token.group);
draws.push(index);
animation = {
group: token.group,
start,
target,
started: performance.now(),
duration: 720
};
updateHUD();
}
drawButton.addEventListener("click", () => {
drawSource(Math.floor(Math.random() * DATA.length));
});
newButton.addEventListener("click", () => {
if (animating) return;
copiedGroups.forEach(group => {
scene.remove(group);
disposeGroup(group);
});
copiedGroups.length = 0;
draws = [];
updateHUD();
});
// Direct camera controls, implemented without Three.js addons.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerMoved = false;
let downX = 0;
let downY = 0;
function setPointerFromEvent(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickSource(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(pickables, false);
return intersections.length ? intersections[0].object.userData.sourceIndex : -1;
}
renderer.domElement.addEventListener("pointerdown", event => {
pointerDown = true;
pointerMoved = false;
downX = event.clientX;
downY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
if (pointerDown) {
const dx = event.clientX - downX;
const dy = event.clientY - downY;
if (Math.abs(dx) + Math.abs(dy) > 3) pointerMoved = true;
cameraYaw = THREE.MathUtils.clamp(
cameraYaw - dx * 0.005,
-0.65,
0.65
);
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.0045,
0.38,
1.14
);
downX = event.clientX;
downY = event.clientY;
updateCamera();
return;
}
const hit = pickSource(event);
hoveredSource = hit;
renderer.domElement.style.cursor = hit >= 0 ? "pointer" : "grab";
});
renderer.domElement.addEventListener("pointerup", event => {
const wasClick = !pointerMoved;
pointerDown = false;
renderer.domElement.style.cursor = "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (wasClick) {
const hit = pickSource(event);
if (hit >= 0) drawSource(hit);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
pointerMoved = false;
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!pointerDown) hoveredSource = -1;
});
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.008,
8.6,
17.5
);
updateCamera();
},
{ passive: false }
);
function animate(now) {
requestAnimationFrame(animate);
if (animation) {
const t = Math.min((now - animation.started) / animation.duration, 1);
const eased = 1 - Math.pow(1 - t, 3);
animation.group.position.lerpVectors(
animation.start,
animation.target,
eased
);
animation.group.position.y += Math.sin(Math.PI * t) * 1.18;
animation.group.rotation.y = (1 - eased) * Math.PI * 2;
animation.group.scale.setScalar(Math.min(1, t * 2.2));
if (t >= 1) {
animation.group.position.copy(animation.target);
animation.group.rotation.set(0, 0, 0);
animation.group.scale.setScalar(1);
animation = null;
animating = false;
updateHUD();
}
}
sourceGroups.forEach((group, index) => {
const targetScale = hoveredSource === index ? 1.075 : 1;
const nextScale = THREE.MathUtils.lerp(
group.scale.x,
targetScale,
0.14
);
group.scale.setScalar(nextScale);
sourceMaterials[index].emissiveIntensity =
hoveredSource === index ? 0.12 : 0;
});
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```