Prompt specification
Build or customize the Three.js 3D scene "Pixel-art memory workshop" 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: Pixel-art memory workshop
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/pixel-art-memory-workshop-x1847
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: pixel-art memory workshop. Compose a tiny pixel grid and its binary storage rows; toggle cells and update encoded patterns while keeping row order and bit ordering explicit. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (pixel-art-memory-workshop-x1847):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Memory Workshop</title>
<style>
:root {
--ink: #eaf6ff;
--muted: #91a7bd;
--cyan: #62e6ff;
--green: #75ffb0;
--amber: #ffc65c;
--panel: rgba(10, 18, 31, 0.86);
--line: rgba(98, 230, 255, 0.28);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #09111e;
color: var(--ink);
font-family: "Courier New", ui-monospace, SFMono-Regular, Menlo, monospace;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.panel {
background: var(--panel);
border: 1px solid var(--line);
box-shadow:
0 16px 50px rgba(0, 0, 0, 0.35),
inset 0 0 0 1px rgba(255, 255, 255, 0.025);
backdrop-filter: blur(12px);
}
.intro {
position: absolute;
top: 22px;
left: 22px;
width: min(410px, calc(100vw - 44px));
padding: 18px 20px 16px;
clip-path: polygon(0 0, calc(100% - 13px) 0, 100% 13px, 100% 100%, 13px 100%, 0 calc(100% - 13px));
}
.eyebrow {
color: var(--cyan);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 8px;
font-size: clamp(23px, 3vw, 34px);
line-height: 1;
letter-spacing: -0.055em;
}
.intro p {
margin: 0 0 14px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.order-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.order {
padding: 9px 10px;
background: rgba(98, 230, 255, 0.055);
border: 1px solid rgba(98, 230, 255, 0.13);
color: #b9cad8;
font-size: 10px;
line-height: 1.5;
}
.order strong {
display: block;
color: var(--ink);
font-size: 11px;
}
#readout {
min-height: 17px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px dashed rgba(145, 167, 189, 0.28);
color: var(--amber);
font-size: 11px;
letter-spacing: 0.03em;
}
.ledger {
position: absolute;
top: 22px;
right: 22px;
width: 302px;
padding: 15px;
}
.ledger-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.ledger h2 {
margin: 0;
font-size: 12px;
letter-spacing: 0.14em;
}
.ledger-note {
color: var(--muted);
font-size: 9px;
}
#memoryRows {
display: grid;
gap: 4px;
}
.mem-row {
display: grid;
grid-template-columns: 36px 1fr 43px;
align-items: center;
gap: 8px;
min-height: 25px;
padding: 4px 7px;
background: rgba(255, 255, 255, 0.025);
border: 1px solid transparent;
color: #afc1d1;
font-size: 11px;
cursor: pointer;
transition: 140ms ease;
}
.mem-row:hover,
.mem-row.selected {
color: var(--ink);
background: rgba(98, 230, 255, 0.09);
border-color: rgba(98, 230, 255, 0.25);
}
.mem-row.flash {
animation: row-flash 320ms ease;
}
@keyframes row-flash {
0% { background: rgba(117, 255, 176, 0.38); }
100% { background: rgba(255, 255, 255, 0.025); }
}
.addr { color: var(--cyan); }
.bits { letter-spacing: 0.13em; }
.hex { color: var(--green); text-align: right; }
.cache {
margin-top: 10px;
padding-top: 10px;
border-top: 1px dashed rgba(145, 167, 189, 0.28);
}
.cache-label {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.1em;
}
#cacheValue {
margin-top: 5px;
color: var(--green);
font-size: 11px;
line-height: 1.5;
word-spacing: 0.35em;
}
.toolbar {
position: absolute;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
display: flex;
gap: 7px;
padding: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid rgba(145, 167, 189, 0.28);
background: rgba(255, 255, 255, 0.035);
color: #b9c9d8;
padding: 10px 13px;
font: 700 10px/1 "Courier New", monospace;
letter-spacing: 0.08em;
cursor: pointer;
transition: 130ms ease;
}
button:hover,
button.active {
color: #07121d;
background: var(--cyan);
border-color: var(--cyan);
box-shadow: 0 0 18px rgba(98, 230, 255, 0.2);
}
button:focus-visible {
outline: 2px solid var(--amber);
outline-offset: 2px;
}
.help {
position: absolute;
left: 22px;
bottom: 24px;
color: rgba(214, 231, 243, 0.7);
font-size: 10px;
line-height: 1.7;
text-shadow: 0 2px 8px #000;
}
.help b { color: var(--cyan); }
@media (max-width: 920px) {
.ledger { display: none; }
.help { display: none; }
}
@media (max-width: 560px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px;
}
.intro p { margin-bottom: 9px; }
.order-grid { grid-template-columns: 1fr; }
.order { display: inline-block; width: 49%; vertical-align: top; }
.toolbar { bottom: 12px; width: calc(100vw - 24px); overflow-x: auto; }
button { flex: 1 0 auto; }
}
</style>
</head>
<body>
<div class="ui">
<section class="intro panel">
<div class="eyebrow">Voxel Lab / 08 × 08 Cell Matrix</div>
<h1>MEMORY WORKSHOP</h1>
<p>Click a voxel to toggle its bit. Each horizontal scanline is stored as one byte, with the grid and memory lamps updating together.</p>
<div class="order-grid">
<div class="order">
<strong>ROW ORDER</strong>
R00 → R07<br />
TOP → BOTTOM
</div>
<div class="order">
<strong>BIT ORDER</strong>
B07 → B00<br />
LEFT → RIGHT · MSB → LSB
</div>
</div>
<div id="readout" aria-live="polite">
READY · SMILE PATTERN LOADED
</div>
</section>
<aside class="ledger panel" aria-label="Encoded byte ledger">
<div class="ledger-head">
<h2>BYTE LEDGER</h2>
<span class="ledger-note">R00 → R07</span>
</div>
<div id="memoryRows"></div>
<div class="cache">
<div class="cache-label">HEX MEMORY · R00 → R07</div>
<div id="cacheValue"></div>
</div>
</aside>
<div class="toolbar panel" role="toolbar" aria-label="Pixel patterns">
<button type="button" data-preset="smile" class="active">SMILE</button>
<button type="button" data-preset="heart">HEART</button>
<button type="button" data-preset="checker">CHECKER</button>
<button type="button" data-preset="clear">CLEAR</button>
</div>
<div class="help">
<b>CLICK</b> VOXEL · TOGGLE BIT<br />
<b>DRAG</b> SCENE · ORBIT VIEW · <b>SCROLL</b> ZOOM
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const SIZE = 8;
const TILE_GAP = 0.55;
const ON_COLOR = 0xffbd4a;
const OFF_COLOR = 0x26354d;
const presets = {
smile: [
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[0, 1, 1, 1, 1, 1, 1, 0]
],
heart: [
[0, 1, 1, 0, 0, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]
],
checker: [
[1, 0, 1, 0, 1, 0, 1, 0],
[0, 1, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 0, 1, 0],
[0, 1, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 0, 1, 0],
[0, 1, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 0, 1, 0],
[0, 1, 0, 1, 0, 1, 0, 1]
],
clear: Array.from({ length: SIZE }, () => Array(SIZE).fill(0))
};
let state = presets.smile.map(row => row.slice());
let selectedRow = null;
let hoveredTile = null;
const readout = document.getElementById("readout");
const memoryRowsElement = document.getElementById("memoryRows");
const cacheValue = document.getElementById("cacheValue");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x09111e);
scene.fog = new THREE.Fog(0x09111e, 24, 42);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.id = "stage";
renderer.domElement.setAttribute("aria-label", "Interactive eight by eight voxel pixel grid");
renderer.domElement.tabIndex = 0;
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-8, 8, 5.25, -5.25, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 2.45, 0);
const cameraState = { yaw: 0.16, pitch: 0.23, zoom: 1 };
function updateCamera() {
const distance = 18;
const cp = Math.cos(cameraState.pitch);
camera.position.set(
cameraTarget.x + Math.sin(cameraState.yaw) * cp * distance,
cameraTarget.y + Math.sin(cameraState.pitch) * distance,
cameraTarget.z + Math.cos(cameraState.yaw) * cp * distance
);
camera.lookAt(cameraTarget);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(10.5, 16.2 / 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);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
updateCamera();
resize();
const hemi = new THREE.HemisphereLight(0xa9d8ff, 0x182033, 2.15);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff2d6, 3.1);
key.position.set(-3, 11, 9);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -11;
key.shadow.camera.right = 11;
key.shadow.camera.top = 10;
key.shadow.camera.bottom = -6;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 35;
key.shadow.bias = -0.0004;
scene.add(key);
const cyanLight = new THREE.PointLight(0x39d8ff, 38, 20, 2);
cyanLight.position.set(-6.5, 5.5, 4.5);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xffa735, 34, 18, 2);
amberLight.position.set(6, 4.2, 4);
scene.add(amberLight);
const materials = {
floor: new THREE.MeshStandardMaterial({ color: 0x0b1422, roughness: 0.95 }),
wall: new THREE.MeshStandardMaterial({ color: 0x172238, roughness: 0.9 }),
peg: new THREE.MeshStandardMaterial({ color: 0x0a1220, roughness: 1 }),
bench: new THREE.MeshStandardMaterial({ color: 0x74513a, roughness: 0.8 }),
benchDark: new THREE.MeshStandardMaterial({ color: 0x342c2d, roughness: 0.86 }),
frame: new THREE.MeshStandardMaterial({ color: 0x463a39, roughness: 0.72 }),
board: new THREE.MeshStandardMaterial({ color: 0x17263a, roughness: 0.88 }),
socket: new THREE.MeshStandardMaterial({ color: 0x080e18, roughness: 0.95 }),
darkMetal: new THREE.MeshStandardMaterial({ color: 0x243247, roughness: 0.52, metalness: 0.28 }),
cream: new THREE.MeshStandardMaterial({ color: 0xd6d3bd, roughness: 0.82 }),
red: new THREE.MeshStandardMaterial({ color: 0xd75e5e, roughness: 0.75 })
};
function box(parent, width, height, depth, x, y, z, material, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Workshop shell.
const floor = new THREE.Mesh(new THREE.PlaneGeometry(60, 60), materials.floor);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.45;
floor.receiveShadow = true;
scene.add(floor);
box(scene, 15.6, 7.4, 0.42, 0, 3.0, -1.35, materials.wall);
box(scene, 15.4, 0.42, 6.4, 0, -0.22, 0.15, materials.bench);
box(scene, 15.7, 0.18, 6.65, 0, 0.02, 0.15, materials.benchDark);
for (const x of [-6.45, 6.45]) {
for (const z of [-2.35, 2.6]) {
box(scene, 0.48, 2.2, 0.48, x, -1.32, z, materials.benchDark);
}
}
box(scene, 12.2, 1.2, 0.38, 0, -0.95, 2.83, materials.benchDark);
for (let i = 0; i < 4; i++) {
box(scene, 2.82, 0.72, 0.08, -4.55 + i * 3.03, -0.95, 3.06, materials.darkMetal);
box(scene, 0.62, 0.08, 0.1, -4.55 + i * 3.03, -0.95, 3.13, materials.cream);
}
// Pegboard holes.
for (let row = 0; row < 9; row++) {
for (let col = 0; col < 19; col++) {
const hole = box(
scene,
0.08,
0.08,
0.025,
-7.05 + col * 0.78,
0.15 + row * 0.68,
-1.125,
materials.peg,
false
);
hole.rotation.z = Math.PI / 4;
}
}
// Labels are rendered locally with canvas textures.
function createLabel(text, width, height, color = "#dcefff", fontSize = 58) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 128;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(width, height), material);
mesh.renderOrder = 8;
mesh.userData.canvas = canvas;
mesh.userData.context = context;
mesh.userData.texture = texture;
mesh.userData.color = color;
mesh.userData.fontSize = fontSize;
updateLabel(mesh, text);
return mesh;
}
function updateLabel(mesh, text) {
const context = mesh.userData.context;
const canvas = mesh.userData.canvas;
context.clearRect(0, 0, canvas.width, canvas.height);
context.textAlign = "center";
context.textBaseline = "middle";
let fontSize = mesh.userData.fontSize;
context.font = `700 ${fontSize}px "Courier New", monospace`;
while (context.measureText(text).width > 730 && fontSize > 18) {
fontSize -= 2;
context.font = `700 ${fontSize}px "Courier New", monospace`;
}
context.fillStyle = mesh.userData.color;
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
mesh.userData.texture.needsUpdate = true;
}
const gridGroup = new THREE.Group();
gridGroup.position.set(-3.15, 3.25, 0.12);
scene.add(gridGroup);
const memoryGroup = new THREE.Group();
memoryGroup.position.set(3.45, 3.25, 0.12);
scene.add(memoryGroup);
box(gridGroup, 5.28, 5.65, 0.36, 0, 0, 0, materials.frame);
box(gridGroup, 5.02, 5.39, 0.16, 0, 0, 0.23, materials.board);
box(memoryGroup, 5.62, 5.65, 0.36, 0, 0, 0, materials.frame);
box(memoryGroup, 5.36, 5.39, 0.16, 0, 0, 0.23, materials.board);
// Feet under both display boards.
for (const x of [-4.95, -1.35, 1.65, 5.25]) {
box(scene, 0.55, 0.52, 0.8, x, 0.24, -0.1, materials.darkMetal);
}
// Corner rivets.
for (const group of [gridGroup, memoryGroup]) {
const halfWidth = group === gridGroup ? 2.48 : 2.66;
for (const sx of [-1, 1]) {
for (const sy of [-1, 1]) {
box(
group,
0.11,
0.11,
0.1,
sx * halfWidth,
sy * 2.66,
0.25,
materials.cream,
false
);
}
}
}
const gridTitle = createLabel("CELL MATRIX // 08 × 08", 3.6, 0.34, "#62e6ff", 62);
gridTitle.position.set(0, 2.51, 0.38);
gridGroup.add(gridTitle);
const gridSubtitle = createLabel("TOP R00 ↓ BOTTOM R07", 3.2, 0.22, "#91a7bd", 45);
gridSubtitle.position.set(0, -2.53, 0.38);
gridGroup.add(gridSubtitle);
const memoryTitle = createLabel("BYTE MEMORY // SCANLINES", 4.45, 0.34, "#62e6ff", 58);
memoryTitle.position.set(0, 2.51, 0.38);
memoryGroup.add(memoryTitle);
const memorySubtitle = createLabel("B07 → B00 · MSB → LSB", 4.15, 0.22, "#91a7bd", 45);
memorySubtitle.position.set(0, 2.19, 0.38);
memoryGroup.add(memorySubtitle);
const tileMeshes = [];
const rowLabels = [];
const columnLabels = [];
const memoryLamps = [];
const memoryPatternLabels = [];
const memoryAddressLabels = [];
for (let col = 0; col < SIZE; col++) {
const bit = 7 - col;
const label = createLabel(`B${String(bit).padStart(2, "0")}`, 0.48, 0.18, "#91a7bd", 44);
label.position.set((col - 3.5) * TILE_GAP, 2.16, 0.39);
gridGroup.add(label);
columnLabels.push(label);
}
for (let row = 0; row < SIZE; row++) {
const y = (3.5 - row) * TILE_GAP;
const rowLabel = createLabel(`R${String(row).padStart(2, "0")}`, 0.48, 0.19, "#62e6ff", 46);
rowLabel.position.set(-2.38, y, 0.4);
gridGroup.add(rowLabel);
rowLabels.push(rowLabel);
for (let col = 0; col < SIZE; col++) {
const x = (col - 3.5) * TILE_GAP;
box(
gridGroup,
0.49,
0.49,
0.09,
x,
y,
0.34,
materials.socket,
false
);
const material = new THREE.MeshStandardMaterial({
color: OFF_COLOR,
emissive: 0x030812,
emissiveIntensity: 0.16,
roughness: 0.52,
metalness: 0.08
});
const tile = box(gridGroup, 0.43, 0.43, 0.32, x, y, 0.49, material);
tile.userData = { row, col };
tileMeshes.push(tile);
}
const address = createLabel(`R${String(row).padStart(2, "0")}`, 0.54, 0.19, "#62e6ff", 45);
address.position.set(-2.33, 1.56 - row * 0.48, 0.4);
memoryGroup.add(address);
memoryAddressLabels.push(address);
for (let col = 0; col < SIZE; col++) {
const bit = 7 - col;
const bitLabel = createLabel(`B${bit}`, 0.31, 0.14, "#91a7bd", 38);
bitLabel.position.set(-1.43 + col * 0.4, 1.94, 0.4);
memoryGroup.add(bitLabel);
const lampMaterial = new THREE.MeshStandardMaterial({
color: 0x17312e,
emissive: 0x03110e,
emissiveIntensity: 0.18,
roughness: 0.46
});
const lamp = box(
memoryGroup,
0.29,
0.29,
0.22,
-1.43 + col * 0.4,
1.56 - row * 0.48,
0.42,
lampMaterial
);
lamp.userData = { row, col };
memoryLamps.push(lamp);
}
const pattern = createLabel("00000000", 1.12, 0.2, "#75ffb0", 38);
pattern.position.set(2.02, 1.56 - row * 0.48, 0.4);
memoryGroup.add(pattern);
memoryPatternLabels.push(pattern);
}
// Selection marker across the selected grid scanline.
const selectionMaterial = new THREE.MeshBasicMaterial({
color: 0x62e6ff,
transparent: true,
opacity: 0.55,
depthWrite: false
});
const selectionMarker = box(gridGroup, 4.45, 0.035, 0.04, 0, 0, 0.73, selectionMaterial, false);
selectionMarker.visible = false;
selectionMarker.renderOrder = 10;
// Hover outline.
const hoverOutline = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(0.49, 0.49, 0.35)),
new THREE.LineBasicMaterial({ color: 0x83efff, transparent: true, opacity: 0.95 })
);
hoverOutline.visible = false;
hoverOutline.renderOrder = 12;
gridGroup.add(hoverOutline);
// Decorative workshop objects.
box(scene, 0.8, 0.16, 0.8, -6.35, 0.12, 1.45, materials.darkMetal);
box(scene, 0.13, 2.25, 0.13, -6.35, 1.25, 1.45, materials.darkMetal);
box(scene, 1.25, 0.13, 0.13, -5.82, 2.3, 1.45, materials.darkMetal);
box(scene, 0.72, 0.46, 0.72, -5.28, 2.11, 1.45, materials.red);
const lampGlow = new THREE.PointLight(0xffa43c, 9, 5, 2);
lampGlow.position.set(-5.25, 1.85, 1.45);
scene.add(lampGlow);
// Memory cartridge stack.
for (let i = 0; i < 4; i++) {
const cartridge = box(
scene,
1.35,
0.18,
0.72,
6.45,
0.18 + i * 0.2,
1.25 - i * 0.08,
i % 2 ? materials.darkMetal : materials.cream
);
cartridge.rotation.y = i * 0.035;
box(
scene,
0.5,
0.035,
0.24,
6.45,
0.285 + i * 0.2,
1.59 - i * 0.08,
materials.red,
false
);
}
// Small tool blocks and ruler.
box(scene, 2.2, 0.07, 0.28, 4.55, 0.11, 2.2, materials.cream);
for (let i = 0; i < 9; i++) {
box(
scene,
0.035,
0.015,
i % 2 ? 0.14 : 0.2,
3.65 + i * 0.22,
0.155,
2.2,
materials.darkMetal,
false
);
}
// Build the HTML ledger.
const ledgerRows = [];
for (let row = 0; row < SIZE; row++) {
const element = document.createElement("div");
element.className = "mem-row";
element.setAttribute("role", "button");
element.setAttribute("tabindex", "0");
element.setAttribute("aria-label", `Select row R${String(row).padStart(2, "0")}`);
element.innerHTML = `
<span class="addr">R${String(row).padStart(2, "0")}</span>
<span class="bits">00000000</span>
<span class="hex">0x00</span>
`;
element.addEventListener("click", () => selectRow(row));
element.addEventListener("keydown", event => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
selectRow(row);
}
});
memoryRowsElement.appendChild(element);
ledgerRows.push(element);
}
function bitsForRow(row) {
return state[row].map(Number).join("");
}
function byteForRow(row) {
return parseInt(bitsForRow(row), 2);
}
function updateVisuals() {
for (const tile of tileMeshes) {
const { row, col } = tile.userData;
const on = Boolean(state[row][col]);
const isHovered = tile === hoveredTile;
const isSelected = selectedRow === row;
tile.material.color.setHex(on ? ON_COLOR : OFF_COLOR);
if (isHovered) {
tile.material.emissive.setHex(0x1a7184);
tile.material.emissiveIntensity = 0.9;
} else if (isSelected) {
tile.material.emissive.setHex(0x0c5361);
tile.material.emissiveIntensity = 0.55;
} else if (on) {
tile.material.emissive.setHex(0x733000);
tile.material.emissiveIntensity = 0.5;
} else {
tile.material.emissive.setHex(0x030812);
tile.material.emissiveIntensity = 0.16;
}
}
for (const lamp of memoryLamps) {
const { row, col } = lamp.userData;
const on = Boolean(state[row][col]);
lamp.material.color.setHex(on ? 0x75ffb0 : 0x17312e);
lamp.material.emissive.setHex(on ? 0x20ff88 : 0x03110e);
lamp.material.emissiveIntensity = on ? 1.35 : 0.18;
}
const hexBytes = [];
for (let row = 0; row < SIZE; row++) {
const bits = bitsForRow(row);
const byte = byteForRow(row);
const hex = byte.toString(16).toUpperCase().padStart(2, "0");
updateLabel(memoryPatternLabels[row], bits);
updateLabel(memoryAddressLabels[row], `R${String(row).padStart(2, "0")}`);
ledgerRows[row].querySelector(".bits").textContent = bits;
ledgerRows[row].querySelector(".hex").textContent = `0x${hex}`;
ledgerRows[row].classList.toggle("selected", selectedRow === row);
hexBytes.push(hex);
}
cacheValue.textContent = hexBytes.join(" ");
if (selectedRow === null) {
selectionMarker.visible = false;
} else {
selectionMarker.visible = true;
selectionMarker.position.y = (3.5 - selectedRow) * TILE_GAP;
}
}
function selectRow(row) {
selectedRow = selectedRow === row ? null : row;
updateVisuals();
if (selectedRow === null) {
readout.textContent = "ROW SELECTION CLEARED";
} else {
readout.textContent =
`ROW R${String(selectedRow).padStart(2, "0")} SELECTED · ` +
`${bitsForRow(selectedRow)} · 0x${byteForRow(selectedRow).toString(16).toUpperCase().padStart(2, "0")}`;
}
}
const pulses = [];
function pulse(mesh) {
pulses.push({ mesh, start: performance.now() });
}
function toggleCell(row, col) {
state[row][col] = state[row][col] ? 0 : 1;
updateVisuals();
const bit = 7 - col;
const value = state[row][col];
const byte = byteForRow(row);
const hex = byte.toString(16).toUpperCase().padStart(2, "0");
readout.textContent =
`R${String(row).padStart(2, "0")} / B${String(bit).padStart(2, "0")} ` +
`→ ${value} · BYTE ${bitsForRow(row)} · 0x${hex}`;
const tile = tileMeshes.find(mesh =>
mesh.userData.row === row && mesh.userData.col === col
);
if (tile) pulse(tile);
const lamp = memoryLamps.find(mesh =>
mesh.userData.row === row && mesh.userData.col === col
);
if (lamp) pulse(lamp);
ledgerRows[row].classList.remove("flash");
void ledgerRows[row].offsetWidth;
ledgerRows[row].classList.add("flash");
}
document.querySelectorAll("[data-preset]").forEach(button => {
button.addEventListener("click", () => {
const name = button.dataset.preset;
state = presets[name].map(row => row.slice());
selectedRow = null;
document.querySelectorAll("[data-preset]").forEach(other => {
other.classList.toggle("active", other === button);
});
updateVisuals();
readout.textContent =
`${name.toUpperCase()} PATTERN LOADED · R00 → R07 · B07 → B00`;
});
});
// Direct raycasting and custom camera controls.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let moved = false;
let startX = 0;
let startY = 0;
let lastX = 0;
let lastY = 0;
function pickTile(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;
raycaster.setFromCamera(pointer, camera);
return raycaster.intersectObjects(tileMeshes, false)[0]?.object ?? null;
}
function setHovered(tile) {
if (hoveredTile === tile) return;
hoveredTile = tile;
if (tile) {
hoverOutline.visible = true;
hoverOutline.position.copy(tile.position);
renderer.domElement.style.cursor = "pointer";
} else {
hoverOutline.visible = false;
renderer.domElement.style.cursor = "grab";
}
updateVisuals();
}
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
pointerDown = true;
moved = false;
startX = lastX = event.clientX;
startY = lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
if (pointerDown) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (Math.hypot(event.clientX - startX, event.clientY - startY) > 4) {
moved = true;
}
cameraState.yaw -= dx * 0.006;
cameraState.pitch += dy * 0.004;
cameraState.pitch = THREE.MathUtils.clamp(cameraState.pitch, 0.06, 0.62);
updateCamera();
} else {
setHovered(pickTile(event));
}
});
renderer.domElement.addEventListener("pointerup", event => {
if (!pointerDown) return;
pointerDown = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
renderer.domElement.style.cursor = hoveredTile ? "pointer" : "grab";
if (!moved) {
const tile = pickTile(event);
if (tile) {
const { row, col } = tile.userData;
toggleCell(row, col);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
renderer.domElement.style.cursor = hoveredTile ? "pointer" : "grab";
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!pointerDown) setHovered(null);
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.7
);
updateCamera();
}, { passive: false });
updateVisuals();
renderer.domElement.style.cursor = "grab";
function animate(now) {
requestAnimationFrame(animate);
for (let i = pulses.length - 1; i >= 0; i--) {
const item = pulses[i];
const progress = (now - item.start) / 360;
if (progress >= 1) {
item.mesh.scale.setScalar(1);
pulses.splice(i, 1);
} else {
const scale = 1 + Math.sin(progress * Math.PI) * 0.18;
item.mesh.scale.setScalar(scale);
}
}
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```