Prompt specification
Build or customize the Three.js 3D scene "Repeating strip continuation" 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: Repeating strip continuation
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/repeating-strip-continuation-x0362
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: repeating strip continuation. Build a short geometric strip with a repeating three-piece motif; users place the next block and compare the resulting continuation against a visible rule card. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (repeating-strip-continuation-x0362):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Polyform — Repeating Strip Lab</title>
<style>
:root {
--paper: #eee9dd;
--panel: #f8f5ed;
--panel-strong: #fffdf7;
--ink: #243338;
--muted: #6f7774;
--line: #d7d0c1;
--coral: #e97152;
--teal: #2d8c82;
--navy: #34485f;
--good: #648a48;
--bad: #bc4f46;
--shadow: 0 18px 50px rgba(49, 55, 51, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
}
body {
overflow: hidden;
color: var(--ink);
background: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
-webkit-font-smoothing: antialiased;
}
button {
font: inherit;
}
.app {
display: grid;
grid-template-rows: 66px minmax(0, 1fr);
height: 100dvh;
}
.topbar {
position: relative;
z-index: 10;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 24px;
border-bottom: 1px solid rgba(63, 69, 64, 0.14);
background: rgba(248, 245, 237, 0.92);
backdrop-filter: blur(12px);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
position: relative;
width: 31px;
height: 31px;
flex: 0 0 auto;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
width: 19px;
height: 19px;
}
.brand-mark::before {
left: 0;
top: 2px;
background: var(--coral);
clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.brand-mark::after {
right: 0;
bottom: 1px;
border: 3px solid var(--navy);
transform: rotate(45deg);
}
.brand-name {
font-size: 15px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
}
.brand-name span {
color: var(--muted);
font-weight: 550;
}
.top-status {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 12px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
white-space: nowrap;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--good);
box-shadow: 0 0 0 4px rgba(100, 138, 72, 0.12);
}
.status-dot.has-error {
background: var(--bad);
box-shadow: 0 0 0 4px rgba(188, 79, 70, 0.12);
}
.workspace {
display: grid;
grid-template-columns: minmax(0, 1fr) 370px;
min-height: 0;
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
isolation: isolate;
background:
radial-gradient(circle at 72% 22%, rgba(255, 255, 255, 0.66), transparent 30%),
linear-gradient(145deg, #f2eee4, #e5dfd1);
}
.stage canvas {
position: absolute;
inset: 0;
z-index: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
.stage canvas:active {
cursor: grabbing;
}
.stage-copy {
position: absolute;
z-index: 3;
top: 28px;
left: 30px;
max-width: 390px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 10px;
color: var(--teal);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.stage-copy h1 {
max-width: 350px;
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(36px, 4.3vw, 62px);
font-weight: 500;
line-height: 0.97;
letter-spacing: -0.045em;
}
.stage-copy p:last-child {
max-width: 310px;
margin: 16px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.stage-actions {
position: absolute;
z-index: 4;
top: 24px;
right: 24px;
display: flex;
gap: 8px;
}
.small-button {
min-height: 38px;
padding: 0 13px;
border: 1px solid rgba(47, 57, 57, 0.15);
border-radius: 999px;
color: var(--ink);
background: rgba(255, 253, 247, 0.78);
box-shadow: 0 7px 20px rgba(49, 55, 51, 0.08);
backdrop-filter: blur(10px);
cursor: pointer;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
transition: transform 160ms ease, background 160ms ease;
}
.small-button:hover {
transform: translateY(-1px);
background: rgba(255, 253, 247, 0.96);
}
.small-button:focus-visible,
.candidate:focus-visible,
.primary-button:focus-visible,
.text-button:focus-visible {
outline: 3px solid rgba(45, 140, 130, 0.25);
outline-offset: 3px;
}
.scene-caption {
position: absolute;
z-index: 3;
right: 24px;
bottom: 22px;
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 1px solid rgba(47, 57, 57, 0.11);
border-radius: 10px;
color: var(--muted);
background: rgba(248, 245, 237, 0.72);
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
pointer-events: none;
}
.caption-key {
padding: 3px 6px;
border: 1px solid rgba(47, 57, 57, 0.18);
border-bottom-width: 2px;
border-radius: 4px;
color: var(--ink);
background: rgba(255, 255, 255, 0.46);
}
.next-label {
position: absolute;
z-index: 3;
left: 50%;
top: 50%;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px dashed rgba(45, 140, 130, 0.72);
border-radius: 999px;
color: #1f6f68;
background: rgba(246, 253, 249, 0.9);
box-shadow: 0 7px 22px rgba(45, 140, 130, 0.12);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -100%);
transition: opacity 150ms ease;
}
.next-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 15px;
background: rgba(45, 140, 130, 0.5);
}
.toast {
position: absolute;
z-index: 6;
left: 50%;
bottom: 72px;
max-width: min(440px, calc(100% - 40px));
padding: 11px 15px;
border-radius: 10px;
color: #fff;
background: rgba(36, 51, 56, 0.92);
box-shadow: 0 12px 36px rgba(36, 51, 56, 0.2);
font-size: 12px;
font-weight: 700;
text-align: center;
opacity: 0;
pointer-events: none;
transform: translate(-50%, 12px);
transition: opacity 180ms ease, transform 180ms ease;
}
.toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
.inspector {
position: relative;
z-index: 5;
min-height: 0;
overflow-y: auto;
padding: 18px;
border-left: 1px solid rgba(63, 69, 64, 0.14);
background: var(--panel);
scrollbar-width: thin;
scrollbar-color: #c8c0b1 transparent;
}
.card {
margin-bottom: 14px;
padding: 18px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel-strong);
box-shadow: 0 7px 24px rgba(59, 60, 54, 0.055);
}
.rule-card {
overflow: hidden;
border-color: #2f464d;
color: #f9f6ed;
background:
radial-gradient(circle at 100% 0, rgba(45, 140, 130, 0.32), transparent 42%),
#263a40;
}
.card-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 15px;
}
.card-kicker {
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.rule-card .card-kicker {
color: rgba(255, 255, 255, 0.58);
}
.rule-number {
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 6px;
color: rgba(255, 255, 255, 0.7);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
}
.rule-card h2,
.card h2 {
margin: 0;
font-size: 21px;
line-height: 1.15;
letter-spacing: -0.025em;
}
.rule-description {
margin: 8px 0 17px;
color: rgba(255, 255, 255, 0.64);
font-size: 12px;
line-height: 1.5;
}
.motif {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.motif-piece {
position: relative;
min-width: 0;
padding: 13px 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 11px;
background: rgba(255, 255, 255, 0.065);
text-align: center;
}
.motif-letter {
position: absolute;
top: 6px;
left: 7px;
color: rgba(255, 255, 255, 0.36);
font-size: 9px;
font-weight: 850;
}
.motif-name {
display: block;
margin-top: 9px;
color: rgba(255, 255, 255, 0.74);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.05em;
text-transform: uppercase;
white-space: nowrap;
}
.repeat-strip {
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
margin-top: 14px;
padding-top: 14px;
border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.repeat-strip .mini-shape {
width: 13px;
height: 13px;
opacity: 0.72;
}
.repeat-strip .repeat-arrow {
color: rgba(255, 255, 255, 0.24);
font-size: 10px;
}
.expected-callout {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 15px;
padding: 11px 12px;
border-radius: 10px;
color: #173f3b;
background: #d9eee5;
font-size: 11px;
font-weight: 750;
}
.expected-callout strong {
font-size: 12px;
}
.card-heading .step-count {
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
.instruction {
margin: 8px 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.candidates {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.candidate {
position: relative;
min-width: 0;
padding: 15px 5px 11px;
border: 1px solid var(--line);
border-radius: 11px;
color: var(--ink);
background: #f8f5ed;
cursor: grab;
touch-action: none;
transition: border 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}
.candidate:hover {
transform: translateY(-2px);
border-color: #aaa294;
}
.candidate.selected {
border-color: var(--teal);
box-shadow: 0 0 0 3px rgba(45, 140, 130, 0.12);
background: #f3faf6;
}
.candidate:active {
cursor: grabbing;
}
.candidate-key {
position: absolute;
top: 6px;
left: 8px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
}
.candidate-name {
display: block;
margin-top: 9px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.04em;
text-transform: uppercase;
white-space: nowrap;
}
.selection-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 14px;
}
.selection-copy {
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.selection-copy strong {
display: block;
color: var(--ink);
font-size: 12px;
}
.primary-button {
flex: 0 0 auto;
min-height: 40px;
padding: 0 15px;
border: 0;
border-radius: 9px;
color: #fff;
background: var(--ink);
box-shadow: 0 8px 18px rgba(36, 51, 56, 0.16);
cursor: pointer;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.07em;
text-transform: uppercase;
transition: transform 150ms ease, background 150ms ease;
}
.primary-button:hover {
transform: translateY(-1px);
background: #17282d;
}
.compare-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.compare-title h2 {
font-size: 17px;
}
.compare-badge {
padding: 5px 7px;
border-radius: 6px;
color: var(--muted);
background: #eee9df;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.compare-row {
margin-top: 12px;
}
.compare-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.compare-items {
display: flex;
gap: 6px;
min-height: 42px;
padding: 8px;
overflow-x: auto;
border: 1px solid #e3ded3;
border-radius: 10px;
background: #f7f3ea;
scrollbar-width: thin;
}
.compare-item {
position: relative;
display: grid;
place-items: center;
width: 29px;
height: 28px;
flex: 0 0 29px;
border-radius: 6px;
background: rgba(255, 255, 255, 0.74);
}
.compare-item.wrong {
background: rgba(188, 79, 70, 0.13);
box-shadow: inset 0 0 0 1px rgba(188, 79, 70, 0.45);
}
.compare-item.correct {
box-shadow: inset 0 0 0 1px rgba(100, 138, 72, 0.22);
}
.compare-item .mini-shape {
width: 13px;
height: 13px;
}
.verdict {
display: flex;
gap: 10px;
margin-top: 14px;
padding: 12px;
border-radius: 10px;
color: #46642f;
background: rgba(100, 138, 72, 0.1);
font-size: 11px;
font-weight: 700;
line-height: 1.45;
}
.verdict.bad {
color: #8e3b35;
background: rgba(188, 79, 70, 0.1);
}
.verdict-icon {
display: grid;
place-items: center;
width: 20px;
height: 20px;
flex: 0 0 20px;
border: 1px solid currentColor;
border-radius: 50%;
font-size: 11px;
}
.card-actions {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 13px;
}
.text-button {
padding: 5px 0;
border: 0;
color: var(--muted);
background: transparent;
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.text-button:hover:not(:disabled) {
color: var(--ink);
}
.text-button:disabled {
opacity: 0.34;
cursor: not-allowed;
}
.mini-shape {
display: inline-block;
width: 24px;
height: 24px;
flex: 0 0 auto;
vertical-align: middle;
}
.shape-wedge {
background: var(--shape-color);
clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.shape-block {
border-radius: 3px;
background: var(--shape-color);
box-shadow: inset -4px -4px 0 rgba(0, 0, 0, 0.11);
}
.shape-diamond {
width: 19px;
height: 19px;
margin: 2px;
border-radius: 2px;
background: var(--shape-color);
transform: rotate(45deg);
}
.drag-ghost {
position: fixed;
z-index: 100;
display: grid;
place-items: center;
width: 64px;
height: 64px;
border: 2px solid rgba(255, 255, 255, 0.9);
border-radius: 15px;
background: rgba(36, 51, 56, 0.9);
box-shadow: 0 14px 35px rgba(36, 51, 56, 0.28);
pointer-events: none;
transform: translate(-50%, -50%) rotate(-4deg);
}
.drag-ghost .mini-shape {
width: 31px;
height: 31px;
}
.drag-ghost .shape-diamond {
width: 25px;
height: 25px;
margin: 3px;
}
@media (max-width: 960px) {
body {
overflow: auto;
}
.app {
height: auto;
min-height: 100dvh;
grid-template-rows: 62px auto;
}
.workspace {
grid-template-columns: 1fr;
}
.stage {
height: 61dvh;
min-height: 440px;
}
.inspector {
overflow: visible;
border-top: 1px solid rgba(63, 69, 64, 0.14);
border-left: 0;
}
.stage-copy h1 {
font-size: 44px;
}
.inspector-inner {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 14px;
max-width: 760px;
margin: 0 auto;
}
.card {
margin: 0;
}
.rule-card,
.compare-card {
grid-column: 1 / -1;
}
}
@media (max-width: 620px) {
.topbar {
padding: 0 16px;
}
.brand-name span {
display: none;
}
.top-status {
font-size: 9px;
}
.stage {
height: 56dvh;
min-height: 390px;
}
.stage-copy {
top: 20px;
left: 20px;
}
.stage-copy h1 {
max-width: 230px;
font-size: 37px;
}
.stage-copy p:last-child {
display: none;
}
.stage-actions {
top: 18px;
right: 16px;
}
.scene-caption {
right: 14px;
bottom: 14px;
left: 14px;
justify-content: center;
font-size: 8px;
}
.inspector {
padding: 14px;
}
.inspector-inner {
display: block;
}
.card {
margin-bottom: 14px;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-name">Polyform <span>/ Pattern Lab</span></div>
</div>
<div class="top-status" aria-live="polite">
<span class="status-dot" id="statusDot"></span>
<span id="alignmentStatus">6 / 6 aligned</span>
</div>
</header>
<main class="workspace">
<section class="stage" id="stage" aria-label="Interactive three-dimensional geometric strip">
<div class="stage-copy">
<p class="eyebrow">Continuation study · 01</p>
<h1>Build the rhythm.</h1>
<p>
Extend the strip with one geometric block. Compare your result with the
repeating rule, then test the pattern again.
</p>
</div>
<div class="stage-actions">
<button class="small-button" id="resetCamera" type="button">Reset view</button>
</div>
<div class="next-label" id="nextLabel">Next · A</div>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<div class="scene-caption">
<span class="caption-key">Drag</span> orbit
<span>·</span>
<span class="caption-key">Scroll</span> zoom
<span>·</span>
<span class="caption-key">Double-click</span> reset
</div>
</section>
<aside class="inspector" aria-label="Pattern rule and placement controls">
<div class="inspector-inner">
<section class="card rule-card">
<div class="card-heading">
<span class="card-kicker">Visible rule card</span>
<span class="rule-number">RULE / 03</span>
</div>
<h2>Three pieces, then repeat.</h2>
<p class="rule-description">
The motif keeps its order no matter how many times the strip continues.
</p>
<div class="motif" aria-label="The three-piece motif">
<div class="motif-piece">
<span class="motif-letter">A</span>
<span class="mini-shape shape-wedge" style="--shape-color: var(--coral)"></span>
<span class="motif-name">Coral wedge</span>
</div>
<div class="motif-piece">
<span class="motif-letter">B</span>
<span class="mini-shape shape-block" style="--shape-color: var(--teal)"></span>
<span class="motif-name">Teal block</span>
</div>
<div class="motif-piece">
<span class="motif-letter">C</span>
<span class="mini-shape shape-diamond" style="--shape-color: var(--navy)"></span>
<span class="motif-name">Navy diamond</span>
</div>
</div>
<div class="repeat-strip" aria-hidden="true">
<span class="mini-shape shape-wedge" style="--shape-color: var(--coral)"></span>
<span class="repeat-arrow">›</span>
<span class="mini-shape shape-block" style="--shape-color: var(--teal)"></span>
<span class="repeat-arrow">›</span>
<span class="mini-shape shape-diamond" style="--shape-color: var(--navy)"></span>
<span class="repeat-arrow">›</span>
<span class="mini-shape shape-wedge" style="--shape-color: var(--coral)"></span>
<span class="repeat-arrow">›</span>
<span class="mini-shape shape-block" style="--shape-color: var(--teal)"></span>
<span class="repeat-arrow">›</span>
<span class="mini-shape shape-diamond" style="--shape-color: var(--navy)"></span>
</div>
<div class="expected-callout">
<span>Next expected</span>
<strong id="expectedNext">A · Coral wedge</strong>
</div>
</section>
<section class="card">
<div class="card-heading">
<h2>Place the next block</h2>
<span class="step-count" id="pieceCount">6 pieces</span>
</div>
<p class="instruction">
Drag a block onto the dotted slot, or select one and press Place.
</p>
<div class="candidates" id="candidates">
<button
class="candidate selected"
type="button"
data-shape="wedge"
aria-pressed="true"
>
<span class="candidate-key">A</span>
<span class="mini-shape shape-wedge" style="--shape-color: var(--coral)"></span>
<span class="candidate-name">Wedge</span>
</button>
<button
class="candidate"
type="button"
data-shape="block"
aria-pressed="false"
>
<span class="candidate-key">B</span>
<span class="mini-shape shape-block" style="--shape-color: var(--teal)"></span>
<span class="candidate-name">Block</span>
</button>
<button
class="candidate"
type="button"
data-shape="diamond"
aria-pressed="false"
>
<span class="candidate-key">C</span>
<span class="mini-shape shape-diamond" style="--shape-color: var(--navy)"></span>
<span class="candidate-name">Diamond</span>
</button>
</div>
<div class="selection-row">
<div class="selection-copy">
Selected
<strong id="selectedName">Coral wedge</strong>
</div>
<button class="primary-button" id="placeButton" type="button">
Place block
</button>
</div>
</section>
<section class="card compare-card">
<div class="compare-title">
<h2>Continuation check</h2>
<span class="compare-badge" id="compareBadge">Rule holds</span>
</div>
<div class="compare-row">
<div class="compare-label">
<span>Expected by rule</span>
<span>A · B · C</span>
</div>
<div class="compare-items" id="expectedRow"></div>
</div>
<div class="compare-row">
<div class="compare-label">
<span>Your strip</span>
<span id="actualLabel">6 blocks</span>
</div>
<div class="compare-items" id="actualRow"></div>
</div>
<div class="verdict" id="verdict" aria-live="polite">
<span class="verdict-icon">✓</span>
<span id="verdictText">The six-piece lead-in matches the rule.</span>
</div>
<div class="card-actions">
<button class="text-button" id="undoButton" type="button" disabled>
Undo last
</button>
<button class="text-button" id="resetStrip" type="button">
Reset strip
</button>
</div>
</section>
</div>
</aside>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const nextLabel = document.getElementById("nextLabel");
const toast = document.getElementById("toast");
const expectedNext = document.getElementById("expectedNext");
const selectedName = document.getElementById("selectedName");
const expectedRow = document.getElementById("expectedRow");
const actualRow = document.getElementById("actualRow");
const verdict = document.getElementById("verdict");
const verdictText = document.getElementById("verdictText");
const compareBadge = document.getElementById("compareBadge");
const pieceCount = document.getElementById("pieceCount");
const actualLabel = document.getElementById("actualLabel");
const undoButton = document.getElementById("undoButton");
const alignmentStatus = document.getElementById("alignmentStatus");
const statusDot = document.getElementById("statusDot");
const candidateButtons = [...document.querySelectorAll(".candidate")];
const PATTERN = [
{
key: "wedge",
letter: "A",
name: "Coral wedge",
color: "#e97152",
className: "shape-wedge"
},
{
key: "block",
letter: "B",
name: "Teal block",
color: "#2d8c82",
className: "shape-block"
},
{
key: "diamond",
letter: "C",
name: "Navy diamond",
color: "#34485f",
className: "shape-diamond"
}
];
const patternByKey = Object.fromEntries(PATTERN.map((item) => [item.key, item]));
const SPACING = 1.34;
const INITIAL_COUNT = 6;
let selectedKey = "wedge";
let nextIndex = INITIAL_COUNT;
let nextX = (INITIAL_COUNT - 2.5) * SPACING;
let entries = [];
let animations = [];
let toastTimer = 0;
let dragState = null;
let dragGhost = null;
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee9dd);
scene.fog = new THREE.Fog(0xeee9dd, 18, 38);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Low-poly geometric strip. Drag to orbit, scroll to zoom, and click the next slot to place the selected block."
);
stage.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-6, 6, 4, -4, 0.1, 100);
const cameraTarget = new THREE.Vector3(0.35, 0.05, 0);
const orbit = {
azimuth: 0.34,
polar: 0.83,
zoom: 1,
active: false,
moved: false,
startX: 0,
startY: 0,
startAzimuth: 0,
startPolar: 0
};
const hemisphere = new THREE.HemisphereLight(0xfff9e9, 0x7f887d, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4dd, 3.3);
keyLight.position.set(-5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x8fc9c0, 1.15);
fillLight.position.set(8, 5, -7);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 30),
new THREE.MeshStandardMaterial({
color: 0xe9e3d6,
roughness: 1,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.11;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 24, 0x8d958c, 0xa8aa9e);
grid.position.y = -0.095;
grid.material.transparent = true;
grid.material.opacity = 0.16;
scene.add(grid);
const stripGroup = new THREE.Group();
stripGroup.rotation.y = -0.075;
scene.add(stripGroup);
const tileGeometry = new THREE.BoxGeometry(1.03, 0.15, 1.16);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xfaf6ec,
roughness: 0.94,
flatShading: true
});
const accentGeometry = new THREE.BoxGeometry(0.26, 0.025, 0.035);
const shapeGeometries = {
wedge: new THREE.CylinderGeometry(0.4, 0.4, 0.28, 3, 1, false),
block: new THREE.BoxGeometry(0.62, 0.5, 0.62),
diamond: new THREE.OctahedronGeometry(0.43, 0)
};
const shapeEdges = {
wedge: new THREE.EdgesGeometry(shapeGeometries.wedge, 18),
block: new THREE.EdgesGeometry(shapeGeometries.block, 18),
diamond: new THREE.EdgesGeometry(shapeGeometries.diamond, 18)
};
const shapeMaterials = {
wedge: new THREE.MeshStandardMaterial({
color: PATTERN[0].color,
roughness: 0.68,
flatShading: true
}),
block: new THREE.MeshStandardMaterial({
color: PATTERN[1].color,
roughness: 0.72,
flatShading: true
}),
diamond: new THREE.MeshStandardMaterial({
color: PATTERN[2].color,
roughness: 0.62,
flatShading: true
})
};
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x17272c,
transparent: true,
opacity: 0.17
});
// The next-slot marker is a deliberately low-poly, dashed footprint.
const ghostGroup = new THREE.Group();
stripGroup.add(ghostGroup);
const ghostFillMaterial = new THREE.MeshBasicMaterial({
color: 0x2d8c82,
transparent: true,
opacity: 0.075,
depthWrite: false
});
const ghostFill = new THREE.Mesh(
new THREE.PlaneGeometry(1.04, 1.17),
ghostFillMaterial
);
ghostFill.rotation.x = -Math.PI / 2;
ghostFill.position.y = 0.075;
ghostGroup.add(ghostFill);
const outlinePoints = [
new THREE.Vector3(-0.52, 0.085, -0.58),
new THREE.Vector3(0.52, 0.085, -0.58),
new THREE.Vector3(0.52, 0.085, 0.58),
new THREE.Vector3(-0.52, 0.085, 0.58),
new THREE.Vector3(-0.52, 0.085, -0.58)
];
const outlineMaterial = new THREE.LineDashedMaterial({
color: 0x2d8c82,
dashSize: 0.13,
gapSize: 0.08,
transparent: true,
opacity: 0.82
});
const ghostOutline = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(outlinePoints),
outlineMaterial
);
ghostOutline.computeLineDistances();
ghostGroup.add(ghostOutline);
const slotHitbox = new THREE.Mesh(
new THREE.BoxGeometry(1.1, 0.72, 1.22),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
slotHitbox.position.y = 0.38;
slotHitbox.userData.isNextSlot = true;
ghostGroup.add(slotHitbox);
const feedbackMaterial = new THREE.MeshBasicMaterial({
color: 0x648a48,
transparent: true,
opacity: 0,
depthWrite: false
});
const feedbackRing = new THREE.Mesh(
new THREE.TorusGeometry(0.48, 0.022, 6, 28),
feedbackMaterial
);
feedbackRing.rotation.x = Math.PI / 2;
feedbackRing.position.y = 0.1;
feedbackRing.visible = false;
stripGroup.add(feedbackRing);
// A few quiet background forms add depth without competing with the strip.
const sceneryMaterial = new THREE.MeshStandardMaterial({
color: 0xc7c3b5,
roughness: 1,
flatShading: true
});
const scenery = [
{ geometry: new THREE.ConeGeometry(0.45, 1.1, 5), position: [-6.3, 0.43, -2.8] },
{ geometry: new THREE.DodecahedronGeometry(0.34, 0), position: [5.6, 0.22, -3.4] },
{ geometry: new THREE.CylinderGeometry(0.32, 0.38, 0.48, 6), position: [-5.6, 0.12, 3.8] }
];
for (const item of scenery) {
const mesh = new THREE.Mesh(item.geometry, sceneryMaterial);
mesh.position.set(...item.position);
mesh.rotation.set(0.2, 0.4, 0.08);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
function updateCamera() {
const radius = 16;
const horizontal = Math.sin(orbit.polar) * radius;
camera.position.set(
cameraTarget.x + Math.sin(orbit.azimuth) * horizontal,
cameraTarget.y + Math.cos(orbit.polar) * radius,
cameraTarget.z + Math.cos(orbit.azimuth) * horizontal
);
camera.lookAt(cameraTarget);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
}
function resetCamera() {
orbit.azimuth = 0.34;
orbit.polar = 0.83;
orbit.zoom = 1;
updateCamera();
showToast("Camera view reset.");
}
function resize() {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
const aspect = width / height;
const viewHeight = Math.max(7.15, 10.7 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
updateCamera();
// -------------------------------------------------------------------------
// Strip construction and interaction
// -------------------------------------------------------------------------
function createEntry(absoluteIndex, shapeKey, x, animate = false) {
const shape = patternByKey[shapeKey];
const group = new THREE.Group();
group.position.x = x;
const tile = new THREE.Mesh(tileGeometry, tileMaterial);
tile.castShadow = true;
tile.receiveShadow = true;
group.add(tile);
const accent = new THREE.Mesh(accentGeometry, shapeMaterials[shapeKey]);
accent.position.set(0, 0.09, 0.53);
group.add(accent);
const piece = new THREE.Group();
const mesh = new THREE.Mesh(shapeGeometries[shapeKey], shapeMaterials[shapeKey]);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.rotation.y = shapeKey === "wedge" ? Math.PI / 2 : shapeKey === "diamond" ? 0.35 : 0.12;
if (shapeKey === "wedge") mesh.position.y = 0.26;
if (shapeKey === "block") mesh.position.y = 0.34;
if (shapeKey === "diamond") {
mesh.position.y = 0.47;
mesh.scale.set(1, 1.08, 0.86);
}
const edges = new THREE.Line(shapeEdges[shapeKey], edgeMaterial);
edges.position.copy(mesh.position);
edges.rotation.copy(mesh.rotation);
edges.scale.copy(mesh.scale);
mesh.add(edges);
piece.add(mesh);
group.add(piece);
if (animate) {
piece.position.y = 1.15;
piece.scale.setScalar(0.05);
animations.push({
piece,
started: performance.now(),
duration: 520
});
}
stripGroup.add(group);
return {
absoluteIndex,
shapeKey,
group,
piece
};
}
function rebuildInitialStrip() {
for (const entry of entries) stripGroup.remove(entry.group);
entries = [];
animations = [];
nextIndex = INITIAL_COUNT;
nextX = (INITIAL_COUNT - 2.5) * SPACING;
for (let i = 0; i < INITIAL_COUNT; i++) {
entries.push(
createEntry(i, PATTERN[i % PATTERN.length].key, (i - 2.5) * SPACING)
);
}
feedbackRing.visible = false;
updateGhostPosition();
updateUI();
}
function updateGhostPosition() {
ghostGroup.position.x = nextX;
}
function placePiece(shapeKey) {
// Keep the visible run compact. Old pieces leave the scene after eight.
if (entries.length >= 8) {
const oldest = entries.shift();
stripGroup.remove(oldest.group);
for (const entry of entries) entry.group.position.x -= SPACING;
nextX -= SPACING;
}
const entry = createEntry(nextIndex, shapeKey, nextX, true);
entries.push(entry);
nextIndex += 1;
nextX += SPACING;
const expected = PATTERN[entry.absoluteIndex % PATTERN.length];
const correct = expected.key === shapeKey;
feedbackMaterial.color.set(correct ? 0x648a48 : 0xbc4f46);
feedbackMaterial.opacity = 0.9;
feedbackRing.position.x = entry.group.position.x;
feedbackRing.scale.setScalar(0.7);
feedbackRing.visible = true;
updateGhostPosition();
updateUI();
if (correct) {
showToast(`${shapeKey === expected.key ? "Perfect" : "Placed"}: the ${expected.name.toLowerCase()} continues the motif.`);
} else {
showToast(`Placed, but the rule expected the ${expected.name.toLowerCase()}. Undo to try again.`);
}
}
function undoLast() {
if (nextIndex <= INITIAL_COUNT) return;
const last = entries.pop();
if (last) stripGroup.remove(last.group);
nextIndex -= 1;
nextX -= SPACING;
feedbackRing.visible = false;
updateGhostPosition();
updateUI();
showToast("Last block removed. The next slot is ready.");
}
function resetStrip() {
rebuildInitialStrip();
showToast("Strip reset to the original six-piece lead-in.");
}
function shapeMarkup(shapeKey) {
const item = patternByKey[shapeKey];
return `<span class="mini-shape ${item.className}" style="--shape-color:${item.color}"></span>`;
}
function selectShape(shapeKey) {
selectedKey = shapeKey;
const item = patternByKey[shapeKey];
candidateButtons.forEach((button) => {
const selected = button.dataset.shape === shapeKey;
button.classList.toggle("selected", selected);
button.setAttribute("aria-pressed", String(selected));
});
selectedName.textContent = item.name;
}
function updateUI() {
const expectedPattern = PATTERN[nextIndex % PATTERN.length];
expectedNext.textContent = `${expectedPattern.letter} · ${expectedPattern.name}`;
nextLabel.textContent = `Next · ${expectedPattern.letter} ${expectedPattern.name.split(" ")[1]}`;
const mismatches = entries.filter((entry) => {
const expected = PATTERN[entry.absoluteIndex % PATTERN.length];
return expected.key !== entry.shapeKey;
});
expectedRow.innerHTML = entries
.map((entry) => {
const expected = PATTERN[entry.absoluteIndex % PATTERN.length];
return `<div class="compare-item correct" title="Expected ${expected.name}">${shapeMarkup(expected.key)}</div>`;
})
.join("");
actualRow.innerHTML = entries
.map((entry) => {
const expected = PATTERN[entry.absoluteIndex % PATTERN.length];
const correct = expected.key === entry.shapeKey;
return `
<div class="compare-item ${correct ? "correct" : "wrong"}" title="${patternByKey[entry.shapeKey].name}">
${shapeMarkup(entry.shapeKey)}
</div>
`;
})
.join("");
const aligned = entries.length - mismatches.length;
alignmentStatus.textContent = `${aligned} / ${entries.length} aligned`;
statusDot.classList.toggle("has-error", mismatches.length > 0);
pieceCount.textContent = `${entries.length} ${entries.length === 1 ? "piece" : "pieces"}`;
actualLabel.textContent = `${entries.length} ${entries.length === 1 ? "block" : "blocks"}`;
undoButton.disabled = nextIndex <= INITIAL_COUNT;
if (mismatches.length > 0) {
const last = entries[entries.length - 1];
const expected = PATTERN[last.absoluteIndex % PATTERN.length];
const lastIsWrong = last.shapeKey !== expected.key;
verdict.classList.add("bad");
verdict.querySelector(".verdict-icon").textContent = "!";
compareBadge.textContent = "Rhythm break";
verdictText.textContent = lastIsWrong
? `Not quite: the rule expects the ${expected.name.toLowerCase()}. Undo the last block to retry.`
: `The strip contains ${mismatches.length} rule mismatch${mismatches.length === 1 ? "" : "es"}.`;
} else {
verdict.classList.remove("bad");
verdict.querySelector(".verdict-icon").textContent = "✓";
compareBadge.textContent = "Rule holds";
verdictText.textContent =
nextIndex > INITIAL_COUNT
? "Perfect continuation. The three-piece motif still holds."
: "The six-piece lead-in matches the rule. Add the next block.";
}
}
function showToast(message) {
clearTimeout(toastTimer);
toast.textContent = message;
toast.classList.add("visible");
toastTimer = window.setTimeout(() => toast.classList.remove("visible"), 2600);
}
// -------------------------------------------------------------------------
// Picking and custom camera controls
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pointerToNdc(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
return rect;
}
function isPointerOverSlot(event, tolerance = 72) {
const rect = pointerToNdc(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObject(slotHitbox, false);
if (hits.length) return true;
const slot = getSlotScreenPosition();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
return Math.hypot(x - slot.x, y - slot.y) < tolerance;
}
function getSlotScreenPosition() {
const world = new THREE.Vector3(0, 0.76, 0);
ghostGroup.localToWorld(world);
world.project(camera);
const rect = stage.getBoundingClientRect();
return {
x: (world.x * 0.5 + 0.5) * rect.width,
y: (-world.y * 0.5 + 0.5) * rect.height
};
}
function setSlotHover(active) {
ghostFillMaterial.opacity = active ? 0.17 : 0.075;
outlineMaterial.opacity = active ? 1 : 0.82;
renderer.domElement.style.cursor = active ? "pointer" : "grab";
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
orbit.active = true;
orbit.moved = false;
orbit.startX = event.clientX;
orbit.startY = event.clientY;
orbit.startAzimuth = orbit.azimuth;
orbit.startPolar = orbit.polar;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (orbit.active) {
const dx = event.clientX - orbit.startX;
const dy = event.clientY - orbit.startY;
if (Math.hypot(dx, dy) > 4) orbit.moved = true;
if (orbit.moved) {
orbit.azimuth = orbit.startAzimuth - dx * 0.006;
orbit.polar = THREE.MathUtils.clamp(
orbit.startPolar + dy * 0.005,
0.48,
1.25
);
updateCamera();
setSlotHover(false);
}
return;
}
setSlotHover(isPointerOverSlot(event));
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!orbit.active) return;
const wasMoved = orbit.moved;
orbit.active = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (!wasMoved && isPointerOverSlot(event)) {
placePiece(selectedKey);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
orbit.active = false;
orbit.moved = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.65
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("resetCamera").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Palette: click selection plus drag-and-drop onto the next slot
// -------------------------------------------------------------------------
candidateButtons.forEach((button) => {
button.addEventListener("click", () => {
selectShape(button.dataset.shape);
});
button.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
selectShape(button.dataset.shape);
dragState = {
key: button.dataset.shape,
startX: event.clientX,
startY: event.clientY,
moved: false,
pointerId: event.pointerId
};
button.setPointerCapture(event.pointerId);
event.preventDefault();
});
});
document.addEventListener("pointermove", (event) => {
if (!dragState) return;
const distance = Math.hypot(
event.clientX - dragState.startX,
event.clientY - dragState.startY
);
if (distance > 6) dragState.moved = true;
if (!dragState.moved) return;
if (!dragGhost) {
dragGhost = document.createElement("div");
dragGhost.className = "drag-ghost";
dragGhost.innerHTML = shapeMarkup(dragState.key);
document.body.appendChild(dragGhost);
}
dragGhost.style.left = `${event.clientX}px`;
dragGhost.style.top = `${event.clientY}px`;
});
document.addEventListener("pointerup", (event) => {
if (!dragState) return;
const state = dragState;
dragState = null;
if (dragGhost) {
dragGhost.remove();
dragGhost = null;
}
if (!state.moved) return;
const rect = renderer.domElement.getBoundingClientRect();
const overCanvas =
event.clientX >= rect.left &&
event.clientX <= rect.right &&
event.clientY >= rect.top &&
event.clientY <= rect.bottom;
if (overCanvas && isPointerOverSlot(event, 105)) {
placePiece(state.key);
} else if (overCanvas) {
showToast("Drop the block on the glowing dotted slot.");
} else {
showToast(`${patternByKey[state.key].name} selected. Click the dotted slot to place it.`);
}
});
document.getElementById("placeButton").addEventListener("click", () => {
placePiece(selectedKey);
});
undoButton.addEventListener("click", undoLast);
document.getElementById("resetStrip").addEventListener("click", resetStrip);
// -------------------------------------------------------------------------
// Animation and render loop
// -------------------------------------------------------------------------
function easeOutBack(t) {
const c1 = 1.70158;
const c3 = c1 + 1;
return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
}
function animate(now) {
requestAnimationFrame(animate);
for (let i = animations.length - 1; i >= 0; i--) {
const animation = animations[i];
const t = THREE.MathUtils.clamp(
(now - animation.started) / animation.duration,
0,
1
);
const eased = 1 - Math.pow(1 - t, 3);
const scale = Math.max(0.05, easeOutBack(t));
animation.piece.position.y = (1 - eased) * 1.15;
animation.piece.rotation.y = (1 - eased) * -0.55;
animation.piece.scale.setScalar(scale);
if (t >= 1) {
animation.piece.position.y = 0;
animation.piece.rotation.y = 0;
animation.piece.scale.setScalar(1);
animations.splice(i, 1);
}
}
if (feedbackRing.visible) {
feedbackMaterial.opacity = Math.max(0, feedbackMaterial.opacity - 0.018);
const scale = feedbackRing.scale.x + 0.008;
feedbackRing.scale.setScalar(scale);
if (feedbackMaterial.opacity <= 0) feedbackRing.visible = false;
}
const slot = getSlotScreenPosition();
nextLabel.style.left = `${slot.x}px`;
nextLabel.style.top = `${slot.y}px`;
renderer.render(scene, camera);
}
rebuildInitialStrip();
requestAnimationFrame(animate);
</script>
</body>
</html>
```