Prompt specification
Build or customize the Three.js 3D scene "Punched card with selected holes" 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: Punched card with selected holes
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/punched-card-with-selected-holes-x2497
Scene Description Prompt:
A stylized punched card with a gridded original hole pattern showing binary selections at each position. Build one HTML file using Three.js from cdnjs.
Working Three.js Starter (punched-card-with-selected-holes-x2497):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PunchLab — Binary Selection Card</title>
<style>
:root {
color-scheme: dark;
--ink: #eef5fb;
--muted: #8fa4b6;
--panel: rgba(10, 20, 32, 0.76);
--line: rgba(158, 196, 222, 0.18);
--cyan: #71d7e7;
--amber: #e6b978;
--paper: #f1e3c8;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111d;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
button,
canvas {
-webkit-tap-highlight-color: transparent;
}
#app {
position: fixed;
inset: 0;
}
#app canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#app canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
z-index: 5;
pointer-events: none;
}
.brand {
top: 30px;
left: 32px;
display: flex;
align-items: center;
gap: 14px;
}
.brand-mark {
position: relative;
width: 42px;
height: 42px;
border: 1px solid rgba(113, 215, 231, 0.5);
border-radius: 11px;
background:
radial-gradient(circle at 50% 50%, rgba(113, 215, 231, 0.18) 0 3px, transparent 4px),
rgba(113, 215, 231, 0.04);
box-shadow: inset 0 0 18px rgba(113, 215, 231, 0.08);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: rgba(113, 215, 231, 0.45);
}
.brand-mark::before {
width: 1px;
height: 26px;
top: 7px;
left: 20px;
}
.brand-mark::after {
width: 26px;
height: 1px;
top: 20px;
left: 7px;
}
.brand h1 {
margin: 0;
font-size: 17px;
line-height: 1;
letter-spacing: 0.2em;
font-weight: 750;
}
.brand p {
margin: 8px 0 0;
color: var(--muted);
font: 10px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.telemetry {
top: 26px;
right: 26px;
width: 292px;
padding: 18px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.32),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
pointer-events: auto;
}
.eyebrow {
color: var(--cyan);
font: 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.count-row {
display: flex;
align-items: baseline;
gap: 8px;
margin-top: 8px;
}
.count-row strong {
font: 600 30px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
color: var(--paper);
}
.count-row span {
color: var(--muted);
font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.meter {
height: 3px;
margin: 13px 0 16px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
}
.meter-fill {
height: 100%;
width: 50%;
border-radius: inherit;
background: linear-gradient(90deg, var(--amber), var(--cyan));
transition: width 250ms ease;
}
#bitRows {
display: grid;
gap: 5px;
padding: 12px 0;
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
}
.bit-row {
display: grid;
grid-template-columns: 22px repeat(16, 1fr);
align-items: center;
gap: 4px;
}
.row-label {
color: #6f8495;
font: 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.bit {
height: 13px;
min-width: 0;
padding: 0;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 2px;
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
.bit:hover {
transform: scaleY(1.2);
border-color: rgba(113, 215, 231, 0.55);
}
.bit.active {
border-color: rgba(230, 185, 120, 0.55);
background: var(--amber);
box-shadow: 0 0 8px rgba(230, 185, 120, 0.13);
}
.legend {
display: flex;
gap: 16px;
margin-top: 13px;
color: var(--muted);
font: 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.legend i {
display: block;
width: 9px;
height: 9px;
border-radius: 50%;
}
.legend .selected {
background: #17120d;
border: 1px solid var(--amber);
}
.legend .unselected {
background: rgba(255, 255, 255, 0.04);
border: 1px solid rgba(230, 185, 120, 0.48);
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 15px;
}
.actions button {
padding: 9px 8px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.04);
color: var(--ink);
font: 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
.actions button:hover {
transform: translateY(-1px);
border-color: rgba(113, 215, 231, 0.45);
background: rgba(113, 215, 231, 0.08);
}
.help {
left: 50%;
bottom: 25px;
transform: translateX(-50%);
padding: 10px 15px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(7, 17, 29, 0.68);
color: var(--muted);
font: 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
white-space: nowrap;
backdrop-filter: blur(12px);
}
.help b {
color: var(--paper);
font-weight: 600;
}
#toast {
position: fixed;
z-index: 8;
left: 50%;
bottom: 76px;
transform: translate(-50%, 10px);
padding: 9px 13px;
border: 1px solid rgba(113, 215, 231, 0.28);
border-radius: 8px;
background: rgba(8, 18, 30, 0.88);
color: var(--cyan);
font: 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
opacity: 0;
pointer-events: none;
transition:
opacity 180ms ease,
transform 180ms ease;
}
#toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 760px) {
.brand {
top: 18px;
left: 18px;
}
.brand p {
display: none;
}
.telemetry {
top: auto;
right: 12px;
bottom: 68px;
width: 258px;
padding: 14px;
}
.count-row strong {
font-size: 24px;
}
.help {
left: 12px;
right: 12px;
bottom: 12px;
transform: none;
overflow: hidden;
text-overflow: ellipsis;
}
}
@media (max-height: 650px) {
.telemetry {
transform: scale(0.84);
transform-origin: top right;
}
.brand {
transform: scale(0.9);
transform-origin: top left;
}
}
</style>
</head>
<body>
<main id="app"></main>
<header class="hud brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>PUNCHLAB</h1>
<p>Binary selection instrument / 160 position</p>
</div>
</header>
<aside class="hud telemetry" aria-label="Binary selection monitor">
<div class="eyebrow">Selection matrix</div>
<div class="count-row">
<strong id="activeCount">000</strong>
<span>/ 160 bits active</span>
</div>
<div class="meter">
<div class="meter-fill" id="meterFill"></div>
</div>
<div id="bitRows"></div>
<div class="legend">
<span><i class="selected"></i>1 / punched</span>
<span><i class="unselected"></i>0 / retained</span>
</div>
<div class="actions">
<button id="resetButton" type="button">Reset</button>
<button id="randomButton" type="button">Randomize</button>
</div>
</aside>
<div class="hud help">
<b>Drag</b> to orbit · <b>Scroll / pinch</b> to zoom ·
<b>Click</b> a position to toggle its bit
</div>
<div id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.querySelector("#app");
const activeCountElement = document.querySelector("#activeCount");
const meterFill = document.querySelector("#meterFill");
const bitRowsElement = document.querySelector("#bitRows");
const toast = document.querySelector("#toast");
const COLS = 16;
const ROWS = 10;
const TOTAL = COLS * ROWS;
const CARD_W = 14;
const CARD_H = 9;
const CARD_DEPTH = 0.14;
const BEVEL_THICKNESS = 0.025;
const TOP_Z = CARD_DEPTH + BEVEL_THICKNESS;
const GRID_LEFT = -6.225;
const GRID_TOP = 3.24;
const STEP_X = 0.83;
const STEP_Y = 0.72;
const HOLE_RADIUS = 0.13;
const INITIAL_PATTERN = [
"0011010010110100",
"1011001101001011",
"1100100101100011",
"0010111010010100",
"1001100011011010",
"0110011010100101",
"1110001011010010",
"0101100100111100",
"1010010111000101",
"0011011001010011"
];
let bits = INITIAL_PATTERN.map((row) =>
Array.from(row, (character) => Number(character))
);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111d);
scene.fog = new THREE.FogExp2(0x07111d, 0.026);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
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 three-dimensional binary punched card"
);
app.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xc8e8ff, 0x332619, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe5bc, 3.4);
keyLight.position.set(5, 12, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x64d8ff, 24, 35, 2);
cyanLight.position.set(-8, 5, -6);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xffb76c, 15, 28, 2);
amberLight.position.set(8, 4, 7);
scene.add(amberLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0x08131f,
roughness: 0.93,
metalness: 0.06
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
const floorGrid = new THREE.GridHelper(
36,
36,
0x345568,
0x1a3345
);
floorGrid.position.y = 0.002;
floorGrid.material.transparent = true;
floorGrid.material.opacity = 0.23;
floorGrid.material.depthWrite = false;
scene.add(floorGrid);
const cardWorld = new THREE.Group();
cardWorld.position.set(-0.55, 0.38, 0);
cardWorld.rotation.y = -0.065;
scene.add(cardWorld);
const cardTilt = new THREE.Group();
cardTilt.rotation.x = -Math.PI / 2;
cardWorld.add(cardTilt);
const frontMaterial = new THREE.MeshStandardMaterial({
color: 0xf1e3c8,
roughness: 0.67,
metalness: 0.015
});
const edgeMaterial = new THREE.MeshStandardMaterial({
color: 0xc5aa7d,
roughness: 0.58,
metalness: 0.02
});
const cavityMaterial = new THREE.MeshStandardMaterial({
color: 0x211910,
roughness: 0.95,
metalness: 0,
side: THREE.DoubleSide
});
const cavityBottomMaterial = new THREE.MeshBasicMaterial({
color: 0x080706,
side: THREE.DoubleSide
});
const unselectedMaterial = new THREE.MeshBasicMaterial({
color: 0xb39d7e,
transparent: true,
opacity: 0.64,
depthWrite: false,
side: THREE.DoubleSide
});
const overlayCanvas = document.createElement("canvas");
overlayCanvas.width = 2048;
overlayCanvas.height = Math.round((2048 * CARD_H) / CARD_W);
const overlayTexture = new THREE.CanvasTexture(overlayCanvas);
overlayTexture.colorSpace = THREE.SRGBColorSpace;
overlayTexture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
const overlayMaterial = new THREE.MeshBasicMaterial({
map: overlayTexture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
});
const overlay = new THREE.Mesh(
new THREE.PlaneGeometry(CARD_W, CARD_H),
overlayMaterial
);
overlay.position.z = TOP_Z + 0.012;
overlay.renderOrder = 3;
cardTilt.add(overlay);
const pickPlane = new THREE.Mesh(
new THREE.PlaneGeometry(CARD_W, CARD_H),
new THREE.MeshBasicMaterial({
visible: false,
side: THREE.DoubleSide
})
);
pickPlane.position.z = TOP_Z + 0.02;
cardTilt.add(pickPlane);
let cardMesh = null;
let cavityMesh = null;
let cavityBottomMesh = null;
let unselectedMesh = null;
function cellPosition(column, row) {
return {
x: GRID_LEFT + column * STEP_X,
y: GRID_TOP - row * STEP_Y
};
}
function createCardShape() {
const halfWidth = CARD_W / 2;
const halfHeight = CARD_H / 2;
const radius = 0.42;
const clippedCorner = 0.78;
const shape = new THREE.Shape();
shape.moveTo(-halfWidth + clippedCorner, -halfHeight);
shape.lineTo(halfWidth - radius, -halfHeight);
shape.quadraticCurveTo(
halfWidth,
-halfHeight,
halfWidth,
-halfHeight + radius
);
shape.lineTo(halfWidth, halfHeight - radius);
shape.quadraticCurveTo(
halfWidth,
halfHeight,
halfWidth - radius,
halfHeight
);
shape.lineTo(-halfWidth + clippedCorner, halfHeight);
shape.lineTo(-halfWidth, halfHeight - clippedCorner);
shape.lineTo(-halfWidth, -halfHeight + radius);
shape.quadraticCurveTo(
-halfWidth,
-halfHeight,
-halfWidth + radius,
-halfHeight
);
shape.closePath();
for (let row = 0; row < ROWS; row++) {
for (let column = 0; column < COLS; column++) {
if (!bits[row][column]) continue;
const { x, y } = cellPosition(column, row);
const hole = new THREE.Path();
hole.absarc(x, y, HOLE_RADIUS, 0, Math.PI * 2, true);
shape.holes.push(hole);
}
}
return shape;
}
function removeDynamicMesh(mesh) {
if (!mesh) return;
cardTilt.remove(mesh);
mesh.geometry.dispose();
}
function rebuildCard() {
removeDynamicMesh(cardMesh);
removeDynamicMesh(cavityMesh);
removeDynamicMesh(cavityBottomMesh);
removeDynamicMesh(unselectedMesh);
const geometry = new THREE.ExtrudeGeometry(createCardShape(), {
depth: CARD_DEPTH,
steps: 1,
curveSegments: 8,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.018,
bevelThickness: BEVEL_THICKNESS,
bevelOffset: 0
});
geometry.computeVertexNormals();
cardMesh = new THREE.Mesh(geometry, [frontMaterial, edgeMaterial]);
cardMesh.castShadow = true;
cardMesh.receiveShadow = true;
cardTilt.add(cardMesh);
const selectedCells = [];
const unselectedCells = [];
for (let row = 0; row < ROWS; row++) {
for (let column = 0; column < COLS; column++) {
const position = cellPosition(column, row);
(bits[row][column] ? selectedCells : unselectedCells).push(position);
}
}
const dummy = new THREE.Object3D();
cavityMesh = new THREE.InstancedMesh(
new THREE.CylinderGeometry(
HOLE_RADIUS * 0.96,
HOLE_RADIUS * 0.96,
0.16,
18,
1,
true
),
cavityMaterial,
Math.max(1, selectedCells.length)
);
cavityBottomMesh = new THREE.InstancedMesh(
new THREE.CircleGeometry(HOLE_RADIUS * 0.96, 18),
cavityBottomMaterial,
Math.max(1, selectedCells.length)
);
const cylinderRotation = new THREE.Quaternion().setFromEuler(
new THREE.Euler(Math.PI / 2, 0, 0)
);
selectedCells.forEach((position, index) => {
dummy.position.set(position.x, position.y, 0.063);
dummy.quaternion.copy(cylinderRotation);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
cavityMesh.setMatrixAt(index, dummy.matrix);
dummy.position.set(position.x, position.y, -0.019);
dummy.quaternion.identity();
dummy.updateMatrix();
cavityBottomMesh.setMatrixAt(index, dummy.matrix);
});
cavityMesh.count = selectedCells.length;
cavityBottomMesh.count = selectedCells.length;
cavityMesh.instanceMatrix.needsUpdate = true;
cavityBottomMesh.instanceMatrix.needsUpdate = true;
cavityMesh.frustumCulled = false;
cavityBottomMesh.frustumCulled = false;
cardTilt.add(cavityMesh, cavityBottomMesh);
unselectedMesh = new THREE.InstancedMesh(
new THREE.RingGeometry(0.088, 0.105, 24),
unselectedMaterial,
Math.max(1, unselectedCells.length)
);
unselectedCells.forEach((position, index) => {
dummy.position.set(position.x, position.y, TOP_Z + 0.006);
dummy.quaternion.identity();
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
unselectedMesh.setMatrixAt(index, dummy.matrix);
});
unselectedMesh.count = unselectedCells.length;
unselectedMesh.instanceMatrix.needsUpdate = true;
unselectedMesh.frustumCulled = false;
unselectedMesh.renderOrder = 2;
cardTilt.add(unselectedMesh);
drawOverlay();
}
function drawOverlay() {
const context = overlayCanvas.getContext("2d");
const width = overlayCanvas.width;
const height = overlayCanvas.height;
const px = (x) => ((x + CARD_W / 2) / CARD_W) * width;
const py = (y) => ((CARD_H / 2 - y) / CARD_H) * height;
context.clearRect(0, 0, width, height);
// Subtle printed-paper fibers.
let seed = 87231;
const random = () => {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
};
for (let index = 0; index < 360; index++) {
const opacity = 0.012 + random() * 0.025;
context.fillStyle = `rgba(84, 58, 35, ${opacity})`;
const size = 0.5 + random() * 2;
context.fillRect(
random() * width,
random() * height,
size,
size
);
}
// Header.
context.fillStyle = "#60452f";
context.font =
"700 27px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
context.textAlign = "left";
context.textBaseline = "middle";
context.fillText("SELECTA / PUNCH MATRIX", px(-6.55), py(4.1));
context.fillStyle = "#a7503d";
context.fillRect(px(5.65), py(4.1) - 7, px(0.9) - px(0), 14);
context.textAlign = "right";
context.font =
"600 17px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
context.fillStyle = "#80684f";
context.fillText("16 × 10 / REV 04", px(5.45), py(4.1));
context.strokeStyle = "rgba(83, 57, 35, 0.35)";
context.lineWidth = 2;
context.beginPath();
context.moveTo(px(-6.55), py(3.82));
context.lineTo(px(6.55), py(3.82));
context.stroke();
// Grid.
context.strokeStyle = "rgba(89, 62, 39, 0.18)";
context.lineWidth = 1.25;
const left = GRID_LEFT - STEP_X / 2;
const top = GRID_TOP + STEP_Y / 2;
for (let column = 0; column <= COLS; column++) {
const x = px(left + column * STEP_X);
context.beginPath();
context.moveTo(x, py(top));
context.lineTo(x, py(top - ROWS * STEP_Y));
context.stroke();
}
for (let row = 0; row <= ROWS; row++) {
const y = py(top - row * STEP_Y);
context.beginPath();
context.moveTo(px(left), y);
context.lineTo(px(left + COLS * STEP_X), y);
context.stroke();
}
// Remove printed grid pixels from the punched openings.
context.save();
context.globalCompositeOperation = "destination-out";
for (let row = 0; row < ROWS; row++) {
for (let column = 0; column < COLS; column++) {
if (!bits[row][column]) continue;
const position = cellPosition(column, row);
const radius = (HOLE_RADIUS / CARD_W) * width + 7;
context.beginPath();
context.arc(
px(position.x),
py(position.y),
radius,
0,
Math.PI * 2
);
context.fill();
}
}
context.restore();
// Row and column identifiers.
context.fillStyle = "rgba(83, 58, 37, 0.62)";
context.font =
"600 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
context.textAlign = "right";
context.textBaseline = "middle";
for (let row = 0; row < ROWS; row++) {
const y = GRID_TOP - row * STEP_Y;
context.fillText(
String(row).padStart(2, "0"),
px(left - 0.15),
py(y)
);
}
context.textAlign = "center";
for (let column = 0; column < COLS; column++) {
const x = GRID_LEFT + column * STEP_X;
context.fillText(
String(column).padStart(2, "0"),
px(x),
py(3.73)
);
}
// Printed binary value beside every position.
context.font =
"700 17px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
context.textAlign = "left";
context.textBaseline = "middle";
for (let row = 0; row < ROWS; row++) {
for (let column = 0; column < COLS; column++) {
const position = cellPosition(column, row);
context.fillStyle = bits[row][column]
? "rgba(104, 61, 32, 0.88)"
: "rgba(112, 91, 69, 0.48)";
context.fillText(
bits[row][column] ? "1" : "0",
px(position.x) + 27,
py(position.y) + 15
);
}
}
// Footer and miniature payload barcode.
context.strokeStyle = "rgba(83, 57, 35, 0.30)";
context.lineWidth = 1.5;
context.beginPath();
context.moveTo(px(-6.55), py(-3.92));
context.lineTo(px(6.55), py(-3.92));
context.stroke();
context.fillStyle = "#72583e";
context.font =
"600 15px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
context.textAlign = "left";
context.fillText(
"PUNCH POSITION // 00 = RETAIN / 01 = PERFORATE",
px(-6.55),
py(-4.18)
);
const flatBits = bits.flat();
for (let index = 0; index < 64; index++) {
const active = flatBits[index];
context.fillStyle = active
? "rgba(74, 47, 27, 0.86)"
: "rgba(74, 47, 27, 0.17)";
context.fillRect(
px(4.65) + index * 5.5,
py(-4.28),
2.5,
active ? 17 : 7
);
}
overlayTexture.needsUpdate = true;
}
function countActiveBits() {
return bits.reduce(
(sum, row) => sum + row.reduce((rowSum, bit) => rowSum + bit, 0),
0
);
}
function updateInterface() {
const count = countActiveBits();
activeCountElement.textContent = String(count).padStart(3, "0");
meterFill.style.width = `${(count / TOTAL) * 100}%`;
bitRowsElement.replaceChildren();
bits.forEach((row, rowIndex) => {
const rowElement = document.createElement("div");
rowElement.className = "bit-row";
const label = document.createElement("span");
label.className = "row-label";
label.textContent = String(rowIndex).padStart(2, "0");
rowElement.appendChild(label);
row.forEach((bit, columnIndex) => {
const button = document.createElement("button");
button.type = "button";
button.className = `bit${bit ? " active" : ""}`;
button.setAttribute(
"aria-label",
`Row ${rowIndex}, column ${columnIndex}, value ${bit}`
);
button.title = `R${String(rowIndex).padStart(2, "0")}:C${String(
columnIndex
).padStart(2, "0")} = ${bit}`;
button.addEventListener("click", () => {
toggleCell(rowIndex, columnIndex);
});
rowElement.appendChild(button);
});
bitRowsElement.appendChild(rowElement);
});
}
let toastTimer = 0;
function showToast(message) {
toast.textContent = message;
toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toast.classList.remove("visible");
}, 1000);
}
function toggleCell(row, column) {
bits[row][column] = bits[row][column] ? 0 : 1;
rebuildCard();
updateInterface();
showToast(
`R${String(row).padStart(2, "0")}:C${String(column).padStart(2, "0")} → ${
bits[row][column]
}`
);
}
document.querySelector("#resetButton").addEventListener("click", () => {
bits = INITIAL_PATTERN.map((row) =>
Array.from(row, (character) => Number(character))
);
rebuildCard();
updateInterface();
showToast("PATTERN RESET");
});
document.querySelector("#randomButton").addEventListener("click", () => {
bits = Array.from({ length: ROWS }, () =>
Array.from({ length: COLS }, () => (Math.random() < 0.54 ? 1 : 0))
);
rebuildCard();
updateInterface();
showToast("NEW RANDOM PAYLOAD");
});
// Atmospheric particles.
const particleCount = 280;
const particlePositions = new Float32Array(particleCount * 3);
for (let index = 0; index < particleCount; index++) {
particlePositions[index * 3] = (Math.random() - 0.5) * 32;
particlePositions[index * 3 + 1] = Math.random() * 11 + 0.2;
particlePositions[index * 3 + 2] = (Math.random() - 0.5) * 30;
}
const particleGeometry = new THREE.BufferGeometry();
particleGeometry.setAttribute(
"position",
new THREE.BufferAttribute(particlePositions, 3)
);
const particles = new THREE.Points(
particleGeometry,
new THREE.PointsMaterial({
color: 0x8bcfe2,
size: 0.025,
transparent: true,
opacity: 0.3,
depthWrite: false
})
);
scene.add(particles);
// Custom orbit camera controls.
const orbit = {
theta: 0.61,
phi: 0.72,
radius: window.innerWidth < 760 ? 19 : 16.4
};
const desiredOrbit = {
theta: orbit.theta,
phi: orbit.phi,
radius: orbit.radius
};
const cameraTarget = new THREE.Vector3();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const activePointers = new Map();
let dragPointerId = null;
let dragTravel = 0;
let previousPinchDistance = 0;
function updateCamera() {
const horizontalRadius =
orbit.radius * Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + horizontalRadius * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + horizontalRadius * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
}
function pointerDistance() {
const points = [...activePointers.values()];
if (points.length < 2) return 0;
return Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
renderer.domElement.setPointerCapture(event.pointerId);
if (activePointers.size === 1) {
dragPointerId = event.pointerId;
dragTravel = 0;
} else if (activePointers.size === 2) {
previousPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = activePointers.get(event.pointerId);
if (!previous) return;
const deltaX = event.clientX - previous.x;
const deltaY = event.clientY - previous.y;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1 && event.pointerId === dragPointerId) {
desiredOrbit.theta -= deltaX * 0.006;
desiredOrbit.phi = THREE.MathUtils.clamp(
desiredOrbit.phi - deltaY * 0.005,
0.32,
1.38
);
dragTravel += Math.hypot(deltaX, deltaY);
} else if (activePointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
desiredOrbit.radius = THREE.MathUtils.clamp(
desiredOrbit.radius * (previousPinchDistance / distance),
9,
25
);
}
previousPinchDistance = distance;
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
const wasClick =
activePointers.size === 1 &&
event.pointerId === dragPointerId &&
dragTravel < 6;
activePointers.delete(event.pointerId);
previousPinchDistance = 0;
if (wasClick) {
toggleFromPointer(event.clientX, event.clientY);
}
if (activePointers.size === 1) {
dragPointerId = [...activePointers.keys()][0];
dragTravel = 0;
} else if (activePointers.size === 0) {
dragPointerId = null;
}
});
renderer.domElement.addEventListener("pointercancel", (event) => {
activePointers.delete(event.pointerId);
previousPinchDistance = 0;
if (activePointers.size === 1) {
dragPointerId = [...activePointers.keys()][0];
} else {
dragPointerId = null;
}
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredOrbit.radius = THREE.MathUtils.clamp(
desiredOrbit.radius * Math.exp(event.deltaY * 0.001),
9,
25
);
},
{ passive: false }
);
function toggleFromPointer(clientX, clientY) {
const rectangle = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rectangle.left) / rectangle.width) * 2 - 1;
pointer.y = -((clientY - rectangle.top) / rectangle.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObject(pickPlane, false)[0];
if (!hit) return;
const localPoint = cardTilt.worldToLocal(hit.point.clone());
const column = Math.round((localPoint.x - GRID_LEFT) / STEP_X);
const row = Math.round((GRID_TOP - localPoint.y) / STEP_Y);
if (
row >= 0 &&
row < ROWS &&
column >= 0 &&
column < COLS
) {
toggleCell(row, column);
}
}
renderer.domElement.addEventListener("dblclick", () => {
desiredOrbit.theta = 0.61;
desiredOrbit.phi = 0.72;
desiredOrbit.radius = window.innerWidth < 760 ? 19 : 16.4;
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = width < 760 ? 52 : 42;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
rebuildCard();
updateInterface();
resize();
updateCamera();
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const smoothing = 0.09;
orbit.theta += (desiredOrbit.theta - orbit.theta) * smoothing;
orbit.phi += (desiredOrbit.phi - orbit.phi) * smoothing;
orbit.radius += (desiredOrbit.radius - orbit.radius) * smoothing;
cardWorld.position.y = 0.38 + Math.sin(elapsed * 0.78) * 0.045;
particles.rotation.y = elapsed * 0.012;
particles.position.y = Math.sin(elapsed * 0.17) * 0.08;
cameraTarget.set(cardWorld.position.x, 0.34, 0);
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```