Prompt specification
Build or customize the Three.js 3D scene "Draw Without Replacement Counter" 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: Draw Without Replacement Counter
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/draw-without-replacement-counter-x3530
Scene Description Prompt:
Animate cards drawn one at a time while updating remaining counts. Calculate the next-draw probability from the actual remaining deck rather than the original composition. Build this with Three.js from cdnjs as a voxel scene in one self-contained HTML file.
Working Three.js Starter (draw-without-replacement-counter-x3530):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Deck — Live Probability</title>
<style>
:root {
color-scheme: dark;
--bg: #07111d;
--panel: rgba(10, 22, 36, 0.82);
--panel-solid: #0b1929;
--line: rgba(157, 205, 235, 0.14);
--text: #edf7ff;
--muted: #8da8bd;
--cyan: #73e7ff;
--green: #70e1a1;
}
* {
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;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#scene canvas:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.ui > * {
pointer-events: auto;
}
.topbar {
position: absolute;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: center;
justify-content: space-between;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
position: relative;
width: 34px;
height: 34px;
transform: rotate(-8deg);
}
.brand-mark span {
position: absolute;
width: 15px;
height: 15px;
background: var(--cyan);
box-shadow: 0 0 22px rgba(115, 231, 255, 0.35);
}
.brand-mark span:nth-child(1) {
left: 0;
top: 0;
}
.brand-mark span:nth-child(2) {
right: 0;
top: 0;
background: #4778ff;
}
.brand-mark span:nth-child(3) {
left: 9px;
bottom: 0;
background: #b4f1ff;
}
.eyebrow {
margin: 0 0 3px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 19px;
line-height: 1;
letter-spacing: 0.03em;
}
.live-badge {
display: flex;
align-items: center;
gap: 8px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(8, 20, 34, 0.72);
color: #b9cedd;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(14px);
}
.live-badge::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 12px var(--green);
content: "";
}
.panel {
position: absolute;
top: 88px;
bottom: 76px;
width: 310px;
padding: 18px;
overflow: auto;
border: 1px solid var(--line);
border-radius: 18px;
background:
linear-gradient(145deg, rgba(255, 255, 255, 0.025), transparent 42%),
var(--panel);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.3),
inset 0 1px rgba(255, 255, 255, 0.025);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: rgba(115, 231, 255, 0.25) transparent;
}
#probabilityPanel {
left: 24px;
}
#drawPanel {
right: 24px;
display: flex;
flex-direction: column;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 15px;
}
.panel h2 {
margin: 0;
font-size: 15px;
letter-spacing: 0.02em;
}
.subtle {
margin: 6px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.remaining-number {
min-width: 61px;
color: var(--cyan);
font-size: 29px;
font-weight: 850;
line-height: 1;
text-align: right;
letter-spacing: -0.05em;
}
.remaining-label {
margin-top: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.13em;
text-align: right;
text-transform: uppercase;
}
.formula {
margin: 15px 0 18px;
padding: 11px 12px;
border: 1px solid rgba(115, 231, 255, 0.13);
border-radius: 10px;
background: rgba(115, 231, 255, 0.045);
color: #9ebdce;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
line-height: 1.55;
}
.formula strong {
color: var(--cyan);
}
.prob-list {
display: grid;
gap: 9px;
}
.prob-row {
--accent: var(--cyan);
padding: 11px 12px;
border: 1px solid rgba(255, 255, 255, 0.055);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.prob-row:hover {
transform: translateX(2px);
border-color: color-mix(in srgb, var(--accent) 35%, transparent);
background: rgba(255, 255, 255, 0.04);
}
.prob-top {
display: grid;
grid-template-columns: 10px minmax(0, 1fr) auto;
align-items: center;
gap: 9px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--accent);
box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 55%, transparent);
}
.prob-name {
font-size: 11px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.prob-count {
margin-left: 5px;
color: var(--muted);
font-size: 10px;
font-weight: 600;
}
.prob-percent {
color: var(--accent);
font-size: 12px;
font-weight: 850;
font-variant-numeric: tabular-nums;
}
.bar {
height: 4px;
margin-top: 9px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.065);
}
.bar i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--accent);
box-shadow: 0 0 9px var(--accent);
transition: width 450ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.deck-status {
margin-top: 17px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.status-row {
display: flex;
justify-content: space-between;
gap: 12px;
margin: 8px 0;
color: var(--muted);
font-size: 10px;
}
.status-row strong {
color: #c6dbe9;
font-weight: 700;
}
.mini-label {
margin: 0 0 8px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.card-stage {
position: relative;
min-height: 173px;
padding: 16px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 14px;
background:
radial-gradient(
circle at 50% 44%,
color-mix(in srgb, var(--card-accent, #73e7ff) 14%, transparent),
transparent 60%
),
rgba(0, 0, 0, 0.15);
}
.draw-counter {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.card-art {
position: absolute;
top: 50%;
left: 50%;
display: grid;
grid-template-columns: repeat(5, 17px);
grid-auto-rows: 17px;
gap: 3px;
transform: translate(-50%, -47%);
}
.art-cell {
width: 17px;
height: 17px;
border-radius: 2px;
background: transparent;
}
.art-cell.on {
background: var(--card-accent);
box-shadow: 0 0 8px color-mix(in srgb, var(--card-accent) 25%, transparent);
}
.art-cell.on.alt {
background: var(--card-accent-alt, var(--card-accent));
opacity: 0.72;
}
.card-id {
position: absolute;
right: 12px;
bottom: 10px;
color: rgba(200, 224, 237, 0.48);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
}
.card-info {
margin: 15px 0 0;
}
.type-pill {
display: inline-block;
margin-bottom: 8px;
padding: 5px 8px;
border: 1px solid color-mix(in srgb, var(--card-accent, #73e7ff) 40%, transparent);
border-radius: 999px;
background: color-mix(in srgb, var(--card-accent, #73e7ff) 10%, transparent);
color: var(--card-accent, var(--cyan));
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#cardName {
margin: 0;
font-size: 22px;
letter-spacing: -0.035em;
}
#cardDescription {
min-height: 34px;
margin: 7px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.controls {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-top: 17px;
}
.button {
min-height: 42px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.045);
color: var(--text);
cursor: pointer;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.025em;
transition:
transform 140ms ease,
border-color 140ms ease,
background 140ms ease,
opacity 140ms ease;
}
.button:hover:not(:disabled) {
transform: translateY(-1px);
border-color: rgba(115, 231, 255, 0.35);
background: rgba(115, 231, 255, 0.08);
}
.button:active:not(:disabled) {
transform: translateY(0);
}
.button.primary {
border-color: transparent;
background: var(--cyan);
color: #062033;
box-shadow: 0 9px 26px rgba(70, 202, 239, 0.17);
}
.button.primary:hover:not(:disabled) {
background: #a4f0ff;
}
.button:disabled {
cursor: not-allowed;
opacity: 0.4;
}
.button.auto-active {
border-color: rgba(112, 225, 161, 0.55);
background: rgba(112, 225, 161, 0.13);
color: #9af2bd;
}
.secondary-controls {
display: flex;
gap: 8px;
margin-top: 8px;
}
.secondary-controls .button {
flex: 1;
min-height: 36px;
font-size: 10px;
}
.history-section {
margin-top: 18px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.history {
display: flex;
flex-wrap: wrap;
gap: 6px;
min-height: 27px;
}
.history-chip {
display: flex;
align-items: center;
gap: 6px;
padding: 6px 8px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(255, 255, 255, 0.025);
color: #afc6d7;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.history-chip i {
width: 6px;
height: 6px;
border-radius: 1px;
background: var(--chip-color);
}
.history-empty {
color: #6f8798;
font-size: 10px;
font-style: italic;
}
.bottom-bar {
position: absolute;
right: 24px;
bottom: 22px;
left: 24px;
display: flex;
align-items: center;
justify-content: space-between;
pointer-events: none;
}
.hint {
display: flex;
align-items: center;
gap: 9px;
color: #728b9d;
font-size: 10px;
letter-spacing: 0.03em;
}
.mouse-icon {
position: relative;
width: 15px;
height: 21px;
border: 1px solid #617d90;
border-radius: 8px;
}
.mouse-icon::before {
position: absolute;
top: 4px;
left: 6px;
width: 2px;
height: 5px;
border-radius: 2px;
background: var(--cyan);
content: "";
}
#resetView {
min-height: 32px;
padding: 0 11px;
pointer-events: auto;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.webgl-error {
position: fixed;
inset: 0;
z-index: 20;
display: none;
place-items: center;
padding: 30px;
background: #07111d;
color: #dcecf7;
text-align: center;
}
@media (max-width: 1050px) {
.panel {
width: 270px;
padding: 15px;
}
.card-stage {
min-height: 155px;
}
#cardName {
font-size: 19px;
}
}
@media (max-width: 760px) {
.topbar {
top: 15px;
right: 14px;
left: 14px;
}
h1 {
font-size: 16px;
}
.live-badge {
padding: 8px 9px;
font-size: 9px;
}
.panel {
top: 70px;
bottom: auto;
}
#probabilityPanel {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 210px;
}
#drawPanel {
right: 12px;
left: auto;
width: 235px;
max-height: calc(100vh - 92px);
}
.formula,
.deck-status,
.history-section,
#cardDescription {
display: none;
}
.prob-list {
grid-template-columns: repeat(2, 1fr);
}
.card-stage {
min-height: 125px;
}
.art-cell {
width: 13px;
height: 13px;
}
.card-art {
grid-template-columns: repeat(5, 13px);
grid-auto-rows: 13px;
gap: 2px;
}
.bottom-bar {
display: none;
}
}
@media (max-width: 480px) {
.live-badge {
display: none;
}
#drawPanel {
top: 65px;
right: 10px;
left: 10px;
width: auto;
}
.card-stage {
display: none;
}
.card-info {
margin-top: 0;
}
.controls {
margin-top: 12px;
}
#probabilityPanel {
right: 10px;
bottom: 10px;
left: 10px;
}
.panel-heading {
margin-bottom: 10px;
}
.remaining-number {
font-size: 23px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="ui">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span>
</div>
<div>
<p class="eyebrow">Voxel draw laboratory</p>
<h1>DECK / SIGNAL</h1>
</div>
</div>
<div class="live-badge">Actual-deck odds</div>
</header>
<aside id="probabilityPanel" class="panel">
<div class="panel-heading">
<div>
<p class="eyebrow">Live composition</p>
<h2>Next-draw probability</h2>
<p class="subtle" id="probabilityCaption">Calculated from the cards still in the deck.</p>
</div>
<div>
<div class="remaining-number" id="remainingCount">64</div>
<div class="remaining-label">Cards left</div>
</div>
</div>
<div class="formula">
<strong>P(type)</strong> = cards of that type remaining<br />
÷ cards remaining in the actual deck
</div>
<div id="probabilityList" class="prob-list" aria-live="polite"></div>
<div class="deck-status">
<p class="mini-label">Deck telemetry</p>
<div class="status-row">
<span>Order</span>
<strong>Fisher–Yates shuffled</strong>
</div>
<div class="status-row">
<span>Source</span>
<strong>Physical remaining array</strong>
</div>
<div class="status-row">
<span>Draw mode</span>
<strong id="drawModeLabel">Manual</strong>
</div>
</div>
</aside>
<aside id="drawPanel" class="panel">
<div class="panel-heading">
<div>
<p class="eyebrow">Reveal bay</p>
<h2>Current draw</h2>
</div>
<button id="resetView" class="button">Reset view</button>
</div>
<div id="cardStage" class="card-stage">
<div id="drawCounter" class="draw-counter">Draw 00 / 64</div>
<div id="cardArt" class="card-art" aria-hidden="true"></div>
<div id="cardId" class="card-id">ID —</div>
</div>
<div class="card-info" aria-live="polite">
<span id="typePill" class="type-pill">Waiting for draw</span>
<h3 id="cardName">The deck is ready</h3>
<p id="cardDescription">
Draw a card to reveal its signal. Every probability updates from the
actual remaining deck.
</p>
</div>
<div class="controls">
<button id="drawButton" class="button primary">Draw next card</button>
<button id="autoButton" class="button auto-button">Auto</button>
</div>
<div class="secondary-controls">
<button id="resetButton" class="button">Shuffle & reset</button>
<button id="keyboardButton" class="button">Space to draw</button>
</div>
<div class="history-section">
<p class="mini-label">Recent draws</p>
<div id="history" class="history">
<span class="history-empty">No cards drawn yet.</span>
</div>
</div>
</aside>
<footer class="bottom-bar">
<div class="hint">
<span class="mouse-icon" aria-hidden="true"></span>
<span>Drag to orbit · Scroll to zoom · Space to draw</span>
</div>
<button id="bottomResetView" class="button">Center camera</button>
</footer>
</div>
<div id="webglError" class="webgl-error">
<div>
<h2>WebGL is required</h2>
<p>This scene could not initialize a WebGL renderer.</p>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/*
* The deck is the single source of truth.
* Counts and probabilities are always derived from this remaining array.
*/
const TYPES = [
{
id: "ember",
name: "Ember",
color: "#ff754f",
light: "#ffd166",
dark: "#a72d3f",
pattern: [
"00010",
"01110",
"11111",
"11011",
"01110",
"00100",
"00100"
],
description: "A warm signal carried from the furnace depths."
},
{
id: "tide",
name: "Tide",
color: "#38c9ff",
light: "#b6f4ff",
dark: "#146b9d",
pattern: [
"00100",
"01110",
"00100",
"11111",
"00100",
"01110",
"00100"
],
description: "A cool pulse moving through a midnight current."
},
{
id: "moss",
name: "Moss",
color: "#70d66f",
light: "#cef28d",
dark: "#277957",
pattern: [
"01110",
"11011",
"11111",
"01110",
"10001",
"01110",
"00000"
],
description: "A quiet green spark from a forgotten garden."
},
{
id: "frost",
name: "Frost",
color: "#b89cff",
light: "#f0eaff",
dark: "#5956ba",
pattern: [
"01010",
"11111",
"01110",
"11011",
"01110",
"00100",
"01110"
],
description: "A sharp crystalline tone hanging in frozen air."
}
];
const TYPE_MAP = Object.fromEntries(TYPES.map((type) => [type.id, type]));
const INITIAL_COMPOSITION = {
ember: 24,
tide: 18,
moss: 14,
frost: 8
};
const INITIAL_SIZE = Object.values(INITIAL_COMPOSITION).reduce(
(sum, count) => sum + count,
0
);
const sceneElement = document.getElementById("scene");
const remainingCountElement = document.getElementById("remainingCount");
const probabilityCaptionElement =
document.getElementById("probabilityList");
const probabilityListElement = document.getElementById("probabilityList");
const probabilityCaption = document.getElementById("probabilityCaption");
const drawButton = document.getElementById("drawButton");
const autoButton = document.getElementById("autoButton");
const resetButton = document.getElementById("resetButton");
const keyboardButton = document.getElementById("keyboardButton");
const resetViewButton = document.getElementById("resetView");
const bottomResetViewButton = document.getElementById("bottomResetView");
const drawModeLabel = document.getElementById("drawModeLabel");
const drawCounter = document.getElementById("drawCounter");
const cardArt = document.getElementById("cardArt");
const cardId = document.getElementById("cardId");
const cardStage = document.getElementById("cardStage");
const typePill = document.getElementById("typePill");
const cardName = document.getElementById("cardName");
const cardDescription = document.getElementById("cardDescription");
const historyElement = document.getElementById("history");
let deck = [];
let currentCard = null;
let currentDraw = null;
let drawNumber = 0;
let busy = false;
let autoMode = false;
let autoTimer = null;
let history = [];
const tweens = [];
function secureRandom() {
const values = new Uint32Array(1);
crypto.getRandomValues(values);
return values[0] / 4294967296;
}
function shuffle(items) {
for (let index = items.length - 1; index > 0; index--) {
const swapIndex = Math.floor(secureRandom() * (index + 1));
[items[index], items[swapIndex]] = [items[swapIndex], items[index]];
}
return items;
}
function createDeck() {
const cards = [];
let id = 1;
for (const type of TYPES) {
for (let index = 0; index < INITIAL_COMPOSITION[type.id]; index++) {
cards.push({
id: `VX-${String(id).padStart(3, "0")}`,
type: type.id
});
id++;
}
}
return shuffle(cards);
}
function getRemainingCounts() {
const counts = Object.fromEntries(TYPES.map((type) => [type.id, 0]));
// Derived directly from the actual remaining deck.
for (const card of deck) {
counts[card.type]++;
}
return counts;
}
function formatPercent(value) {
if (value === 0) return "0.0%";
if (value < 0.001) return "<0.1%";
return `${(value * 100).toFixed(1)}%`;
}
function renderProbabilities() {
const remaining = deck.length;
const counts = getRemainingCounts();
probabilityListElement.innerHTML = TYPES.map((type) => {
const probability = remaining > 0 ? counts[type.id] / remaining : 0;
return `
<div class="prob-row" style="--accent:${type.color}">
<div class="prob-top">
<span class="swatch"></span>
<div>
<span class="prob-name">${type.name}</span>
<span class="prob-count">${counts[type.id]} left</span>
</div>
<span class="prob-percent">${formatPercent(probability)}</span>
</div>
<div class="bar">
<i style="width:${(probability * 100).toFixed(4)}%"></i>
</div>
</div>
`;
}).join("");
remainingCountElement.textContent = remaining;
probabilityCaption.textContent = remaining
? `Each result uses the ${remaining} cards currently left in the deck.`
: "The deck is empty, so no next draw is possible.";
if (deckStack) {
const ratio = remaining / INITIAL_SIZE;
deckStack.scale.y = Math.max(0.12, ratio);
deckStack.visible = remaining > 0;
}
}
function renderCardArt(type) {
cardArt.innerHTML = type.pattern
.join("")
.split("")
.map((cell, index) => {
const alt = Math.floor(index / 5 + (index % 5)) % 3 === 0;
return `<span class="art-cell ${cell === "1" ? "on" : ""} ${
cell === "1" && alt ? "alt" : ""
}"></span>`;
})
.join("");
}
function updateCurrentCard(card) {
if (!card) return;
const type = TYPE_MAP[card.type];
cardStage.style.setProperty("--card-accent", type.color);
cardStage.style.setProperty("--card-accent-alt", type.light);
typePill.style.setProperty("--card-accent", type.color);
typePill.textContent = type.name;
cardName.textContent = `${type.name} signal`;
cardDescription.textContent = type.description;
cardId.textContent = card.id;
drawCounter.textContent = `Draw ${String(drawNumber).padStart(
2,
"0"
)} / ${INITIAL_SIZE}`;
renderCardArt(type);
}
function renderHistory() {
if (!history.length) {
historyElement.innerHTML =
'<span class="history-empty">No cards drawn yet.</span>';
return;
}
historyElement.innerHTML = history
.slice(0, 10)
.map((card) => {
const type = TYPE_MAP[card.type];
return `
<span class="history-chip" style="--chip-color:${type.color}">
<i></i>${card.id}
</span>
`;
})
.join("");
}
function updateControls() {
const noCards = deck.length === 0;
drawButton.disabled = busy || autoMode || noCards;
drawButton.textContent = noCards
? "Deck exhausted"
: busy
? "Drawing…"
: autoMode
? "Auto drawing…"
: "Draw next card";
autoButton.disabled = noCards;
autoButton.classList.toggle("auto-active", autoMode);
autoButton.textContent = autoMode ? "Stop auto" : "Auto";
drawModeLabel.textContent = autoMode
? "Automatic / one at a time"
: "Manual / one at a time";
}
/*
* Three.js setup
*/
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
} catch (error) {
document.getElementById("webglError").style.display = "grid";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel deck scene. Drag to orbit and use the mouse wheel to zoom."
);
sceneElement.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111d);
scene.fog = new THREE.Fog(0x07111d, 13, 29);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0, 1.35, 0);
const cameraState = {
theta: 0.62,
phi: 1.14,
radius: 14.6,
desiredTheta: 0.62,
desiredPhi: 1.14,
desiredRadius: 14.6
};
function updateCamera() {
cameraState.theta +=
(cameraState.desiredTheta - cameraState.theta) * 0.09;
cameraState.phi +=
(cameraState.desiredPhi - cameraState.phi) * 0.09;
cameraState.radius +=
(cameraState.desiredRadius - cameraState.radius) * 0.09;
const spherical = new THREE.Spherical(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraState.desiredTheta = 0.62;
cameraState.desiredPhi = 1.14;
cameraState.desiredRadius = 14.6;
}
resetViewButton.addEventListener("click", resetCamera);
bottomResetViewButton.addEventListener("click", resetCamera);
const hemisphere = new THREE.HemisphereLight(0xb9e8ff, 0x0a1018, 1.75);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(5, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x397dff, 30, 18, 2);
rimLight.position.set(-6, 4, -4);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff7448, 18, 14, 2);
warmLight.position.set(5, 3, 4);
scene.add(warmLight);
function makeBox(
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
options = {}
) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const material = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.72,
metalness: options.metalness ?? 0.08,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
return mesh;
}
/*
* Voxel environment
*/
const groundBase = makeBox(
19,
0.45,
12,
0x0b1826,
0,
-0.48,
0,
{ roughness: 0.92 }
);
scene.add(groundBase);
const tileGeometry = new THREE.BoxGeometry(0.92, 0.07, 0.92);
const tileMaterials = [
new THREE.MeshStandardMaterial({
color: 0x11263a,
roughness: 0.86,
metalness: 0.08
}),
new THREE.MeshStandardMaterial({
color: 0x0e2133,
roughness: 0.86,
metalness: 0.08
}),
new THREE.MeshStandardMaterial({
color: 0x142a3e,
roughness: 0.86,
metalness: 0.08
})
];
for (let row = 0; row < 7; row++) {
for (let column = 0; column < 13; column++) {
const tile = new THREE.Mesh(
tileGeometry,
tileMaterials[(row + column) % tileMaterials.length]
);
tile.position.set(
(column - 6) * 1.04,
-0.22,
(row - 3) * 1.04
);
tile.receiveShadow = true;
scene.add(tile);
}
}
// Rear voxel skyline.
const skylineColors = [0x10263a, 0x142c42, 0x0c2033];
for (let index = 0; index < 15; index++) {
const height = 0.7 + ((index * 7) % 9) * 0.34;
const block = makeBox(
0.86,
height,
0.86,
skylineColors[index % skylineColors.length],
(index - 7) * 1.12,
height / 2 - 0.1,
-4.7,
{ roughness: 0.9 }
);
scene.add(block);
}
// Deck pedestal.
const deckPedestal = makeBox(
3.7,
0.48,
4.3,
0x142a3e,
-2.85,
0.05,
0.05
);
scene.add(deckPedestal);
const deckPedestalTop = makeBox(
3.35,
0.12,
3.95,
0x203b50,
-2.85,
0.35,
0.05
);
scene.add(deckPedestalTop);
// Reveal pedestal.
const revealPedestal = makeBox(
3.8,
0.42,
3.5,
0x142a3e,
2.45,
0.03,
0.2
);
scene.add(revealPedestal);
const revealPedestalTop = makeBox(
3.45,
0.11,
3.15,
0x203b50,
2.45,
0.3,
0.2
);
scene.add(revealPedestalTop);
const displayX = 2.45;
const displayY = 2.57;
const displayZ = 0.2;
const displaySlot = new THREE.Group();
displaySlot.position.set(displayX, displayY, displayZ);
scene.add(displaySlot);
const deckStack = new THREE.Group();
deckStack.position.set(-2.85, 0.41, 0.05);
scene.add(deckStack);
const deckSlabGeometry = new THREE.BoxGeometry(2.78, 0.055, 3.76);
const deckSlabMaterials = [
new THREE.MeshStandardMaterial({
color: 0x172a3e,
roughness: 0.7,
metalness: 0.12
}),
new THREE.MeshStandardMaterial({
color: 0x203a51,
roughness: 0.7,
metalness: 0.12
})
];
for (let index = 0; index < 18; index++) {
const slab = new THREE.Mesh(
deckSlabGeometry,
deckSlabMaterials[index % 2]
);
slab.position.y = index * 0.054;
slab.castShadow = true;
slab.receiveShadow = true;
deckStack.add(slab);
}
// Pixel emblem on the top of the physical deck.
const deckEmblemMaterial = new THREE.MeshStandardMaterial({
color: 0x73e7ff,
emissive: 0x1a91b6,
emissiveIntensity: 0.55,
roughness: 0.5
});
const emblemGeometry = new THREE.BoxGeometry(0.27, 0.065, 0.27);
const emblemPattern = [
[-0.54, -0.54],
[0, -0.54],
[0.54, -0.54],
[-0.27, 0],
[0.27, 0],
[0, 0.54]
];
for (const [x, z] of emblemPattern) {
const emblem = new THREE.Mesh(emblemGeometry, deckEmblemMaterial);
emblem.position.set(x, 1.01, z);
emblem.castShadow = true;
deckStack.add(emblem);
}
function makeVoxelCard(typeId) {
const type = TYPE_MAP[typeId];
const group = new THREE.Group();
const frame = makeBox(
2.8,
3.8,
0.22,
0x172738,
0,
0,
0,
{ roughness: 0.56, metalness: 0.12 }
);
group.add(frame);
const paper = makeBox(
2.54,
3.53,
0.11,
0xe9e5d8,
0,
0,
0.15,
{ roughness: 0.92, metalness: 0 }
);
group.add(paper);
const typeMaterial = new THREE.MeshStandardMaterial({
color: type.color,
emissive: type.dark,
emissiveIntensity: 0.14,
roughness: 0.58,
metalness: 0.08
});
const lightMaterial = new THREE.MeshStandardMaterial({
color: type.light,
emissive: type.color,
emissiveIntensity: 0.1,
roughness: 0.62
});
const voxelGeometry = new THREE.BoxGeometry(0.31, 0.31, 0.13);
type.pattern.forEach((row, rowIndex) => {
[...row].forEach((cell, columnIndex) => {
if (cell !== "1") return;
const voxel = new THREE.Mesh(
voxelGeometry,
(rowIndex + columnIndex) % 3 === 0
? lightMaterial
: typeMaterial
);
voxel.position.set(
(columnIndex - 2) * 0.38,
(3 - rowIndex) * 0.38,
0.27
);
voxel.castShadow = true;
group.add(voxel);
});
});
// Small corner markers give the cards a printed, collectible feel.
const markerGeometry = new THREE.BoxGeometry(0.22, 0.12, 0.08);
const markerMaterial = new THREE.MeshStandardMaterial({
color: type.dark,
roughness: 0.65
});
for (const x of [-1.03, 1.03]) {
for (const y of [-1.48, 1.48]) {
const marker = new THREE.Mesh(markerGeometry, markerMaterial);
marker.position.set(x, y, 0.23);
group.add(marker);
}
}
return group;
}
// Floating decorative voxels.
const floatingCubes = [];
const floatingGeometry = new THREE.BoxGeometry(0.13, 0.13, 0.13);
for (let index = 0; index < 26; index++) {
const material = new THREE.MeshStandardMaterial({
color: index % 3 === 0 ? 0x73e7ff : 0x294b67,
emissive: index % 3 === 0 ? 0x164b62 : 0x000000,
emissiveIntensity: 0.35,
roughness: 0.45
});
const cube = new THREE.Mesh(floatingGeometry, material);
const baseY = 0.6 + ((index * 13) % 19) * 0.22;
cube.position.set(
-6 + ((index * 17) % 120) * 0.1,
baseY,
-2.8 + ((index * 11) % 15) * 0.28
);
cube.userData.baseY = baseY;
cube.userData.phase = index * 0.73;
cube.userData.speed = 0.4 + (index % 5) * 0.08;
scene.add(cube);
floatingCubes.push(cube);
}
/*
* Minimal tween engine
*/
function tween(duration, onUpdate, onComplete) {
tweens.push({
start: performance.now(),
duration,
onUpdate,
onComplete
});
}
function updateTweens(now) {
for (let index = tweens.length - 1; index >= 0; index--) {
const item = tweens[index];
const progress = Math.min(
1,
(now - item.start) / item.duration
);
item.onUpdate(progress);
if (progress >= 1) {
tweens.splice(index, 1);
if (item.onComplete) item.onComplete();
}
}
}
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
function easeOutCubic(value) {
return 1 - Math.pow(1 - value, 3);
}
function easeOutBack(value) {
const c1 = 1.70158;
const c3 = c1 + 1;
return (
1 +
c3 * Math.pow(value - 1, 3) +
c1 * Math.pow(value - 1, 2)
);
}
function lerp(start, end, amount) {
return start + (end - start) * amount;
}
function createBurst(typeId) {
const type = TYPE_MAP[typeId];
const geometry = new THREE.BoxGeometry(0.13, 0.13, 0.13);
const material = new THREE.MeshStandardMaterial({
color: type.light,
emissive: type.color,
emissiveIntensity: 0.75,
roughness: 0.4
});
const particles = [];
for (let index = 0; index < 18; index++) {
const particle = new THREE.Mesh(geometry, material);
const angle = (index / 18) * Math.PI * 2;
const radius = 1.1 + secureRandom() * 1.25;
particle.position.set(
displayX,
displayY,
displayZ + 0.45
);
particle.userData.velocity = new THREE.Vector3(
Math.cos(angle) * radius,
0.8 + secureRandom() * 1.8,
Math.sin(angle) * radius * 0.55
);
particle.userData.spin = new THREE.Vector3(
secureRandom() * 5,
secureRandom() * 5,
secureRandom() * 5
);
scene.add(particle);
particles.push(particle);
}
tween(
720,
(progress) => {
const eased = easeOutCubic(progress);
for (const particle of particles) {
particle.position.addScaledVector(
particle.userData.velocity,
0.018
);
particle.userData.velocity.y -= 0.045;
particle.rotation.x += particle.userData.spin.x * 0.015;
particle.rotation.y += particle.userData.spin.y * 0.015;
particle.rotation.z += particle.userData.spin.z * 0.015;
particle.scale.setScalar(Math.max(0.001, 1 - eased));
}
},
() => {
for (const particle of particles) {
scene.remove(particle);
}
geometry.dispose();
material.dispose();
}
);
}
/*
* Draw flow
*/
function scheduleAutoDraw() {
clearTimeout(autoTimer);
if (!autoMode || busy || deck.length === 0) return;
autoTimer = setTimeout(() => {
if (autoMode) drawNextCard();
}, 720);
}
function drawNextCard() {
if (busy || deck.length === 0) return;
busy = true;
updateControls();
// The actual next card comes from the shuffled remaining array.
const card = deck.pop();
// Immediately remove that card from the probability denominator.
renderProbabilities();
// Move the previous reveal out of the bay.
if (currentCard) {
const previousCard = currentCard;
currentCard = null;
tween(
260,
(progress) => {
const eased = easeOutCubic(progress);
previousCard.scale.setScalar(1 - eased);
previousCard.position.y = -eased * 0.55;
previousCard.rotation.z = eased * -0.22;
},
() => {
displaySlot.remove(previousCard);
}
);
}
const voxelCard = makeVoxelCard(card.type);
voxelCard.scale.setScalar(0.55);
voxelCard.position.set(
-2.85 - displayX,
1.48 - displayY,
0.05 - displayZ
);
voxelCard.rotation.x = -Math.PI / 2;
voxelCard.rotation.y = -0.34;
displaySlot.add(voxelCard);
tween(
980,
(progress) => {
const travel = easeInOutCubic(Math.min(1, progress / 0.82));
const reveal = easeOutBack(Math.min(1, progress / 0.9));
const lift = Math.sin(travel * Math.PI) * 1.35;
voxelCard.position.x = lerp(
-2.85 - displayX,
0,
travel
);
voxelCard.position.y =
lerp(1.48 - displayY, 0, travel) + lift;
voxelCard.position.z = lerp(
0.05 - displayZ,
0,
travel
);
voxelCard.rotation.x = lerp(-Math.PI / 2, 0, travel);
voxelCard.rotation.y = lerp(-0.34, 0, travel);
voxelCard.rotation.z = lerp(0.09, 0, travel);
const scale = Math.min(1.035, 0.55 + reveal * 0.45);
voxelCard.scale.setScalar(scale);
},
() => {
voxelCard.position.set(0, 0, 0);
voxelCard.rotation.set(0, 0, 0);
voxelCard.scale.setScalar(1);
currentCard = voxelCard;
currentDraw = card;
drawNumber += 1;
history.unshift(card);
renderHistory();
updateCurrentCard(card);
createBurst(card.type);
busy = false;
updateControls();
if (autoMode && deck.length > 0) {
scheduleAutoDraw();
} else if (autoMode && deck.length === 0) {
autoMode = false;
updateControls();
}
}
);
}
function resetDeck() {
clearTimeout(autoTimer);
autoMode = false;
busy = false;
drawNumber = 0;
currentDraw = null;
history = [];
if (currentCard) {
displaySlot.remove(currentCard);
currentCard = null;
}
deck = createDeck();
renderProbabilities();
renderHistory();
updateCurrentCard({
id: "—",
type: "ember"
});
typePill.textContent = "Waiting for draw";
cardName.textContent = "The deck is ready";
cardDescription.textContent =
"Draw a card to reveal its signal. Every probability updates from the actual remaining deck.";
cardId.textContent = "ID —";
drawCounter.textContent = `Draw 00 / ${INITIAL_SIZE}`;
cardArt.innerHTML = "";
updateControls();
}
drawButton.addEventListener("click", drawNextCard);
autoButton.addEventListener("click", () => {
autoMode = !autoMode;
if (!autoMode) {
clearTimeout(autoTimer);
updateControls();
return;
}
updateControls();
if (!busy) {
drawNextCard();
}
});
resetButton.addEventListener("click", resetDeck);
keyboardButton.addEventListener("click", drawNextCard);
window.addEventListener("keydown", (event) => {
const activeTag = document.activeElement?.tagName;
if (["BUTTON", "INPUT", "TEXTAREA", "SELECT"].includes(activeTag)) {
return;
}
if (event.code === "Space") {
event.preventDefault();
if (!autoMode) drawNextCard();
}
if (event.key.toLowerCase() === "r") {
resetDeck();
}
});
/*
* Direct camera controls — no addons or OrbitControls import.
*/
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
let activePointerId = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
activePointerId = event.pointerId;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraState.desiredTheta -= deltaX * 0.006;
cameraState.desiredPhi -= deltaY * 0.005;
cameraState.desiredPhi = THREE.MathUtils.clamp(
cameraState.desiredPhi,
0.58,
1.42
);
});
function endDrag(event) {
if (event.pointerId !== activePointerId) return;
dragging = false;
activePointerId = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius * Math.exp(event.deltaY * 0.001),
9.5,
22
);
},
{ passive: false }
);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
/*
* Initialization and render loop
*/
deck = createDeck();
renderProbabilities();
renderHistory();
updateControls();
updateCamera();
const clock = new THREE.Clock();
function render(now) {
requestAnimationFrame(render);
const elapsed = clock.getElapsedTime();
updateTweens(now);
updateCamera();
displaySlot.position.y = displayY + Math.sin(elapsed * 1.25) * 0.035;
displaySlot.rotation.y = Math.sin(elapsed * 0.42) * 0.018;
for (const cube of floatingCubes) {
cube.position.y =
cube.userData.baseY +
Math.sin(elapsed * cube.userData.speed + cube.userData.phase) *
0.16;
cube.rotation.x = elapsed * 0.12 + cube.userData.phase;
cube.rotation.y = elapsed * 0.18 + cube.userData.phase;
}
renderer.render(scene, camera);
}
requestAnimationFrame(render);
</script>
</body>
</html>
```