Prompt specification
Build or customize the Three.js 3D scene "Pattern weaving from a card sequence" 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: Pattern weaving from a card sequence
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/pattern-weaving-from-a-card-sequence-x2499
Scene Description Prompt:
Use Three.js from cdnjs to build a compact loom scene with a loop of cards, warp, shuttle, and growing fabric. Use an original geometric design and synchronize each woven row with its card. Deliver one self-contained HTML file with visible voxel blocks.
Working Three.js Starter (pattern-weaving-from-a-card-sequence-x2499):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tessera Loom — Geometric Card Weaving</title>
<style>
:root {
--ink: #e9f2f4;
--muted: #8da3ad;
--cyan: #53e0d0;
--coral: #ff705f;
--amber: #f4bd57;
--panel: rgba(9, 18, 27, 0.72);
--line: rgba(140, 206, 211, 0.2);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 38%, #172c3b 0%, #0b1621 43%, #050a11 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
z-index: 5;
pointer-events: none;
}
.brand {
top: 28px;
left: 30px;
max-width: 360px;
}
.eyebrow {
color: var(--cyan);
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.brand h1 {
margin: 8px 0 7px;
font-size: clamp(25px, 3.1vw, 43px);
line-height: 0.95;
letter-spacing: -0.055em;
font-weight: 760;
}
.brand h1 span {
color: var(--cyan);
font-weight: 350;
}
.brand p {
margin: 0;
max-width: 320px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.live {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 14px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(8, 16, 24, 0.45);
color: #b9c9cf;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.15em;
}
.live i {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 0 12px var(--coral);
animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
50% { opacity: 0.35; transform: scale(0.72); }
}
.reader {
top: 27px;
right: 28px;
width: 242px;
padding: 16px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 20px 70px rgba(0,0,0,.25);
backdrop-filter: blur(16px);
}
.reader-head {
display: flex;
align-items: center;
justify-content: space-between;
color: var(--muted);
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .15em;
}
.reader-head b {
color: var(--cyan);
font-size: 11px;
}
.card-preview {
position: relative;
margin: 14px 0 12px;
padding: 12px 12px 11px;
overflow: hidden;
border-radius: 10px;
color: #172028;
background:
linear-gradient(135deg, rgba(255,255,255,.48), transparent 42%),
#e7d9b9;
box-shadow: 0 10px 30px rgba(0,0,0,.28);
transform: rotate(1.5deg);
}
.card-preview::after {
content: "";
position: absolute;
inset: 5px;
border: 1px solid rgba(29, 39, 41, .17);
border-radius: 6px;
pointer-events: none;
}
.card-preview .serial {
display: flex;
justify-content: space-between;
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .08em;
}
.punch-grid {
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 5px;
margin: 13px 0 12px;
padding: 0 3px;
}
.punch-grid span {
aspect-ratio: 1;
border-radius: 50%;
background: rgba(25,35,39,.15);
box-shadow: inset 0 1px 2px rgba(0,0,0,.25);
transition: background .2s, transform .2s;
}
.punch-grid span.punched {
background: #17232a;
transform: scale(.9);
box-shadow: inset 0 2px 2px rgba(0,0,0,.6), 0 0 0 1px rgba(255,255,255,.18);
}
.card-caption {
display: flex;
justify-content: space-between;
color: rgba(23,32,40,.65);
font: 800 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .12em;
}
.sync-line {
display: flex;
align-items: center;
justify-content: space-between;
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .11em;
}
.sync-line strong {
color: var(--ink);
font-size: 11px;
}
.status {
left: 29px;
bottom: 28px;
width: 286px;
padding: 14px 15px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
backdrop-filter: blur(14px);
}
.status-top {
display: flex;
justify-content: space-between;
align-items: flex-end;
}
.status-label {
color: var(--muted);
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .16em;
}
#statusValue {
margin-top: 5px;
font-size: 19px;
font-weight: 720;
letter-spacing: -.025em;
}
#phaseValue {
color: var(--cyan);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .12em;
}
.progress {
height: 3px;
margin-top: 12px;
overflow: hidden;
border-radius: 3px;
background: rgba(255,255,255,.08);
}
#progressFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), var(--coral));
box-shadow: 0 0 12px rgba(83,224,208,.55);
}
.phase-track {
left: 50%;
bottom: 31px;
display: flex;
gap: 5px;
transform: translateX(-50%);
}
.phase-track span {
min-width: 74px;
padding: 8px 10px;
border: 1px solid rgba(141,163,173,.13);
border-radius: 999px;
background: rgba(7,14,22,.48);
color: #708792;
text-align: center;
font: 700 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .13em;
transition: .2s;
}
.phase-track span.active {
color: #081318;
border-color: var(--cyan);
background: var(--cyan);
box-shadow: 0 0 24px rgba(83,224,208,.22);
}
.controls {
right: 28px;
bottom: 29px;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 9px;
color: var(--muted);
font: 700 9px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .08em;
}
#resetButton {
pointer-events: auto;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(10,19,27,.65);
color: #bdd0d6;
cursor: pointer;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .11em;
transition: .2s;
}
#resetButton:hover {
color: var(--cyan);
border-color: rgba(83,224,208,.55);
transform: translateY(-1px);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #071019;
color: var(--cyan);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .2em;
transition: opacity .5s;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.brand { top: 20px; left: 20px; }
.brand p { display: none; }
.reader { top: 18px; right: 18px; width: 190px; padding: 12px; }
.card-preview { margin: 10px 0; padding: 10px; }
.punch-grid { gap: 3px; margin: 10px 0; }
.status { left: 18px; bottom: 18px; width: 235px; }
.controls { right: 18px; bottom: 18px; }
.controls .hint { display: none; }
.phase-track { display: none; }
}
@media (max-width: 470px) {
.reader { width: 154px; }
.card-caption, .sync-line span { display: none; }
.brand h1 { font-size: 25px; }
.brand .live { display: none; }
.status { width: 205px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional card loom"></canvas>
<header class="hud brand">
<div class="eyebrow">Geometric card weaving / 24</div>
<h1>TESSERA <span>LOOM</span></h1>
<p>A continuous punch-card loop drives a shuttle through an original stepped-diamond textile. Every completed row remains paired with its source card.</p>
<div class="live"><i></i> CARD LOOP ONLINE</div>
</header>
<aside class="hud reader">
<div class="reader-head">
<span>ACTIVE PUNCH</span>
<b id="cardNumber">C09</b>
</div>
<div class="card-preview">
<div class="serial">
<span>TESSERA</span>
<span id="previewNumber">09 / 24</span>
</div>
<div class="punch-grid" id="punchGrid"></div>
<div class="card-caption">
<span>12 WARP CHANNELS</span>
<span>STEP / DIAMOND</span>
</div>
</div>
<div class="sync-line">
<span>ROW ↔ CARD</span>
<strong id="syncValue">09 ↔ 09</strong>
</div>
</aside>
<section class="hud status">
<div class="status-top">
<div>
<div class="status-label">WEFT PROGRESS</div>
<div id="statusValue">ROW 09 / 24</div>
</div>
<div id="phaseValue">PICK</div>
</div>
<div class="progress"><div id="progressFill"></div></div>
</section>
<div class="hud phase-track">
<span id="pickPhase">01 PICK</span>
<span id="passPhase">02 PASS</span>
<span id="beatPhase">03 BEAT</span>
</div>
<div class="hud controls">
<div class="hint">DRAG TO ORBIT · SCROLL TO ZOOM<br>DOUBLE-CLICK TO RESET VIEW</div>
<button id="resetButton">RESTART CLOTH</button>
</div>
<div id="loading">THREADING LOOM…</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
const canvas = document.getElementById('scene');
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: 'high-performance'
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x08131e, 14, 28);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraState = {
yaw: 0.69,
pitch: 0.43,
radius: 13.4,
target: new THREE.Vector3(0, 2.55, 0)
};
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function updateCamera() {
const { yaw, pitch, radius, target } = cameraState;
camera.position.set(
target.x + radius * Math.cos(pitch) * Math.sin(yaw),
target.y + radius * Math.sin(pitch),
target.z + radius * Math.cos(pitch) * Math.cos(yaw)
);
camera.lookAt(target);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0x9fc7dc, 0x18202b, 1.35));
const keyLight = new THREE.DirectionalLight(0xffe4c1, 3.2);
keyLight.position.set(5.5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0006;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x55d8ef, 1.8);
rimLight.position.set(-7, 6, -5);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xff705f, 22, 9, 2);
warmFill.position.set(3.5, 2.2, 4);
scene.add(warmFill);
const material = {
frame: new THREE.MeshStandardMaterial({
color: 0x382a29, roughness: 0.42, metalness: 0.32
}),
frameDark: new THREE.MeshStandardMaterial({
color: 0x17222c, roughness: 0.34, metalness: 0.68
}),
brass: new THREE.MeshStandardMaterial({
color: 0xc48d45, roughness: 0.3, metalness: 0.72,
emissive: 0x281507, emissiveIntensity: 0.3
}),
cyan: new THREE.MeshStandardMaterial({
color: 0x69e5d6, emissive: 0x2bbcac,
emissiveIntensity: 1.25, roughness: 0.28, metalness: 0.45
}),
coral: new THREE.MeshStandardMaterial({
color: 0xff705f, emissive: 0xb72f24,
emissiveIntensity: 0.55, roughness: 0.36, metalness: 0.35
}),
platform: new THREE.MeshStandardMaterial({
color: 0x101b25, roughness: 0.76, metalness: 0.18
}),
floor: new THREE.MeshStandardMaterial({
color: 0x071019, roughness: 0.9, metalness: 0.05
})
};
const fabricColors = [
0x354f8e,
0x43d7c5,
0xff705f,
0xf4bd57,
0x9d7cff,
0xf0e3c5
];
const fabricMaterials = fabricColors.map((color, index) =>
new THREE.MeshStandardMaterial({
color,
roughness: index === 5 ? 0.72 : 0.43,
metalness: index === 1 ? 0.22 : 0.08,
emissive: color,
emissiveIntensity: index === 1 || index === 2 ? 0.08 : 0.025
})
);
function box(parent, width, height, depth, mat, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const floor = new THREE.Mesh(
new THREE.CircleGeometry(13, 96),
material.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.29;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 48, 0x31505a, 0x162a33);
grid.position.y = -0.275;
grid.material.transparent = true;
grid.material.opacity = 0.24;
scene.add(grid);
const platform = box(scene, 10.8, 0.28, 6.6, material.platform, 0, -0.13, 0);
platform.receiveShadow = true;
box(scene, 9.8, 0.045, 5.8,
new THREE.MeshStandardMaterial({ color: 0x1a2b35, roughness: 0.58 }),
0, 0.025, 0
);
const loom = new THREE.Group();
scene.add(loom);
const postX = 3.12;
const postZ = 0.67;
for (const x of [-postX, postX]) {
for (const z of [-postZ, postZ]) {
box(loom, 0.25, 4.95, 0.25, material.frame, x, 2.88, z);
box(loom, 0.37, 0.12, 0.37, material.brass, x, 0.48, z);
}
box(loom, 0.26, 0.28, 1.65, material.frame, x, 5.25, 0);
box(loom, 0.27, 0.27, 1.65, material.frame, x, 0.55, 0);
const brace = box(
loom, 1.52, 0.13, 0.14, material.frameDark,
x + (x < 0 ? 0.55 : -0.55), 4.76, 0.69
);
brace.rotation.z = x < 0 ? -0.46 : 0.46;
}
for (const z of [-postZ, postZ]) {
box(loom, 6.55, 0.3, 0.3, material.frame, 0, 5.25, z);
box(loom, 6.55, 0.27, 0.27, material.frame, 0, 0.55, z);
}
const lowerRoll = new THREE.Mesh(
new THREE.CylinderGeometry(0.17, 0.17, 5.95, 20),
material.brass
);
lowerRoll.rotation.z = Math.PI / 2;
lowerRoll.position.set(0, 0.66, 0.18);
lowerRoll.castShadow = true;
loom.add(lowerRoll);
const reed = new THREE.Group();
loom.add(reed);
box(reed, 5.7, 0.075, 0.1, material.brass, 0, 5.01, 0.1);
box(reed, 5.7, 0.045, 0.07, material.cyan, 0, 4.88, 0.15);
const warpMaterial = new THREE.MeshStandardMaterial({
color: 0xd8c9a7,
roughness: 0.72,
metalness: 0.02,
transparent: true,
opacity: 0.64
});
const warpGeometry = new THREE.CylinderGeometry(0.012, 0.012, 4.32, 6);
const COLS = 12;
const ROWS = 24;
const fabricBaseY = 0.79;
const rowHeight = 0.146;
const columnSpacing = 0.315;
const fabricLeft = -((COLS - 1) * columnSpacing) / 2;
const fabricRight = -fabricLeft;
for (let col = 0; col < COLS; col++) {
const x = fabricLeft + col * columnSpacing;
const warp = new THREE.Mesh(warpGeometry, warpMaterial);
warp.position.set(x, 2.87, 0.105);
loom.add(warp);
const hedle = box(
reed, 0.035, 0.48, 0.035,
col % 2 ? material.brass : material.cyan,
x, 5.13, col % 2 ? 0.01 : 0.12
);
hedle.castShadow = false;
}
function designColor(row, col) {
const u = Math.abs(col - (COLS - 1) / 2) / ((COLS - 1) / 2);
const v = Math.abs(row - (ROWS - 1) / 2) / 10;
const diamond = u + v * 0.92;
if (diamond < 0.30) return 2;
if (diamond < 0.50) return 5;
if (Math.abs(u - v * 0.94) < 0.13) return 1;
if (u > 0.80) return 4;
if ((row + col * 2) % 7 === 0) return 3;
return 0;
}
const fabricRoot = new THREE.Group();
fabricRoot.position.y = fabricBaseY;
scene.add(fabricRoot);
const blockGeometry = new THREE.BoxGeometry(0.266, 0.128, 0.18);
const rowGroups = new Map();
function createFabricRow(row, complete = true) {
const group = new THREE.Group();
group.userData.cells = [];
group.userData.complete = complete;
for (let col = 0; col < COLS; col++) {
const colorIndex = designColor(row % ROWS, col);
const block = new THREE.Mesh(blockGeometry, fabricMaterials[colorIndex]);
const x = fabricLeft + col * columnSpacing;
const z = 0.355 + ((row + col) % 2) * 0.008;
block.position.set(x, row * rowHeight, z);
block.castShadow = true;
block.receiveShadow = true;
block.userData.revealAt = col / (COLS - 1);
block.userData.targetScale = complete ? 1 : 0;
block.visible = complete;
block.scale.setScalar(complete ? 1 : 0.001);
group.add(block);
group.userData.cells.push(block);
}
fabricRoot.add(group);
rowGroups.set(row, group);
return group;
}
function clearFabric() {
for (const group of rowGroups.values()) {
fabricRoot.remove(group);
}
rowGroups.clear();
fabricRoot.scale.set(1, 1, 1);
}
for (let row = 0; row < 8; row++) {
createFabricRow(row, true);
}
let rowCycle = 8;
let phase = 0;
let cycleDuration = 2.25;
let clothState = 'weaving';
let completeTimer = 0;
let resetTimer = 0;
createFabricRow(rowCycle, false);
const shuttle = new THREE.Group();
scene.add(shuttle);
const shuttleBody = box(
shuttle, 0.55, 0.14, 0.15, material.brass, -0.06, 0, 0
);
shuttleBody.castShadow = true;
const shuttleNose = new THREE.Mesh(
new THREE.ConeGeometry(0.125, 0.29, 4),
material.coral
);
shuttleNose.rotation.z = -Math.PI / 2;
shuttleNose.rotation.y = Math.PI / 4;
shuttleNose.position.x = 0.34;
shuttleNose.castShadow = true;
shuttle.add(shuttleNose);
const spool = new THREE.Mesh(
new THREE.TorusGeometry(0.072, 0.027, 8, 18),
material.coral
);
spool.position.set(-0.22, 0.02, 0.09);
shuttle.add(spool);
const shuttleLight = new THREE.PointLight(0xff705f, 7, 2.3, 2);
shuttleLight.position.z = 0.28;
shuttle.add(shuttleLight);
const weftGeometry = new THREE.BufferGeometry();
weftGeometry.setAttribute(
'position',
new THREE.BufferAttribute(new Float32Array(6), 3)
);
const weft = new THREE.Line(
weftGeometry,
new THREE.LineBasicMaterial({ color: 0xff806d })
);
scene.add(weft);
const loopPath = new THREE.CatmullRomCurve3([
new THREE.Vector3(3.36, 2.26, 1.55),
new THREE.Vector3(4.56, 1.16, 1.02),
new THREE.Vector3(4.86, 4.82, 0.25),
new THREE.Vector3(3.18, 5.92, -0.55),
new THREE.Vector3(-3.18, 5.92, -0.55),
new THREE.Vector3(-4.86, 4.82, 0.25),
new THREE.Vector3(-4.56, 1.16, 1.02),
new THREE.Vector3(-3.36, 0.72, 1.66),
new THREE.Vector3(-1.55, 0.52, 1.95),
new THREE.Vector3(1.55, 0.52, 1.95)
], true, 'catmullrom', 0.42);
loopPath.arcLengthDivisions = 500;
const track = new THREE.Mesh(
new THREE.TubeGeometry(loopPath, 220, 0.027, 6, true),
new THREE.MeshStandardMaterial({
color: 0x4bbdb6,
emissive: 0x1b6c6a,
emissiveIntensity: 0.7,
roughness: 0.4,
metalness: 0.55
})
);
scene.add(track);
const CARD_COUNT = 24;
const cardBackGeometry = new THREE.BoxGeometry(0.65, 0.84, 0.036);
const cardFaceGeometry = new THREE.PlaneGeometry(0.65, 0.84);
const haloGeometry = new THREE.PlaneGeometry(0.76, 0.96);
const cardBackMaterial = new THREE.MeshStandardMaterial({
color: 0xdac9a6, roughness: 0.82, metalness: 0.02
});
function makeCardTexture(row) {
const c = document.createElement('canvas');
c.width = 240;
c.height = 300;
const ctx = c.getContext('2d');
const gradient = ctx.createLinearGradient(0, 0, 240, 300);
gradient.addColorStop(0, '#f0e2bf');
gradient.addColorStop(1, '#cdbd98');
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 240, 300);
ctx.strokeStyle = 'rgba(36,43,42,.25)';
ctx.lineWidth = 2;
ctx.strokeRect(9, 9, 222, 282);
ctx.fillStyle = '#1b2529';
ctx.font = '800 25px monospace';
ctx.fillText(String(row + 1).padStart(2, '0'), 18, 39);
ctx.font = '700 11px monospace';
ctx.fillStyle = 'rgba(27,37,41,.58)';
ctx.fillText('TESSERA', 148, 36);
const startX = 22;
const gapX = 17.2;
const startY = 72;
const gapY = 47;
for (let band = 0; band < 4; band++) {
for (let col = 0; col < COLS; col++) {
const x = startX + col * gapX;
const y = startY + band * gapY;
const isSignalBand = band === 2;
const signal = designColor(row, col) !== 0;
const filled = isSignalBand ? signal : ((band + col + row) % 3 !== 0);
ctx.beginPath();
ctx.arc(x, y, filled ? 5.1 : 3.1, 0, Math.PI * 2);
ctx.fillStyle = filled
? 'rgba(19,30,34,.93)'
: 'rgba(38,48,49,.18)';
ctx.fill();
if (isSignalBand && signal) {
ctx.beginPath();
ctx.arc(x, y, 7.2, 0, Math.PI * 2);
ctx.strokeStyle = 'rgba(25,40,43,.16)';
ctx.lineWidth = 1.2;
ctx.stroke();
}
}
}
ctx.fillStyle = 'rgba(28,39,41,.55)';
ctx.font = '700 10px monospace';
ctx.fillText('12 CHANNEL PUNCH', 18, 278);
ctx.fillText('24', 202, 278);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const cards = [];
for (let i = 0; i < CARD_COUNT; i++) {
const group = new THREE.Group();
const back = new THREE.Mesh(cardBackGeometry, cardBackMaterial);
back.castShadow = true;
group.add(back);
const faceMaterial = new THREE.MeshStandardMaterial({
map: makeCardTexture(i),
roughness: 0.78,
metalness: 0.02,
side: THREE.DoubleSide
});
const face = new THREE.Mesh(cardFaceGeometry, faceMaterial);
face.position.z = 0.022;
group.add(face);
const halo = new THREE.Mesh(
haloGeometry,
new THREE.MeshBasicMaterial({
color: 0x54e4d3,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
halo.position.z = -0.025;
group.add(halo);
group.userData.halo = halo;
group.userData.index = i;
scene.add(group);
cards.push(group);
}
const reader = new THREE.Group();
reader.position.copy(loopPath.getPointAt(0));
scene.add(reader);
box(reader, 0.055, 1.23, 0.07, material.cyan, -0.39, 0, 0.02);
box(reader, 0.055, 1.23, 0.07, material.cyan, 0.39, 0, 0.02);
box(reader, 0.83, 0.055, 0.07, material.cyan, 0, 0.61, 0.02);
box(reader, 0.83, 0.055, 0.07, material.cyan, 0, -0.61, 0.02);
const scanner = box(
reader, 0.7, 0.025, 0.075,
new THREE.MeshBasicMaterial({ color: 0xff806d }),
0, 0, 0.045
);
scanner.castShadow = false;
const readerLight = new THREE.PointLight(0x54e4d3, 9, 3.2, 2);
readerLight.position.set(0, 0, 0.45);
reader.add(readerLight);
const dustCount = 100;
const dustPositions = new Float32Array(dustCount * 3);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 15;
dustPositions[i * 3 + 1] = Math.random() * 8;
dustPositions[i * 3 + 2] = (Math.random() - 0.5) * 10;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
'position',
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0x8bc6cc,
size: 0.025,
transparent: true,
opacity: 0.32,
depthWrite: false
})
);
scene.add(dust);
const punchGrid = document.getElementById('punchGrid');
const punchDots = [];
for (let i = 0; i < COLS; i++) {
const dot = document.createElement('span');
punchGrid.appendChild(dot);
punchDots.push(dot);
}
const cardNumber = document.getElementById('cardNumber');
const previewNumber = document.getElementById('previewNumber');
const syncValue = document.getElementById('syncValue');
const statusValue = document.getElementById('statusValue');
const phaseValue = document.getElementById('phaseValue');
const progressFill = document.getElementById('progressFill');
const pickPhase = document.getElementById('pickPhase');
const passPhase = document.getElementById('passPhase');
const beatPhase = document.getElementById('beatPhase');
let lastPreviewRow = -1;
function updatePreview(row) {
if (row === lastPreviewRow) return;
lastPreviewRow = row;
const cardIndex = ((row % CARD_COUNT) + CARD_COUNT) % CARD_COUNT;
const shownRow = Math.min(row, ROWS - 1);
cardNumber.textContent = `C${String(cardIndex + 1).padStart(2, '0')}`;
previewNumber.textContent =
`${String(shownRow + 1).padStart(2, '0')} / ${ROWS}`;
for (let col = 0; col < COLS; col++) {
const color = designColor(shownRow, col);
const punched = color !== 0;
punchDots[col].className = punched ? 'punched' : '';
punchDots[col].style.background = punched
? ''
: 'rgba(25,35,39,.15)';
}
}
function resetCloth() {
clearFabric();
rowCycle = 0;
phase = 0;
clothState = 'weaving';
completeTimer = 0;
resetTimer = 0;
createFabricRow(rowCycle, false);
lastPreviewRow = -1;
}
document.getElementById('resetButton').addEventListener('click', resetCloth);
function easeOutBack(x) {
const c1 = 1.70158;
const c3 = c1 + 1;
return 1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2);
}
const smooth = x => x * x * (3 - 2 * x);
function updateWeaving(dt) {
if (clothState === 'complete') {
completeTimer += dt;
shuttle.position.set(fabricRight, fabricBaseY + (ROWS - 1) * rowHeight, 0.67);
if (completeTimer > 2.8) {
clothState = 'resetting';
resetTimer = 0;
}
return;
}
if (clothState === 'resetting') {
resetTimer += dt;
const t = clamp(resetTimer / 1.15, 0, 1);
fabricRoot.scale.y = 1 - smooth(t);
if (t >= 1) {
clearFabric();
rowCycle = 0;
phase = 0;
clothState = 'weaving';
createFabricRow(rowCycle, false);
lastPreviewRow = -1;
}
return;
}
phase += dt / cycleDuration;
const travel = clamp((phase - 0.06) / 0.64, 0, 1);
let shuttleX;
if (phase < 0.06) {
shuttleX = fabricLeft;
} else if (phase < 0.70) {
shuttleX = lerp(fabricLeft, fabricRight, smooth(travel));
} else if (phase < 0.91) {
const back = smooth((phase - 0.70) / 0.21);
shuttleX = lerp(fabricRight, fabricLeft, back);
} else {
shuttleX = fabricLeft;
}
const currentGroup = rowGroups.get(rowCycle);
if (currentGroup && !currentGroup.userData.complete) {
for (const block of currentGroup.userData.cells) {
const local = travel >= 0.999
? 1
: clamp((travel - block.userData.revealAt) / 0.08, 0, 1);
block.visible = local > 0;
const scale = local <= 0 ? 0.001 : easeOutBack(local);
block.scale.setScalar(scale);
}
if (travel >= 0.999) {
currentGroup.userData.complete = true;
for (const block of currentGroup.userData.cells) {
block.visible = true;
block.scale.setScalar(1);
}
}
}
const lineEnd = travel >= 0.999
? fabricRight
: lerp(fabricLeft, fabricRight, travel);
const positions = weftGeometry.attributes.position.array;
positions[0] = fabricLeft;
positions[1] = fabricBaseY + rowCycle * rowHeight;
positions[2] = 0.59;
positions[3] = lineEnd;
positions[4] = positions[1];
positions[5] = 0.59;
weftGeometry.attributes.position.needsUpdate = true;
shuttle.position.set(
shuttleX,
fabricBaseY + rowCycle * rowHeight,
0.67
);
shuttle.rotation.z = Math.sin(elapsed * 5) * 0.015;
if (phase >= 1) {
phase -= 1;
rowCycle++;
if (rowCycle >= ROWS) {
rowCycle = ROWS;
clothState = 'complete';
completeTimer = 0;
} else {
createFabricRow(rowCycle, false);
}
}
}
function updateCards() {
const head = rowCycle + phase;
const activeIndex = ((rowCycle % CARD_COUNT) + CARD_COUNT) % CARD_COUNT;
for (const card of cards) {
const index = card.userData.index;
const s = (((index - head) / CARD_COUNT) % 1 + 1) % 1;
const point = loopPath.getPointAt(s);
card.position.copy(point);
card.quaternion.copy(camera.quaternion);
card.rotateZ(Math.sin(s * Math.PI * 4) * 0.055);
const active = index === activeIndex;
const targetScale = active ? 1.075 : 0.95;
card.scale.lerp(
new THREE.Vector3(targetScale, targetScale, targetScale),
0.12
);
card.userData.halo.material.opacity = active ? 0.52 : 0;
card.userData.halo.material.color.setHex(active ? 0xff705f : 0x54e4d3);
}
reader.quaternion.copy(camera.quaternion);
scanner.position.y = Math.sin(elapsed * 4.2) * 0.47;
readerLight.intensity = 8 + Math.sin(elapsed * 4.2) * 2;
}
function updateUI() {
const activeIndex = ((rowCycle % CARD_COUNT) + CARD_COUNT) % CARD_COUNT;
const shownRow = Math.min(rowCycle, ROWS - 1);
updatePreview(shownRow);
const cycleProgress = clothState === 'complete'
? 1
: clothState === 'resetting'
? 1
: phase;
progressFill.style.width = `${cycleProgress * 100}%`;
if (clothState === 'complete') {
statusValue.textContent = 'CLOTH COMPLETE';
phaseValue.textContent = 'RESET';
syncValue.textContent = `${ROWS} ↔ ${activeIndex + 1}`;
pickPhase.classList.remove('active');
passPhase.classList.remove('active');
beatPhase.classList.remove('active');
beatPhase.classList.add('active');
return;
}
if (clothState === 'resetting') {
statusValue.textContent = 'REWINDING CLOTH';
phaseValue.textContent = 'RESET';
return;
}
statusValue.textContent = `ROW ${String(rowCycle + 1).padStart(2, '0')} / ${ROWS}`;
syncValue.textContent = `${String(rowCycle + 1).padStart(2, '0')} ↔ ${String(activeIndex + 1).padStart(2, '0')}`;
const currentPhase = phase < 0.06 ? 0 : phase < 0.70 ? 1 : 2;
const phaseNames = ['PICK', 'PASS', 'BEAT'];
phaseValue.textContent = phaseNames[currentPhase];
pickPhase.classList.toggle('active', currentPhase === 0);
passPhase.classList.toggle('active', currentPhase === 1);
beatPhase.classList.toggle('active', currentPhase === 2);
}
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener('pointerdown', event => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = 'grabbing';
});
canvas.addEventListener('pointermove', event => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = clamp(
cameraState.pitch + dy * 0.0045,
0.12,
1.12
);
});
function endDrag(event) {
dragging = false;
canvas.style.cursor = 'grab';
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener('pointerup', endDrag);
canvas.addEventListener('pointercancel', endDrag);
canvas.style.cursor = 'grab';
canvas.addEventListener('wheel', event => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius + event.deltaY * 0.008,
8.5,
19
);
}, { passive: false });
canvas.addEventListener('dblclick', () => {
cameraState.yaw = 0.69;
cameraState.pitch = 0.43;
cameraState.radius = 13.4;
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener('resize', resize);
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
updateWeaving(dt);
updateCamera();
updateCards();
updateUI();
dust.rotation.y = elapsed * 0.018;
dust.position.y = Math.sin(elapsed * 0.18) * 0.08;
renderer.render(scene, camera);
}
updateUI();
updateCards();
animate();
requestAnimationFrame(() => {
document.getElementById('loading').classList.add('hidden');
});
</script>
</body>
</html>
```