Prompt specification
Build or customize the Three.js 3D scene "Edit one card and inspect the woven result" 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: Edit one card and inspect the woven result
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/edit-one-card-and-inspect-the-woven-result-x2500
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: Edit one card and inspect the woven result. Let users toggle selected card holes before running the loom model. Highlight the changed fabric rows and connect stored instructions to repeated physical output. Return one self-contained HTML file.
Working Three.js Starter (edit-one-card-and-inspect-the-woven-result-x2500):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Loomline — Punch Card Studio</title>
<style>
:root {
--bg: #11191c;
--panel: #172225;
--panel-2: #1d2a2e;
--line: rgba(210, 231, 222, 0.12);
--muted: #8fa39f;
--text: #edf2e9;
--mint: #91d6c2;
--gold: #f0b865;
--paper: #d8c39b;
--paper-dark: #b89d72;
--shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}
* { 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;
color: inherit;
}
button:focus-visible {
outline: 2px solid var(--mint);
outline-offset: 3px;
}
.topbar {
height: 70px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 22px;
border-bottom: 1px solid var(--line);
background: #11191c;
position: relative;
z-index: 30;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 34px;
height: 34px;
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(4, 1fr);
gap: 3px;
transform: rotate(-5deg);
}
.brand-mark i {
display: block;
border-radius: 1px;
background: var(--mint);
opacity: 0.85;
}
.brand-mark i:nth-child(3n),
.brand-mark i:nth-child(7) { opacity: 0.2; }
.brand-copy { min-width: 0; }
.brand-copy strong {
display: block;
font-size: 14px;
line-height: 1;
letter-spacing: 0.22em;
white-space: nowrap;
}
.brand-copy span {
display: block;
margin-top: 7px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.14em;
text-transform: uppercase;
white-space: nowrap;
}
.header-meta {
display: flex;
align-items: center;
gap: 18px;
}
.model-label {
color: var(--muted);
font-size: 10px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.online {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 999px;
font-size: 10px;
letter-spacing: 0.11em;
text-transform: uppercase;
color: #c9d8d1;
}
.online::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 10px rgba(145, 214, 194, 0.7);
}
.mobile-toggle {
display: none;
border: 1px solid var(--line);
background: var(--panel-2);
border-radius: 8px;
padding: 9px 11px;
cursor: pointer;
font-size: 11px;
}
.workspace {
height: calc(100vh - 70px);
display: grid;
grid-template-columns: 300px minmax(420px, 1fr) 292px;
min-height: 0;
}
.panel {
min-height: 0;
overflow: auto;
scrollbar-width: thin;
scrollbar-color: #3c4b4e transparent;
background: var(--panel);
position: relative;
z-index: 10;
}
.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-thumb { background: #3c4b4e; border-radius: 8px; }
.program-panel {
border-right: 1px solid var(--line);
padding: 23px 21px 20px;
}
.inspector-panel {
border-left: 1px solid var(--line);
padding: 23px 20px 20px;
}
.eyebrow {
margin: 0 0 7px;
color: var(--mint);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1, h2, h3, p { margin-top: 0; }
.panel-title {
margin-bottom: 5px;
font-size: 19px;
line-height: 1.2;
letter-spacing: -0.025em;
font-weight: 650;
}
.panel-subtitle {
margin-bottom: 21px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 20px 0 10px;
color: #aebfba;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.section-label span:last-child {
color: #61736f;
font-weight: 500;
letter-spacing: 0.08em;
}
.card-tabs {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin-bottom: 17px;
}
.card-tab {
min-width: 0;
padding: 10px 4px 8px;
border: 1px solid var(--line);
border-radius: 9px;
background: #142023;
cursor: pointer;
transition: 160ms ease;
}
.card-tab:hover { border-color: rgba(145, 214, 194, 0.42); }
.card-tab.active {
border-color: var(--mint);
background: #20312f;
box-shadow: inset 0 0 0 1px rgba(145, 214, 194, 0.12);
}
.card-tab strong {
display: block;
margin-bottom: 7px;
font-size: 10px;
letter-spacing: 0.12em;
}
.mini-pattern {
height: 18px;
display: flex;
align-items: end;
justify-content: center;
gap: 2px;
}
.mini-pattern i {
width: 3px;
min-height: 3px;
border-radius: 2px;
background: #526560;
}
.mini-pattern i.on { background: var(--mint); }
.card-tab.changed strong::after {
content: "";
display: inline-block;
width: 4px;
height: 4px;
margin-left: 4px;
border-radius: 50%;
background: var(--gold);
vertical-align: middle;
}
.punch-card {
padding: 16px;
border-radius: 13px;
background:
linear-gradient(135deg, rgba(255,255,255,0.12), transparent 45%),
var(--paper);
color: #443b2e;
box-shadow: var(--shadow);
position: relative;
}
.punch-card::before {
content: "";
position: absolute;
inset: 8px;
border: 1px solid rgba(76, 62, 41, 0.13);
border-radius: 8px;
pointer-events: none;
}
.card-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
position: relative;
z-index: 1;
}
.card-heading strong {
font-size: 11px;
letter-spacing: 0.14em;
}
.card-heading span {
font-size: 8px;
letter-spacing: 0.1em;
opacity: 0.6;
text-transform: uppercase;
}
.hole-grid {
display: grid;
grid-template-columns: repeat(8, 1fr);
gap: 8px;
padding: 7px;
border-radius: 8px;
background: rgba(91, 72, 44, 0.08);
}
.hole {
aspect-ratio: 1;
min-width: 0;
padding: 0;
border: 0;
border-radius: 50%;
background: #c4aa7e;
box-shadow:
inset 0 2px 2px rgba(255,255,255,0.24),
inset 0 -2px 3px rgba(79, 58, 30, 0.16),
0 1px 0 rgba(255,255,255,0.25);
cursor: pointer;
position: relative;
transition: 140ms ease;
}
.hole::after {
content: "";
position: absolute;
inset: 3px;
border-radius: 50%;
background: rgba(88, 66, 36, 0.08);
}
.hole:hover {
transform: scale(1.12);
background: #ddc69c;
}
.hole.open {
background: #263034;
box-shadow:
inset 0 4px 7px rgba(0,0,0,0.62),
0 0 0 2px rgba(38,48,52,0.14),
0 0 0 3px rgba(145,214,194,0.28);
}
.hole.open::after {
inset: 5px;
background: #10191c;
box-shadow: inset 0 1px 3px #000;
}
.card-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 13px;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
position: relative;
z-index: 1;
}
.legend {
display: flex;
gap: 15px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 8px;
height: 8px;
border-radius: 50%;
background: #c4aa7e;
}
.legend i.open {
background: #172225;
box-shadow: 0 0 0 1px rgba(145,214,194,0.5);
}
.program-strip {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 5px;
}
.program-strip span {
padding: 7px 4px;
border: 1px solid var(--line);
border-radius: 6px;
color: #a7b7b2;
font-size: 9px;
text-align: center;
letter-spacing: 0.12em;
}
.program-strip span.active {
color: var(--mint);
border-color: rgba(145,214,194,0.45);
background: rgba(145,214,194,0.06);
}
.panel-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 17px;
}
.quiet-button {
padding: 10px 8px;
border: 1px solid var(--line);
border-radius: 8px;
background: transparent;
color: #a7b8b3;
font-size: 9px;
font-weight: 650;
letter-spacing: 0.09em;
text-transform: uppercase;
cursor: pointer;
transition: 150ms ease;
}
.quiet-button:hover {
border-color: rgba(145,214,194,0.42);
color: var(--text);
background: rgba(145,214,194,0.04);
}
.stage {
min-width: 0;
min-height: 0;
position: relative;
overflow: hidden;
background: #172226;
}
#canvasHost {
position: absolute;
inset: 0;
}
#canvasHost canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#canvasHost canvas:active { cursor: grabbing; }
.stage-heading {
position: absolute;
top: 22px;
left: 23px;
z-index: 4;
pointer-events: none;
}
.stage-heading .eyebrow { color: #83aa9f; }
.stage-heading h2 {
margin-bottom: 5px;
font-size: 16px;
font-weight: 550;
letter-spacing: 0.02em;
}
.stage-heading p {
margin: 0;
color: #758984;
font-size: 9px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.stage-tools {
position: absolute;
top: 20px;
right: 20px;
z-index: 5;
display: flex;
gap: 7px;
}
.tool-button {
height: 34px;
padding: 0 11px;
border: 1px solid rgba(213,235,227,0.13);
border-radius: 8px;
background: rgba(19,30,33,0.76);
backdrop-filter: blur(10px);
color: #9fb1ac;
font-size: 9px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
.tool-button:hover {
color: var(--text);
border-color: rgba(145,214,194,0.45);
}
.scene-legend {
position: absolute;
left: 22px;
bottom: 103px;
z-index: 4;
display: flex;
gap: 16px;
color: #829792;
font-size: 8px;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
}
.scene-legend span {
display: flex;
align-items: center;
gap: 6px;
}
.scene-legend i {
width: 14px;
height: 2px;
background: #73908b;
}
.scene-legend i.weft { background: #e1cfaa; }
.scene-legend i.change { background: var(--gold); }
.transport {
position: absolute;
left: 22px;
right: 22px;
bottom: 20px;
z-index: 5;
display: grid;
grid-template-columns: auto minmax(100px, 1fr) auto;
align-items: center;
gap: 15px;
padding: 12px 14px;
border: 1px solid rgba(213,235,227,0.13);
border-radius: 12px;
background: rgba(17,25,28,0.84);
backdrop-filter: blur(14px);
box-shadow: 0 12px 38px rgba(0,0,0,0.22);
}
.run-button {
display: flex;
align-items: center;
gap: 9px;
min-width: 130px;
height: 38px;
padding: 0 16px;
border: 0;
border-radius: 8px;
color: #14201e;
background: var(--mint);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
transition: 150ms ease;
}
.run-button:hover { background: #afe5d3; }
.run-button.running { background: var(--gold); }
.run-button svg {
width: 12px;
height: 12px;
fill: currentColor;
}
.progress-wrap {
min-width: 0;
}
.progress-copy {
display: flex;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
color: #8ca09b;
font-size: 8px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.progress-copy strong {
color: #c7d5d0;
font-weight: 600;
}
.progress-track {
height: 3px;
overflow: hidden;
border-radius: 4px;
background: #344246;
}
.progress-fill {
width: 0;
height: 100%;
background: linear-gradient(90deg, var(--mint), var(--gold));
transition: width 80ms linear;
}
.pick-readout {
min-width: 83px;
text-align: right;
}
.pick-readout strong {
display: block;
font-size: 17px;
font-weight: 500;
font-variant-numeric: tabular-nums;
}
.pick-readout span {
color: #758984;
font-size: 8px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.inspector-title {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
padding-bottom: 17px;
border-bottom: 1px solid var(--line);
}
.inspector-title .panel-title { margin-bottom: 0; }
.active-code {
min-width: 47px;
padding: 8px 9px;
border: 1px solid rgba(145,214,194,0.35);
border-radius: 8px;
color: var(--mint);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.12em;
text-align: center;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 16px;
}
.metric {
min-width: 0;
padding: 11px 7px;
border: 1px solid var(--line);
border-radius: 8px;
background: #142023;
text-align: center;
}
.metric strong {
display: block;
margin-bottom: 5px;
font-size: 17px;
font-weight: 500;
font-variant-numeric: tabular-nums;
}
.metric span {
color: #738681;
font-size: 7px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.metric.changed strong { color: var(--gold); }
.card-name {
margin: 15px 0 4px;
color: #d7e0da;
font-size: 12px;
font-weight: 600;
}
.mapping-copy {
color: #788c86;
font-size: 9px;
line-height: 1.55;
}
.output-map {
display: grid;
grid-template-columns: repeat(8, 1fr);
gap: 5px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: #121c1f;
}
.map-cell {
aspect-ratio: 1.25;
padding: 0;
border: 1px solid transparent;
border-radius: 4px;
background: var(--pick);
opacity: 0.62;
cursor: pointer;
position: relative;
transition: 120ms ease;
}
.map-cell:hover {
opacity: 1;
transform: translateY(-1px);
}
.map-cell.active-source {
border-color: rgba(255,255,255,0.75);
}
.map-cell.changed {
opacity: 1;
box-shadow: inset 0 0 0 2px var(--gold);
}
.map-cell.current::after {
content: "";
position: absolute;
inset: -4px;
border: 1px solid #fff;
border-radius: 6px;
}
.map-key {
display: flex;
justify-content: space-between;
gap: 8px;
margin-top: 8px;
color: #657872;
font-size: 8px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.change-list {
display: flex;
flex-wrap: wrap;
gap: 6px;
min-height: 29px;
}
.change-chip {
min-width: 35px;
padding: 7px 7px;
border: 1px solid rgba(240,184,101,0.25);
border-radius: 6px;
background: rgba(240,184,101,0.08);
color: var(--gold);
font-size: 9px;
font-variant-numeric: tabular-nums;
cursor: pointer;
}
.change-chip:hover {
background: rgba(240,184,101,0.16);
}
.empty-trace {
display: flex;
align-items: center;
gap: 8px;
color: #71847e;
font-size: 9px;
line-height: 1.45;
}
.empty-trace::before {
content: "";
width: 7px;
height: 7px;
border: 1px solid #59716a;
border-radius: 50%;
}
.lineage {
margin-top: 19px;
padding: 13px;
border-left: 2px solid var(--mint);
border-radius: 0 8px 8px 0;
background: rgba(145,214,194,0.055);
color: #9cafaa;
font-size: 9px;
line-height: 1.6;
}
.lineage strong {
display: block;
margin-bottom: 3px;
color: #d7e2dc;
font-size: 10px;
}
.loading {
position: absolute;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #172226;
color: #8ca19b;
font-size: 9px;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.toast {
position: fixed;
left: 50%;
bottom: 104px;
z-index: 50;
padding: 10px 14px;
border: 1px solid rgba(145,214,194,0.25);
border-radius: 8px;
background: rgba(17,25,28,0.94);
color: #c6d5d0;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
box-shadow: var(--shadow);
opacity: 0;
pointer-events: none;
transform: translate(-50%, 10px);
transition: 180ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 1120px) {
.workspace {
grid-template-columns: 275px minmax(390px, 1fr) 260px;
}
.program-panel { padding-left: 17px; padding-right: 17px; }
.inspector-panel { padding-left: 17px; padding-right: 17px; }
.hole-grid { gap: 6px; }
}
@media (max-width: 920px) {
.workspace { grid-template-columns: 275px minmax(0, 1fr); }
.inspector-panel {
position: fixed;
top: 82px;
right: 12px;
bottom: 12px;
width: 292px;
border: 1px solid var(--line);
border-radius: 12px;
box-shadow: var(--shadow);
transform: translateX(calc(100% + 24px));
transition: transform 180ms ease;
}
body.inspector-open .inspector-panel { transform: translateX(0); }
#toggleInspector { display: inline-block; }
.model-label { display: none; }
}
@media (max-width: 700px) {
.topbar { padding: 0 13px; }
.brand-copy span { display: none; }
.online { display: none; }
.workspace { grid-template-columns: 1fr; }
.program-panel {
position: fixed;
top: 82px;
left: 12px;
bottom: 12px;
width: min(300px, calc(100vw - 24px));
border: 1px solid var(--line);
border-radius: 12px;
box-shadow: var(--shadow);
transform: translateX(calc(-100% - 24px));
transition: transform 180ms ease;
}
body.program-open .program-panel { transform: translateX(0); }
#toggleProgram { display: inline-block; }
.header-meta { gap: 7px; }
.stage-heading { left: 15px; top: 16px; }
.stage-tools { right: 12px; top: 14px; }
.tool-button { width: 34px; padding: 0; }
.tool-button span { display: none; }
.transport { left: 12px; right: 12px; bottom: 12px; grid-template-columns: auto 1fr; }
.pick-readout { display: none; }
.run-button { min-width: 114px; }
.scene-legend { left: 14px; bottom: 95px; }
}
</style>
</head>
<body>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i>
<i></i><i></i><i></i><i></i>
<i></i><i></i><i></i><i></i>
<i></i><i></i><i></i><i></i>
</div>
<div class="brand-copy">
<strong>LOOMLINE</strong>
<span>Punch card instruction studio</span>
</div>
</div>
<div class="header-meta">
<span class="model-label">Program 04 / repeat ×8</span>
<span class="online">Loom model ready</span>
<button id="toggleProgram" class="mobile-toggle" type="button">Cards</button>
<button id="toggleInspector" class="mobile-toggle" type="button">Output</button>
</div>
</header>
<main class="workspace">
<aside class="panel program-panel" id="programPanel">
<p class="eyebrow">01 / Stored program</p>
<h2 class="panel-title">Edit a punch card</h2>
<p class="panel-subtitle">Open or close holes, then run the loom to compare instruction with woven output.</p>
<div class="section-label">
<span>Card library</span>
<span>4 cards</span>
</div>
<div class="card-tabs" id="cardTabs"></div>
<div class="punch-card">
<div class="card-heading">
<strong id="cardHeading">CARD 02</strong>
<span>8 × 8 matrix</span>
</div>
<div class="hole-grid" id="holeGrid" aria-label="Punch card hole matrix"></div>
<div class="card-footer">
<div class="legend">
<span><i></i> Closed</span>
<span><i class="open"></i> Open</span>
</div>
<span id="holeCount">0 open</span>
</div>
</div>
<div class="section-label">
<span>Loom sequence</span>
<span>8 cycles</span>
</div>
<div class="program-strip" id="programStrip">
<span data-card="0">C01</span>
<span data-card="1">C02</span>
<span data-card="2">C03</span>
<span data-card="3">C04</span>
</div>
<div class="panel-actions">
<button class="quiet-button" id="resetCardBtn" type="button">Reset card</button>
<button class="quiet-button" id="exportBtn" type="button">Export program</button>
</div>
</aside>
<section class="stage" id="stage">
<div id="canvasHost">
<div class="loading" id="loading">Threading loom…</div>
</div>
<div class="stage-heading">
<p class="eyebrow">Instruction → physical output</p>
<h2>Loom 04 / live weave model</h2>
<p>Drag to orbit · scroll to zoom</p>
</div>
<div class="stage-tools">
<button class="tool-button" id="viewBtn" type="button" title="Toggle front and angled views"><span>Front</span> ↗</button>
<button class="tool-button" id="resetCameraBtn" type="button" title="Reset camera"><span>Reset</span> ◎</button>
</div>
<div class="scene-legend">
<span><i></i> Warp</span>
<span><i class="weft"></i> Weft</span>
<span><i class="change"></i> Changed</span>
</div>
<div class="transport">
<button class="run-button" id="runBtn" type="button">
<svg id="runIcon" viewBox="0 0 12 12" aria-hidden="true"><path d="M3 1.4 10 6l-7 4.6z"/></svg>
<span id="runLabel">Run loom</span>
</button>
<div class="progress-wrap">
<div class="progress-copy">
<strong id="runStatus">32 picks ready</strong>
<span id="progressPercent">0%</span>
</div>
<div class="progress-track"><div class="progress-fill" id="progressFill"></div></div>
</div>
<div class="pick-readout">
<strong id="pickNumber">00 / 32</strong>
<span>current pick</span>
</div>
</div>
</section>
<aside class="panel inspector-panel" id="inspectorPanel">
<div class="inspector-title">
<div>
<p class="eyebrow">02 / Loom inspector</p>
<h2 class="panel-title">Output trace</h2>
</div>
<div class="active-code" id="activeCode">C02</div>
</div>
<div class="metrics">
<div class="metric">
<strong id="openMetric">0</strong>
<span>Open holes</span>
</div>
<div class="metric">
<strong>×8</strong>
<span>Repeats</span>
</div>
<div class="metric changed">
<strong id="changeMetric">0</strong>
<span>Changed rows</span>
</div>
</div>
<div class="card-name" id="cardName">LOOP / instruction card</div>
<div class="mapping-copy" id="mappingCopy">Card 02 supplies eight physical picks in the program.</div>
<div class="section-label">
<span>Stored card → physical picks</span>
<span>01–32</span>
</div>
<div class="output-map" id="outputMap"></div>
<div class="map-key">
<span>Card order 01 · 02 · 03 · 04</span>
<span>8 cycles</span>
</div>
<div class="section-label">
<span>Changed fabric rows</span>
<span id="changedLabel">0</span>
</div>
<div class="change-list" id="changeList"></div>
<div class="lineage" id="lineageCopy">
<strong>Instruction lineage</strong>
Select a physical pick to isolate its source card and matrix line.
</div>
</aside>
</main>
<div class="toast" id="toast" role="status"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const CARD_COUNT = 4;
const MATRIX_SIZE = 8;
const ROW_COUNT = 32;
const WARP_COLUMNS = 64;
const ROW_SPACING = 0.205;
const CLOTH_BOTTOM = 0.45;
const CLOTH_WIDTH = 8.6;
const CARD_NAMES = ["BORDER", "LOOP", "TWILL", "ECHO"];
const CARD_COLORS = [0x77b9ad, 0x7899c4, 0xd1a65e, 0xc78378];
const seedPatterns = [
[
"00111100",
"01111110",
"11001111",
"10100101",
"00111100",
"01100110",
"11011011",
"00100100"
],
[
"10000001",
"01000010",
"00111100",
"00011000",
"00111100",
"01000010",
"10000001",
"00000000"
],
[
"01010101",
"10101010",
"00110011",
"01100110",
"11000011",
"00100100",
"01011010",
"10100101"
],
[
"11100111",
"10011001",
"00100100",
"01011010",
"10100101",
"11000011",
"01100110",
"00111100"
]
];
const parsePatterns = rows => rows.map(row => row.split("").map(value => value === "1"));
const baseline = seedPatterns.map(parsePatterns);
const cards = baseline.map(card => card.map(row => row.slice()));
const state = {
activeCard: 1,
currentRow: -1,
focusedRow: -1,
focusUntil: 0,
run: {
status: "idle",
elapsed: 0,
duration: 0.43,
current: -1
}
};
const dom = {
cardTabs: document.getElementById("cardTabs"),
cardHeading: document.getElementById("cardHeading"),
holeGrid: document.getElementById("holeGrid"),
holeCount: document.getElementById("holeCount"),
programStrip: document.getElementById("programStrip"),
resetCardBtn: document.getElementById("resetCardBtn"),
exportBtn: document.getElementById("exportBtn"),
host: document.getElementById("canvasHost"),
loading: document.getElementById("loading"),
viewBtn: document.getElementById("viewBtn"),
resetCameraBtn: document.getElementById("resetCameraBtn"),
runBtn: document.getElementById("runBtn"),
runIcon: document.getElementById("runIcon"),
runLabel: document.getElementById("runLabel"),
runStatus: document.getElementById("runStatus"),
progressPercent: document.getElementById("progressPercent"),
progressFill: document.getElementById("progressFill"),
pickNumber: document.getElementById("pickNumber"),
activeCode: document.getElementById("activeCode"),
openMetric: document.getElementById("openMetric"),
changeMetric: document.getElementById("changeMetric"),
cardName: document.getElementById("cardName"),
mappingCopy: document.getElementById("mappingCopy"),
outputMap: document.getElementById("outputMap"),
changedLabel: document.getElementById("changedLabel"),
changeList: document.getElementById("changeList"),
lineageCopy: document.getElementById("lineageCopy"),
toast: document.getElementById("toast"),
toggleProgram: document.getElementById("toggleProgram"),
toggleInspector: document.getElementById("toggleInspector")
};
let toastTimer;
function showToast(message) {
dom.toast.textContent = message;
dom.toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => dom.toast.classList.remove("show"), 2200);
}
const rowSource = row => row % CARD_COUNT;
const rowMatrixLine = row => Math.floor(row / CARD_COUNT);
const rowPattern = row => cards[rowSource(row)][rowMatrixLine(row)];
function matrixLineChanged(cardIndex, matrixLine) {
const original = baseline[cardIndex][matrixLine];
const current = cards[cardIndex][matrixLine];
return original.some((value, index) => value !== current[index]);
}
function rowChanged(row) {
return matrixLineChanged(rowSource(row), rowMatrixLine(row));
}
function changedRows() {
const result = [];
for (let row = 0; row < ROW_COUNT; row++) {
if (rowChanged(row)) result.push(row);
}
return result;
}
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x172226);
scene.fog = new THREE.Fog(0x172226, 15, 31);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
dom.host.appendChild(renderer.domElement);
const cameraState = {
target: new THREE.Vector3(0, 3.65, 0),
yaw: 0.31,
pitch: 0.115,
radius: 14.1
};
function updateCamera() {
const { target, yaw, pitch, radius } = 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();
const hemisphere = new THREE.HemisphereLight(0xe6eee2, 0x352a20, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffedc9, 3.1);
keyLight.position.set(5.5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -3;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x91c9c2, 1.1);
fillLight.position.set(-7, 4, 5);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0xf0b865, 16, 12, 2);
rimLight.position.set(0, 5, -2);
scene.add(rimLight);
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0xa96f37,
roughness: 0.78,
metalness: 0.02,
flatShading: true
});
const darkWoodMaterial = new THREE.MeshStandardMaterial({
color: 0x6d4529,
roughness: 0.9,
metalness: 0,
flatShading: true
});
const metalMaterial = new THREE.MeshStandardMaterial({
color: 0x4c5d5d,
roughness: 0.48,
metalness: 0.58,
flatShading: true
});
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x3c261a,
transparent: true,
opacity: 0.5
});
function addBeam(width, height, depth, x, y, z, material = woodMaterial) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
const edges = new THREE.LineSegments(new THREE.EdgesGeometry(mesh.geometry), edgeMaterial);
mesh.add(edges);
scene.add(mesh);
return mesh;
}
// Studio floor and backdrop.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(32, 25),
new THREE.MeshStandardMaterial({ color: 0x202b2d, roughness: 1 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = 0;
floor.receiveShadow = true;
scene.add(floor);
const backdrop = new THREE.Mesh(
new THREE.PlaneGeometry(26, 16),
new THREE.MeshStandardMaterial({ color: 0x1d292c, roughness: 1 })
);
backdrop.position.set(0, 7, -3.1);
backdrop.receiveShadow = true;
scene.add(backdrop);
const grid = new THREE.GridHelper(24, 24, 0x425052, 0x2a383a);
grid.position.y = 0.008;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
// Low-poly loom frame.
addBeam(0.46, 6.95, 0.58, -5.12, 3.58, -0.12);
addBeam(0.46, 6.95, 0.58, 5.12, 3.58, -0.12);
addBeam(10.7, 0.46, 0.72, 0, 7.03, -0.12);
addBeam(10.7, 0.40, 0.72, 0, 0.25, -0.12);
addBeam(0.28, 6.8, 0.34, 0, 3.62, -0.72, darkWoodMaterial);
const lowerBrace = addBeam(9.8, 0.20, 0.28, 0, 0.48, -0.56, darkWoodMaterial);
lowerBrace.rotation.z = 0;
const pegGeometry = new THREE.CylinderGeometry(0.075, 0.075, 0.34, 6);
for (let i = 0; i < 9; i++) {
const peg = new THREE.Mesh(pegGeometry, darkWoodMaterial);
peg.position.set(-4.4 + i * 1.1, 7.29, -0.12);
peg.castShadow = true;
scene.add(peg);
}
const boltGeometry = new THREE.CylinderGeometry(0.095, 0.095, 0.10, 8);
for (const x of [-5.12, 5.12]) {
for (const y of [0.45, 3.6, 6.85]) {
const bolt = new THREE.Mesh(boltGeometry, metalMaterial);
bolt.rotation.x = Math.PI / 2;
bolt.position.set(x, y, 0.22);
bolt.castShadow = true;
scene.add(bolt);
}
}
const reedBar = addBeam(9.6, 0.18, 0.18, 0, 6.76, -0.28, metalMaterial);
reedBar.castShadow = false;
const reedRodGeometry = new THREE.CylinderGeometry(0.023, 0.023, 0.68, 5);
for (let i = 0; i < 17; i++) {
const rod = new THREE.Mesh(reedRodGeometry, metalMaterial);
rod.position.set(-4.5 + i * 0.5625, 6.98, -0.27);
scene.add(rod);
}
function createTextSprite(text) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = "#273335";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = "#91d6c2";
context.lineWidth = 4;
context.strokeRect(8, 8, canvas.width - 16, canvas.height - 16);
context.fillStyle = "#dce8df";
context.font = "700 37px sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({ map: texture });
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.35, 0.59, 1);
sprite.position.set(0, 7.04, 0.32);
scene.add(sprite);
}
createTextSprite("LOOM / 04");
// Instanced warp segments: each card hole lifts a bundle of eight warps.
const warpGeometry = new THREE.CylinderGeometry(0.016, 0.016, 1, 5);
const warpMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.86,
metalness: 0.02,
vertexColors: true
});
const warpMesh = new THREE.InstancedMesh(
warpGeometry,
warpMaterial,
ROW_COUNT * WARP_COLUMNS
);
warpMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
warpMesh.frustumCulled = false;
scene.add(warpMesh);
const dummy = new THREE.Object3D();
const warmWarp = new THREE.Color(0x78938a);
const coolWarp = new THREE.Color(0x3e6667);
const raisedWarp = new THREE.Color(0xa8b09a);
const tempColor = new THREE.Color();
function updateWarpRow(row) {
const pattern = rowPattern(row);
const startY = CLOTH_BOTTOM + row * ROW_SPACING;
const length = ROW_SPACING * 1.035;
for (let column = 0; column < WARP_COLUMNS; column++) {
const group = Math.min(MATRIX_SIZE - 1, Math.floor(column / 8));
const isOpen = pattern[group];
const x = -CLOTH_WIDTH / 2 + (column / (WARP_COLUMNS - 1)) * CLOTH_WIDTH;
const z = isOpen ? 0.145 : -0.115;
dummy.position.set(x, startY + length / 2, z);
dummy.quaternion.identity();
dummy.scale.set(1, length, 1);
dummy.updateMatrix();
const index = row * WARP_COLUMNS + column;
warpMesh.setMatrixAt(index, dummy.matrix);
if (isOpen) {
tempColor.copy(raisedWarp);
} else {
tempColor.copy((row + group) % 2 === 0 ? warmWarp : coolWarp);
}
warpMesh.setColorAt(index, tempColor);
}
warpMesh.instanceMatrix.needsUpdate = true;
if (warpMesh.instanceColor) warpMesh.instanceColor.needsUpdate = true;
}
function createWeftGeometry(pattern) {
const points = [];
const pointCount = 17;
for (let i = 0; i < pointCount; i++) {
const x = -CLOTH_WIDTH / 2 + (i / (pointCount - 1)) * CLOTH_WIDTH;
const group = Math.min(MATRIX_SIZE - 1, Math.floor(i / 2));
const z = pattern[group] ? 0.17 : -0.13;
points.push(new THREE.Vector3(x, 0, z));
}
const curve = new THREE.CatmullRomCurve3(points, false, "centripetal", 0.15);
return new THREE.TubeGeometry(curve, 56, 0.032, 5, false);
}
const rows = [];
const tagGeometry = new THREE.BoxGeometry(0.16, 0.09, 0.10);
const highlightGeometry = new THREE.PlaneGeometry(8.88, 0.115);
for (let row = 0; row < ROW_COUNT; row++) {
const changed = rowChanged(row);
const material = new THREE.MeshStandardMaterial({
color: changed ? 0xf0b865 : 0xdccaa8,
emissive: changed ? 0x7a4215 : 0x000000,
emissiveIntensity: changed ? 0.24 : 0,
roughness: 0.92,
metalness: 0,
transparent: true,
opacity: 0.92
});
const mesh = new THREE.Mesh(createWeftGeometry(rowPattern(row)), material);
mesh.position.y = CLOTH_BOTTOM + row * ROW_SPACING;
mesh.frustumCulled = false;
scene.add(mesh);
const highlight = new THREE.Mesh(
highlightGeometry,
new THREE.MeshBasicMaterial({
color: 0xf0b865,
transparent: true,
opacity: 0.12,
depthWrite: false,
side: THREE.DoubleSide
})
);
highlight.position.z = 0.255;
highlight.visible = changed;
mesh.add(highlight);
const tag = new THREE.Mesh(
tagGeometry,
new THREE.MeshStandardMaterial({
color: CARD_COLORS[rowSource(row)],
roughness: 0.75,
metalness: 0.05
})
);
tag.position.set(CLOTH_WIDTH / 2 + 0.16, 0, 0.24);
mesh.add(tag);
rows.push({
mesh,
material,
highlight,
tag
});
}
function updateRowAppearance(row) {
const changed = rowChanged(row);
rows[row].material.color.setHex(changed ? 0xf0b865 : 0xdccaa8);
rows[row].material.emissive.setHex(changed ? 0x7a4215 : 0x000000);
rows[row].material.emissiveIntensity = changed ? 0.24 : 0;
rows[row].highlight.visible = changed;
}
function updateCardGeometry(cardIndex) {
for (let row = 0; row < ROW_COUNT; row++) {
if (rowSource(row) !== cardIndex) continue;
const oldGeometry = rows[row].mesh.geometry;
rows[row].mesh.geometry = createWeftGeometry(rowPattern(row));
oldGeometry.dispose();
updateWarpRow(row);
updateRowAppearance(row);
}
}
// Low-poly shuttle.
const shuttle = new THREE.Group();
const shuttleBodyMaterial = new THREE.MeshStandardMaterial({
color: 0xe39a48,
roughness: 0.5,
metalness: 0.18,
flatShading: true
});
const shuttleCore = new THREE.Mesh(new THREE.BoxGeometry(0.58, 0.13, 0.18), shuttleBodyMaterial);
shuttleCore.castShadow = true;
shuttle.add(shuttleCore);
const shuttlePoint = new THREE.Mesh(new THREE.ConeGeometry(0.12, 0.42, 4), shuttleBodyMaterial);
shuttlePoint.rotation.z = -Math.PI / 2;
shuttlePoint.position.x = 0.48;
shuttlePoint.castShadow = true;
shuttle.add(shuttlePoint);
const shuttleTail = new THREE.Mesh(new THREE.ConeGeometry(0.08, 0.25, 4), shuttleBodyMaterial);
shuttleTail.rotation.z = Math.PI / 2;
shuttleTail.position.x = -0.40;
shuttle.add(shuttleTail);
const shuttleLight = new THREE.PointLight(0xf5b768, 1.8, 1.7, 2);
shuttleLight.position.z = 0.15;
shuttle.add(shuttleLight);
shuttle.position.set(0, CLOTH_BOTTOM + 0.16, 0.48);
scene.add(shuttle);
for (let row = 0; row < ROW_COUNT; row++) updateWarpRow(row);
// -------------------------------------------------------------------------
// Interface rendering
// -------------------------------------------------------------------------
function renderCardTabs() {
dom.cardTabs.innerHTML = "";
cards.forEach((card, index) => {
const button = document.createElement("button");
button.type = "button";
button.className = `card-tab${index === state.activeCard ? " active" : ""}`;
button.dataset.card = index;
const changed = card.some((line, lineIndex) => matrixLineChanged(index, lineIndex));
if (changed) button.classList.add("changed");
const title = document.createElement("strong");
title.textContent = `C0${index + 1}`;
button.appendChild(title);
const preview = document.createElement("span");
preview.className = "mini-pattern";
card[0].forEach(value => {
const bar = document.createElement("i");
bar.style.height = `${value ? "100%" : "28%"}`;
if (value) bar.classList.add("on");
preview.appendChild(bar);
});
button.appendChild(preview);
dom.cardTabs.appendChild(button);
});
}
function renderHoleGrid() {
const pattern = cards[state.activeCard];
dom.holeGrid.innerHTML = "";
for (let row = 0; row < MATRIX_SIZE; row++) {
for (let column = 0; column < MATRIX_SIZE; column++) {
const isOpen = pattern[row][column];
const button = document.createElement("button");
button.type = "button";
button.className = `hole${isOpen ? " open" : ""}`;
button.dataset.row = row;
button.dataset.column = column;
button.setAttribute("aria-pressed", String(isOpen));
button.setAttribute(
"aria-label",
`Card ${state.activeCard + 1}, row ${row + 1}, column ${column + 1}, ${isOpen ? "open" : "closed"}`
);
button.title = `R${row + 1} / C${column + 1}`;
dom.holeGrid.appendChild(button);
}
}
const count = pattern.flat().filter(Boolean).length;
dom.holeCount.textContent = `${count} open`;
dom.cardHeading.textContent = `CARD 0${state.activeCard + 1}`;
}
function renderProgramStrip() {
dom.programStrip.querySelectorAll("span").forEach(element => {
element.classList.toggle("active", Number(element.dataset.card) === state.activeCard);
});
}
function renderOutputMap() {
dom.outputMap.innerHTML = "";
const changed = new Set(changedRows());
for (let row = 0; row < ROW_COUNT; row++) {
const source = rowSource(row);
const cell = document.createElement("button");
cell.type = "button";
cell.className = "map-cell";
cell.dataset.row = row;
cell.style.setProperty("--pick", `#${CARD_COLORS[source].toString(16).padStart(6, "0")}`);
cell.title = `Pick ${row + 1} · Card ${source + 1} · Matrix line ${rowMatrixLine(row) + 1}`;
if (source === state.activeCard) cell.classList.add("active-source");
if (changed.has(row)) cell.classList.add("changed");
if (row === state.currentRow) cell.classList.add("current");
dom.outputMap.appendChild(cell);
}
}
function renderInspector() {
const card = cards[state.activeCard];
const openCount = card.flat().filter(Boolean).length;
const changed = changedRows();
dom.activeCode.textContent = `C0${state.activeCard + 1}`;
dom.openMetric.textContent = openCount;
dom.changeMetric.textContent = changed.length;
dom.cardName.textContent = `${CARD_NAMES[state.activeCard]} / instruction card`;
dom.mappingCopy.textContent =
`Card 0${state.activeCard + 1} supplies eight physical picks. Each matrix line appears once per loom cycle.`;
dom.changedLabel.textContent = `${changed.length} highlighted`;
dom.changeList.innerHTML = "";
if (changed.length === 0) {
const empty = document.createElement("div");
empty.className = "empty-trace";
empty.textContent = "No modified fabric rows";
dom.changeList.appendChild(empty);
} else {
changed.forEach(row => {
const chip = document.createElement("button");
chip.type = "button";
chip.className = "change-chip";
chip.dataset.row = row;
chip.textContent = String(row + 1).padStart(2, "0");
chip.title = `Inspect pick ${row + 1}`;
dom.changeList.appendChild(chip);
});
}
renderOutputMap();
}
function renderAll() {
renderCardTabs();
renderHoleGrid();
renderProgramStrip();
renderInspector();
}
function selectCard(index) {
state.activeCard = index;
renderAll();
}
function toggleHole(row, column) {
const pattern = cards[state.activeCard];
pattern[row][column] = !pattern[row][column];
updateCardGeometry(state.activeCard);
renderAll();
}
// -------------------------------------------------------------------------
// Run state
// -------------------------------------------------------------------------
function totalRunTime() {
return ROW_COUNT * state.run.duration;
}
function setRunButton() {
dom.runBtn.classList.toggle("running", state.run.status !== "idle");
dom.runIcon.innerHTML = state.run.status === "running"
? '<path d="M2.5 2h2.7v8H2.5zm4.3 0h2.7v8H6.8z"/>'
: '<path d="M3 1.4 10 6l-7 4.6z"/>';
if (state.run.status === "running") {
dom.runLabel.textContent = "Pause";
} else if (state.run.status === "paused") {
dom.runLabel.textContent = "Resume";
} else if (state.run.elapsed >= totalRunTime()) {
dom.runLabel.textContent = "Run again";
} else {
dom.runLabel.textContent = "Run loom";
}
}
function toggleRun() {
if (state.run.status === "running") {
state.run.status = "paused";
dom.runStatus.textContent = "Loom paused";
} else if (state.run.status === "paused") {
state.run.status = "running";
dom.runStatus.textContent = "Weaving stored instructions";
} else {
state.run.status = "running";
state.run.elapsed = 0;
state.run.current = -1;
state.currentRow = -1;
rows.forEach(row => { row.material.opacity = 0.08; });
dom.runStatus.textContent = "Weaving stored instructions";
}
setRunButton();
}
function visitRow(row) {
state.currentRow = row;
state.run.current = row;
updateWarpRow(row);
rows[row].material.opacity = 1;
const source = rowSource(row);
const line = rowMatrixLine(row);
dom.pickNumber.textContent = `${String(row + 1).padStart(2, "0")} / ${ROW_COUNT}`;
dom.runStatus.textContent = `Pick ${row + 1} · card ${source + 1} · line ${line + 1}`;
renderOutputMap();
renderInspector();
}
function finishRun() {
state.run.status = "idle";
state.run.elapsed = totalRunTime();
state.currentRow = ROW_COUNT - 1;
rows.forEach(row => { row.material.opacity = 0.92; });
dom.runStatus.textContent = "32 / 32 picks complete";
dom.progressPercent.textContent = "100%";
dom.progressFill.style.width = "100%";
setRunButton();
renderOutputMap();
}
function focusRow(row) {
state.focusedRow = row;
state.focusUntil = performance.now() + 1800;
rows[row].material.opacity = 1;
rows[row].material.emissiveIntensity = 0.9;
const source = rowSource(row);
const line = rowMatrixLine(row);
dom.lineageCopy.innerHTML =
`<strong>Pick ${row + 1} lineage</strong>` +
`Card 0${source + 1} / ${CARD_NAMES[source]} → matrix line ${line + 1} → physical weft row ${row + 1}.`;
showToast(`Pick ${row + 1} · Card 0${source + 1} / line ${line + 1}`);
}
// -------------------------------------------------------------------------
// Events
// -------------------------------------------------------------------------
dom.cardTabs.addEventListener("click", event => {
const button = event.target.closest("[data-card]");
if (button) selectCard(Number(button.dataset.card));
});
dom.holeGrid.addEventListener("click", event => {
const button = event.target.closest(".hole");
if (!button) return;
toggleHole(Number(button.dataset.row), Number(button.dataset.column));
});
dom.programStrip.addEventListener("click", event => {
const item = event.target.closest("[data-card]");
if (item) selectCard(Number(item.dataset.card));
});
dom.outputMap.addEventListener("click", event => {
const cell = event.target.closest("[data-row]");
if (cell) focusRow(Number(cell.dataset.row));
});
dom.changeList.addEventListener("click", event => {
const chip = event.target.closest("[data-row]");
if (chip) focusRow(Number(chip.dataset.row));
});
dom.resetCardBtn.addEventListener("click", () => {
const index = state.activeCard;
cards[index] = baseline[index].map(row => row.slice());
updateCardGeometry(index);
renderAll();
showToast(`Card 0${index + 1} restored`);
});
dom.exportBtn.addEventListener("click", () => {
const program = {
model: "LOOMLINE / 04",
matrixSize: [8, 8],
cycle: [1, 2, 3, 4],
repeats: 8,
cards: cards.map((card, index) => ({
id: `C0${index + 1}`,
name: CARD_NAMES[index],
holes: card.map(row => row.map(value => value ? 1 : 0))
}))
};
const blob = new Blob([JSON.stringify(program, null, 2)], { type: "application/json" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = "loomline-program.json";
link.click();
setTimeout(() => URL.revokeObjectURL(url), 1000);
showToast("Program exported");
});
dom.runBtn.addEventListener("click", toggleRun);
let frontView = false;
dom.viewBtn.addEventListener("click", () => {
frontView = !frontView;
if (frontView) {
cameraState.yaw = 0;
cameraState.pitch = 0.035;
cameraState.radius = 14.4;
dom.viewBtn.innerHTML = "<span>Angle</span> ↗";
} else {
cameraState.yaw = 0.31;
cameraState.pitch = 0.115;
cameraState.radius = 14.1;
dom.viewBtn.innerHTML = "<span>Front</span> ↗";
}
});
dom.resetCameraBtn.addEventListener("click", () => {
cameraState.yaw = 0.31;
cameraState.pitch = 0.115;
cameraState.radius = 14.1;
frontView = false;
dom.viewBtn.innerHTML = "<span>Front</span> ↗";
});
dom.toggleProgram.addEventListener("click", () => {
document.body.classList.toggle("program-open");
document.body.classList.remove("inspector-open");
});
dom.toggleInspector.addEventListener("click", () => {
document.body.classList.toggle("inspector-open");
document.body.classList.remove("program-open");
});
// Camera controls implemented directly without addons.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.yaw -= deltaX * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.0045,
-0.08,
0.55
);
});
const endDrag = event => {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
};
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.009,
9.5,
19
);
}, { passive: false });
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resizeRenderer() {
const width = Math.max(1, dom.host.clientWidth);
const height = Math.max(1, dom.host.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
new ResizeObserver(resizeRenderer).observe(dom.host);
resizeRenderer();
renderAll();
setRunButton();
dom.loading.remove();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (state.run.status === "running") {
state.run.elapsed = Math.min(totalRunTime(), state.run.elapsed + delta);
const row = Math.min(ROW_COUNT - 1, Math.floor(state.run.elapsed / state.run.duration));
if (row !== state.run.current) visitRow(row);
const fraction = (state.run.elapsed % state.run.duration) / state.run.duration;
const direction = row % 2 === 0 ? 1 : -1;
const start = direction === 1 ? -4.45 : 4.45;
const end = direction === 1 ? 4.45 : -4.45;
shuttle.position.x = THREE.MathUtils.lerp(start, end, fraction);
shuttle.position.y = CLOTH_BOTTOM + row * ROW_SPACING + 0.02;
shuttle.position.z = 0.46;
shuttle.rotation.z = direction === 1 ? -0.06 : 0.06;
rows.forEach((entry, index) => {
if (index < row) entry.material.opacity = 0.16;
else if (index === row) entry.material.opacity = 1;
else entry.material.opacity = 0.075;
});
const progress = state.run.elapsed / totalRunTime();
dom.progressFill.style.width = `${progress * 100}%`;
dom.progressPercent.textContent = `${Math.round(progress * 100)}%`;
if (state.run.elapsed >= totalRunTime()) finishRun();
} else if (state.run.status === "idle") {
shuttle.position.x = Math.sin(elapsed * 0.55) * 0.55;
shuttle.position.y = CLOTH_BOTTOM + 0.16;
shuttle.position.z = 0.48;
shuttle.rotation.z = Math.sin(elapsed * 0.7) * 0.025;
}
if (state.focusedRow >= 0) {
const row = state.focusedRow;
rows[row].material.opacity = 1;
rows[row].material.emissiveIntensity = 0.65 + Math.sin(elapsed * 7) * 0.25;
if (performance.now() > state.focusUntil) {
state.focusedRow = -1;
updateRowAppearance(row);
if (state.run.status === "idle") rows[row].material.opacity = 0.92;
}
}
updateCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```