Prompt specification
Build or customize the Three.js 3D scene "Decode a Noisy Timed Message" 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: Decode a Noisy Timed Message
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/decode-a-noisy-timed-message-x3396
Scene Description Prompt:
Build a toy Morse puzzle with bounded timing variation and a known alphabet. Let users inspect intervals and report ambiguous symbols instead of forcing an unsupported decoding. Build this with Three.js from cdnjs as a low-poly scene in one self-contained HTML file.
Working Three.js Starter (decode-a-noisy-timed-message-x3396):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Boundary Beacon — Morse Interval Puzzle</title>
<style>
:root {
color-scheme: dark;
--bg: #07121c;
--panel: rgba(10, 24, 36, 0.88);
--panel-strong: rgba(8, 20, 31, 0.96);
--line: rgba(166, 207, 221, 0.17);
--line-strong: rgba(166, 207, 221, 0.3);
--text: #e8f2f4;
--muted: #91a8b3;
--cyan: #72e2d1;
--cyan-dim: #2c8f87;
--amber: #ffbf69;
--red: #ff7d76;
--green: #83e6a4;
--shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
select,
input,
textarea {
font: inherit;
}
button,
select {
color: var(--text);
}
button {
cursor: pointer;
}
button:disabled {
cursor: not-allowed;
opacity: 0.42;
}
button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 38%, transparent 25%, rgba(1, 7, 12, 0.2) 65%),
linear-gradient(180deg, rgba(2, 9, 14, 0.22), rgba(2, 9, 14, 0.48));
z-index: 1;
}
header {
position: fixed;
z-index: 5;
top: 0;
left: 0;
right: 0;
height: 72px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 0 22px;
border-bottom: 1px solid var(--line);
background: linear-gradient(180deg, rgba(5, 15, 23, 0.95), rgba(5, 15, 23, 0.66));
backdrop-filter: blur(18px);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 38px;
height: 38px;
display: grid;
place-items: center;
flex: 0 0 auto;
border: 1px solid rgba(114, 226, 209, 0.5);
border-radius: 12px;
color: var(--cyan);
background: rgba(114, 226, 209, 0.08);
box-shadow: inset 0 0 18px rgba(114, 226, 209, 0.08);
}
.brand-mark svg {
width: 22px;
height: 22px;
}
.brand h1 {
margin: 0;
font-size: 15px;
line-height: 1.1;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.08em;
}
.header-actions {
display: flex;
align-items: center;
gap: 9px;
}
.compact-select,
.button {
min-height: 38px;
border: 1px solid var(--line-strong);
border-radius: 10px;
background: rgba(17, 37, 52, 0.86);
transition:
border-color 140ms ease,
background 140ms ease,
transform 140ms ease;
}
.compact-select {
padding: 0 34px 0 12px;
}
.button {
padding: 9px 14px;
font-weight: 700;
font-size: 12px;
letter-spacing: 0.035em;
}
.button:hover:not(:disabled),
.compact-select:hover {
border-color: rgba(114, 226, 209, 0.55);
background: rgba(24, 54, 70, 0.92);
}
.button:active:not(:disabled) {
transform: translateY(1px);
}
.button.primary {
color: #05201f;
border-color: transparent;
background: linear-gradient(135deg, #8bf0df, #55cdbd);
box-shadow: 0 8px 24px rgba(48, 183, 166, 0.16);
}
.button.primary:hover:not(:disabled) {
background: linear-gradient(135deg, #a0f5e7, #66d9c9);
}
.button.warning {
color: #26190b;
border-color: transparent;
background: linear-gradient(135deg, #ffd28b, #f3aa4f);
}
.button.ghost {
background: transparent;
}
main {
position: relative;
z-index: 3;
width: min(1480px, calc(100% - 36px));
height: calc(100vh - 92px);
margin: 82px auto 18px;
display: grid;
grid-template-columns: minmax(560px, 1fr) 390px;
gap: 16px;
pointer-events: none;
}
.panel {
pointer-events: auto;
border: 1px solid var(--line);
border-radius: 18px;
background:
linear-gradient(145deg, rgba(15, 34, 48, 0.93), rgba(7, 20, 31, 0.88));
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.left-column {
min-width: 0;
display: grid;
grid-template-rows: minmax(440px, auto) minmax(250px, 1fr);
gap: 16px;
overflow: auto;
scrollbar-width: thin;
scrollbar-color: var(--cyan-dim) transparent;
}
.right-column {
min-width: 0;
display: grid;
grid-template-rows: auto minmax(0, 1fr);
gap: 16px;
overflow: hidden;
}
.puzzle-panel {
padding: 22px;
}
.eyebrow-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.badge {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted);
background: rgba(0, 0, 0, 0.12);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.badge::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 10px var(--amber);
}
.puzzle-panel h2 {
margin: 12px 0 7px;
font-size: clamp(24px, 3vw, 38px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro {
max-width: 680px;
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.6;
}
.transport {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 9px;
margin-top: 19px;
}
.speed-control {
display: flex;
align-items: center;
gap: 8px;
margin-left: auto;
color: var(--muted);
font-size: 11px;
}
.speed-control select {
min-height: 36px;
}
.sound-label {
display: inline-flex;
align-items: center;
gap: 6px;
min-height: 36px;
color: var(--muted);
font-size: 11px;
}
.sound-label input {
accent-color: var(--cyan);
}
.timeline-shell {
margin-top: 18px;
padding: 13px 13px 9px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(2, 12, 19, 0.42);
}
.timeline-head {
display: flex;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
#timeline {
position: relative;
height: 56px;
overflow: hidden;
border-radius: 8px;
background:
repeating-linear-gradient(
90deg,
rgba(255, 255, 255, 0.035) 0,
rgba(255, 255, 255, 0.035) 1px,
transparent 1px,
transparent 10%
),
rgba(0, 0, 0, 0.23);
}
.timeline-segment {
position: absolute;
top: 8px;
bottom: 8px;
min-width: 2px;
overflow: hidden;
border: 0;
border-radius: 3px;
background: rgba(78, 122, 143, 0.18);
cursor: pointer;
}
.timeline-segment.on {
background: linear-gradient(180deg, #ffd595, #e99b45);
box-shadow: 0 0 16px rgba(255, 182, 87, 0.18);
}
.timeline-segment.off {
background: rgba(66, 115, 137, 0.23);
}
.timeline-segment.selected {
outline: 2px solid var(--cyan);
outline-offset: 1px;
z-index: 3;
}
.timeline-segment span {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
color: rgba(9, 20, 26, 0.8);
font-size: 9px;
font-weight: 900;
}
#playhead {
position: absolute;
z-index: 4;
top: 0;
bottom: 0;
left: 0;
width: 2px;
pointer-events: none;
background: #fff;
box-shadow: 0 0 10px #fff;
}
.timeline-ruler {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #6f8995;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.sequence-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 20px;
}
.sequence-heading h3,
.panel h3 {
margin: 0;
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.sequence-heading p {
margin: 0;
color: var(--muted);
font-size: 10px;
}
.slots {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
gap: 9px;
margin-top: 10px;
}
.slot {
position: relative;
min-height: 70px;
display: grid;
place-items: center;
border: 1px solid var(--line);
border-radius: 12px;
color: var(--muted);
background: rgba(3, 13, 21, 0.38);
font-size: 23px;
font-weight: 800;
transition: 140ms ease;
}
.slot small {
position: absolute;
top: 7px;
left: 8px;
color: #718994;
font-size: 9px;
font-weight: 700;
}
.slot:hover {
border-color: var(--line-strong);
background: rgba(20, 45, 61, 0.55);
}
.slot.current {
border-color: rgba(114, 226, 209, 0.75);
color: var(--text);
box-shadow:
inset 0 0 22px rgba(114, 226, 209, 0.08),
0 0 0 1px rgba(114, 226, 209, 0.1);
}
.slot.answered {
color: var(--text);
}
.slot.correct {
color: var(--green);
border-color: rgba(131, 230, 164, 0.55);
}
.slot.wrong {
color: var(--red);
border-color: rgba(255, 125, 118, 0.55);
}
.slot.safe {
color: var(--amber);
border-color: rgba(255, 191, 105, 0.65);
}
.reading-card {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
align-items: center;
gap: 16px;
margin-top: 15px;
padding: 14px 15px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(3, 14, 22, 0.4);
}
.reading-card.ambiguous {
border-color: rgba(255, 191, 105, 0.45);
background: rgba(255, 191, 105, 0.055);
}
.reading-card h4 {
margin: 0 0 5px;
font-size: 13px;
}
.reading-card p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.observed-pattern {
min-width: 110px;
text-align: right;
}
.observed-pattern small {
display: block;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.observed-pattern strong {
display: block;
margin-top: 5px;
color: var(--amber);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 21px;
letter-spacing: 0.12em;
}
.answer-panel {
min-height: 0;
padding: 19px 21px;
display: flex;
flex-direction: column;
}
.answer-panel h3 {
margin-bottom: 5px;
}
.answer-hint {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.candidate-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(43px, 1fr));
gap: 7px;
margin-top: 13px;
overflow: auto;
padding-right: 3px;
}
.candidate {
min-height: 41px;
border: 1px solid var(--line);
border-radius: 9px;
color: var(--text);
background: rgba(18, 42, 56, 0.72);
font-weight: 800;
transition: 120ms ease;
}
.candidate:hover:not(:disabled) {
color: #061b1b;
border-color: var(--cyan);
background: var(--cyan);
transform: translateY(-1px);
}
.answer-footer {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 10px;
margin-top: 13px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.answer-footer small {
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.inspector-panel {
padding: 18px;
}
.selected-reading {
margin-top: 13px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(2, 12, 19, 0.45);
}
.selected-reading.ambiguous {
border-color: rgba(255, 191, 105, 0.46);
background: rgba(255, 191, 105, 0.055);
}
.selected-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.selected-title strong {
font-size: 13px;
}
.reading-chip {
padding: 5px 7px;
border-radius: 7px;
color: var(--cyan);
background: rgba(114, 226, 209, 0.08);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.reading-chip.ambiguous {
color: var(--amber);
background: rgba(255, 191, 105, 0.1);
}
.range-visual {
position: relative;
height: 38px;
margin: 15px 0 8px;
border-radius: 8px;
background:
linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
rgba(0, 0, 0, 0.18);
background-size: 10% 100%;
overflow: hidden;
}
.range-band {
position: absolute;
top: 10px;
height: 17px;
border-radius: 5px;
background: rgba(114, 226, 209, 0.32);
border: 1px solid rgba(114, 226, 209, 0.72);
}
.range-band.ambiguous {
background: rgba(255, 191, 105, 0.28);
border-color: rgba(255, 191, 105, 0.8);
}
.threshold {
position: absolute;
top: 5px;
bottom: 5px;
width: 2px;
background: var(--text);
opacity: 0.8;
}
.range-labels {
display: flex;
justify-content: space-between;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
}
.selected-explanation {
margin: 11px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.interval-panel {
min-height: 0;
display: flex;
flex-direction: column;
padding: 18px;
overflow: hidden;
}
.interval-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.model-note {
margin: 7px 0 12px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.table-wrap {
min-height: 0;
flex: 1;
overflow: auto;
border: 1px solid var(--line);
border-radius: 11px;
scrollbar-width: thin;
scrollbar-color: var(--cyan-dim) transparent;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 10px;
}
th {
position: sticky;
z-index: 2;
top: 0;
padding: 9px 8px;
color: #8099a5;
background: #0a1d2a;
text-align: left;
font-size: 9px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
td {
padding: 9px 8px;
border-top: 1px solid rgba(166, 207, 221, 0.09);
color: #b8c9d0;
white-space: nowrap;
}
tbody tr {
cursor: pointer;
}
tbody tr:hover,
tbody tr.selected {
background: rgba(114, 226, 209, 0.075);
}
tbody tr.selected {
box-shadow: inset 2px 0 var(--cyan);
}
.table-ambiguous {
color: var(--amber) !important;
font-weight: 800;
}
.result {
margin-top: 14px;
padding: 13px 15px;
border: 1px solid rgba(131, 230, 164, 0.38);
border-radius: 12px;
background: rgba(131, 230, 164, 0.06);
}
.result.bad {
border-color: rgba(255, 125, 118, 0.4);
background: rgba(255, 125, 118, 0.055);
}
.result strong {
font-size: 13px;
}
.result p {
margin: 5px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
dialog {
width: min(760px, calc(100% - 30px));
max-height: min(82vh, 760px);
padding: 0;
overflow: hidden;
color: var(--text);
border: 1px solid var(--line-strong);
border-radius: 18px;
background: var(--panel-strong);
box-shadow: 0 30px 100px rgba(0, 0, 0, 0.62);
}
dialog::backdrop {
background: rgba(1, 7, 12, 0.76);
backdrop-filter: blur(7px);
}
.dialog-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
padding: 18px 20px;
border-bottom: 1px solid var(--line);
}
.dialog-header h2 {
margin: 0;
font-size: 17px;
}
.dialog-body {
max-height: calc(82vh - 72px);
padding: 20px;
overflow: auto;
}
.dialog-copy {
margin: 0 0 17px;
color: var(--muted);
font-size: 12px;
line-height: 1.65;
}
.alphabet-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
gap: 8px;
}
.alphabet-item {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(19, 43, 58, 0.58);
}
.alphabet-item strong {
font-size: 13px;
}
.alphabet-item code {
color: var(--amber);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 13px;
letter-spacing: 0.12em;
}
#reportDialog {
width: min(510px, calc(100% - 30px));
}
.form-field {
display: grid;
gap: 7px;
margin-top: 15px;
}
.form-field label {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.form-field select,
.form-field textarea {
width: 100%;
padding: 11px 12px;
color: var(--text);
border: 1px solid var(--line-strong);
border-radius: 10px;
background: #0c2230;
}
.form-field textarea {
min-height: 84px;
resize: vertical;
}
.dialog-actions {
display: flex;
justify-content: flex-end;
gap: 9px;
margin-top: 20px;
}
.mobile-help {
display: none;
}
@media (max-width: 1050px) {
body {
overflow: auto;
}
header {
position: sticky;
}
main {
height: auto;
min-height: calc(100vh - 90px);
grid-template-columns: 1fr;
}
.left-column {
overflow: visible;
}
.right-column {
overflow: visible;
}
.table-wrap {
max-height: 360px;
}
}
@media (max-width: 680px) {
header {
height: auto;
min-height: 70px;
padding: 12px;
align-items: flex-start;
}
.brand p {
display: none;
}
.brand h1 {
max-width: 150px;
font-size: 12px;
}
.header-actions {
flex-wrap: wrap;
justify-content: flex-end;
}
.header-actions .button {
padding-inline: 10px;
}
main {
width: calc(100% - 20px);
margin-top: 78px;
}
.puzzle-panel,
.answer-panel,
.inspector-panel,
.interval-panel {
padding: 15px;
}
.slots {
gap: 5px;
}
.slot {
min-height: 58px;
}
.reading-card {
grid-template-columns: 1fr;
}
.observed-pattern {
text-align: left;
}
.speed-control {
margin-left: 0;
}
.mobile-help {
display: block;
margin-top: 9px;
color: var(--muted);
font-size: 9px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Low-poly lighthouse beacon scene"></canvas>
<div class="vignette"></div>
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
<path d="M8 20h8M9 20l1-9h4l1 9M10 11V7h4v4"/>
<path d="M7 7h10M12 7V3M9 3h6"/>
<path d="M3 12h3M18 12h3M4.5 8.5 6.7 10M19.5 8.5 17.3 10"/>
</svg>
</div>
<div>
<h1>Boundary Beacon</h1>
<p>Interval evidence before interpretation</p>
</div>
</div>
<div class="header-actions">
<select id="alphabetScope" class="compact-select" aria-label="Known alphabet">
<option value="letters">Known alphabet: A–Z</option>
<option value="letters-digits">Known alphabet: A–Z + 0–9</option>
</select>
<button id="openAlphabet" class="button ghost">Morse table</button>
</div>
</header>
<main>
<section class="left-column">
<article class="panel puzzle-panel">
<div class="eyebrow-row">
<span class="eyebrow" id="transmissionLabel">Transmission 01</span>
<span class="badge">Bounded timing envelope</span>
</div>
<h2>Read the signal, not the guess.</h2>
<p class="intro">
Replay the beacon, inspect its measured intervals, and use the known Morse alphabet.
When the evidence overlaps a decision boundary, report an ambiguous symbol instead
of inventing a decoding the measurements do not support.
</p>
<div class="transport">
<button id="playButton" class="button primary">▶ Play</button>
<button id="replayButton" class="button">↻ Replay</button>
<button id="newButton" class="button">New signal</button>
<label class="sound-label">
<input id="soundOn" type="checkbox" checked>
Sound
</label>
<label class="speed-control">
Speed
<select id="speed" class="compact-select">
<option value="0.65">0.65×</option>
<option value="0.85">0.85×</option>
<option value="1" selected>1×</option>
<option value="1.25">1.25×</option>
<option value="1.5">1.5×</option>
</select>
</label>
</div>
<div class="timeline-shell">
<div class="timeline-head">
<span>Measured transmission</span>
<span id="timelineLength">0.00 u</span>
</div>
<div id="timeline" aria-label="Transmission timeline"></div>
<div class="timeline-ruler">
<span>0 u</span>
<span>Click an interval to inspect it</span>
<span id="timelineEnd">0 u</span>
</div>
</div>
<div class="sequence-heading">
<h3>Decoded sequence</h3>
<p>Select a slot to revisit it</p>
</div>
<div id="slots" class="slots"></div>
<div id="readingCard" class="reading-card">
<div>
<h4 id="evidenceHeadline">Inspect the current symbol</h4>
<p id="evidenceText">Replay the signal and select an interval.</p>
</div>
<div class="observed-pattern">
<small>Observed marks</small>
<strong id="observedPattern">—</strong>
</div>
</div>
<div id="result" class="result" hidden></div>
</article>
<article class="panel answer-panel">
<h3>Known alphabet</h3>
<p class="answer-hint" id="candidateHint">
Choose the symbol supported by the current interval evidence.
</p>
<div id="candidateGrid" class="candidate-grid"></div>
<div class="answer-footer">
<small>
“?” means the evidence was reported as ambiguous; it is not a decoded letter.
<span class="mobile-help">Drag the scene to orbit. Scroll to zoom.</span>
</small>
<button id="reportButton" class="button warning">Report ambiguous symbol</button>
</div>
</article>
</section>
<aside class="right-column">
<article class="panel inspector-panel">
<div class="eyebrow-row">
<h3>Interval inspector</h3>
<span class="badge" id="inspectorBadge">Ready</span>
</div>
<div id="selectedReading" class="selected-reading">
<div class="selected-title">
<strong id="selectedTitle">No interval selected</strong>
<span id="readingChip" class="reading-chip">—</span>
</div>
<div class="range-visual">
<div id="rangeBand" class="range-band"></div>
<div id="threshold" class="threshold"></div>
</div>
<div class="range-labels">
<span id="rangeMin">—</span>
<span id="rangeMax">—</span>
</div>
<p id="selectedExplanation" class="selected-explanation"></p>
</div>
</article>
<article class="panel interval-panel">
<div class="interval-heading">
<h3>Measured intervals</h3>
<span class="badge">±40% source bound</span>
</div>
<p class="model-note">
Marks use a 1.50 u boundary; silence uses a 1.00 u boundary.
Measurement uncertainty is ±0.16 u for marks and ±0.12 u for gaps.
The original source truth is never shown.
</p>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Slot</th>
<th>Edge</th>
<th>Measured</th>
<th>Evidence</th>
</tr>
</thead>
<tbody id="intervalRows"></tbody>
</table>
</div>
</article>
</aside>
</main>
<dialog id="alphabetDialog">
<div class="dialog-header">
<h2>Known Morse alphabet</h2>
<button class="button ghost" data-close="alphabetDialog">Close</button>
</div>
<div class="dialog-body">
<p class="dialog-copy">
The puzzle only expects symbols from the selected finite alphabet.
An interval can still be ambiguous even when its symbol belongs to this table.
</p>
<div id="alphabetGrid" class="alphabet-grid"></div>
</div>
</dialog>
<dialog id="reportDialog">
<div class="dialog-header">
<h2>Report an ambiguous symbol</h2>
<button class="button ghost" data-close="reportDialog">Cancel</button>
</div>
<div class="dialog-body">
<p class="dialog-copy">
This records “?” for the current symbol. It deliberately avoids assigning a letter
that the available interval evidence cannot establish.
</p>
<form id="reportForm">
<div class="form-field">
<label for="reportInterval">Evidence interval</label>
<select id="reportInterval"></select>
</div>
<div class="form-field">
<label for="reportReason">Why is it ambiguous?</label>
<select id="reportReason">
<option>Timing range crosses a decision boundary</option>
<option>The mark cannot be distinguished reliably</option>
<option>The gap cannot be distinguished reliably</option>
<option>The audible or visual signal was unclear</option>
<option>Other evidence concern</option>
</select>
</div>
<div class="form-field">
<label for="reportNote">Optional note</label>
<textarea id="reportNote" placeholder="Example: interval 4 may be a dot or dash."></textarea>
</div>
<div class="dialog-actions">
<button type="button" class="button ghost" data-close="reportDialog">Cancel</button>
<button type="button" id="recordReport" class="button warning">Record “?” and continue</button>
</div>
</form>
</div>
</dialog>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const MORSE = {
A: ".-",
B: "-...",
C: "-.-.",
D: "-..",
E: ".",
F: "..-.",
G: "--.",
H: "....",
I: "..",
J: ".---",
K: "-.-",
L: ".-..",
M: "--",
N: "-.",
O: "---",
P: ".--.",
Q: "--.-",
R: ".-.",
S: "...",
T: "-",
U: "..-",
V: "...-",
W: ".--",
X: "-..-",
Y: "-.--",
Z: "--..",
"0": "-----",
"1": ".----",
"2": "..---",
"3": "...--",
"4": "....-",
"5": ".....",
"6": "-....",
"7": "--...",
"8": "---..",
"9": "----."
};
const LETTERS = Object.keys(MORSE).filter((key) => /[A-Z]/.test(key));
const DIGITS = Object.keys(MORSE).filter((key) => /[0-9]/.test(key));
const UNIT_MS = 340;
const MARK_THRESHOLD = 1.5;
const GAP_THRESHOLD = 1.0;
const MARK_UNCERTAINTY = 0.16;
const GAP_UNCERTAINTY = 0.12;
const TRANSMISSION_COUNT = 5;
const state = {
scope: "letters",
source: [],
intervals: [],
letters: [],
answers: [],
reports: [],
current: 0,
selectedIntervalId: null,
targetSlot: -1,
targetPulseIndex: -1,
totalUnits: 0,
totalMs: 0,
playing: false,
playhead: 0,
playStartWall: 0,
playStartTimeline: 0,
speed: 1,
transmissionNumber: 0
};
let audioContext = null;
let activeOscillators = [];
const randomItem = (items) => items[Math.floor(Math.random() * items.length)];
const randomBetween = (min, max) => min + Math.random() * (max - min);
function knownAlphabet() {
return state.scope === "letters" ? LETTERS : [...LETTERS, ...DIGITS];
}
function crossingThreshold(interval, threshold) {
const min = interval.duration - interval.uncertainty;
const max = interval.duration + interval.uncertainty;
return min < threshold && max > threshold;
}
function intervalReading(interval) {
const threshold = interval.type === "on" ? MARK_THRESHOLD : GAP_THRESHOLD;
const min = interval.duration - interval.uncertainty;
const max = interval.duration + interval.uncertainty;
if (interval.type === "on") {
if (max < threshold) {
return { label: "DOT", ambiguous: false };
}
if (min > threshold) {
return { label: "DASH", ambiguous: false };
}
return { label: "DOT / DASH", ambiguous: true };
}
if (max < threshold) {
return { label: "IN-SYMBOL GAP", ambiguous: false };
}
if (min > threshold) {
return { label: "LETTER BOUNDARY", ambiguous: false };
}
return { label: "GAP / BOUNDARY", ambiguous: true };
}
function buildPuzzle() {
pausePlayback();
const alphabet = knownAlphabet();
const length = TRANSMISSION_COUNT;
state.source = Array.from({ length }, () => randomItem(alphabet));
state.targetSlot = -1;
state.targetPulseIndex = -1;
const eligibleTargets = alphabet.filter(
(char) => MORSE[char].includes(".") && MORSE[char].length > 1
);
if (eligibleTargets.length) {
state.targetSlot = Math.floor(Math.random() * length);
const targetChar = randomItem(eligibleTargets);
state.source[state.targetSlot] = targetChar;
const dotPositions = [...MORSE[targetChar]]
.map((symbol, index) => (symbol === "." ? index : -1))
.filter((index) => index >= 0);
state.targetPulseIndex = randomItem(dotPositions);
}
state.intervals = [];
state.letters = [];
state.answers = Array(length).fill(null);
state.reports = [];
state.current = 0;
state.playhead = 0;
state.selectedIntervalId = null;
state.transmissionNumber += 1;
let cursor = 0;
let intervalId = 0;
const addInterval = ({
type,
duration,
uncertainty,
letterIndex,
markIndex = null,
gapRole = null
}) => {
const interval = {
id: intervalId++,
type,
duration,
uncertainty,
letterIndex,
markIndex,
gapRole,
start: cursor,
end: cursor + duration,
startMs: cursor * UNIT_MS,
endMs: (cursor + duration) * UNIT_MS
};
cursor += duration;
state.intervals.push(interval);
return interval;
};
state.source.forEach((char, letterIndex) => {
const pattern = MORSE[char];
const letterIntervals = [];
[...pattern].forEach((symbol, markIndex) => {
let duration;
if (
letterIndex === state.targetSlot &&
markIndex === state.targetPulseIndex &&
symbol === "."
) {
// A legal stretched dot whose measured uncertainty overlaps the
// dot/dash decision boundary.
duration = randomBetween(1.34, 1.38);
} else if (symbol === ".") {
duration = 1 + randomBetween(-0.18, 0.18);
} else {
duration = 2 + randomBetween(-0.18, 0.18);
}
const mark = addInterval({
type: "on",
duration,
uncertainty: MARK_UNCERTAINTY,
letterIndex,
markIndex
});
letterIntervals.push(mark);
if (markIndex < pattern.length - 1) {
const gap = addInterval({
type: "off",
duration: 0.65 + randomBetween(-0.12, 0.12),
uncertainty: GAP_UNCERTAINTY,
letterIndex,
gapRole: "intra"
});
letterIntervals.push(gap);
}
});
if (letterIndex < state.source.length - 1) {
addInterval({
type: "off",
duration: 1.35 + randomBetween(-0.1, 0.1),
uncertainty: GAP_UNCERTAINTY,
letterIndex,
gapRole: "letter"
});
}
const marks = letterIntervals.filter((interval) => interval.type === "on");
const internalGaps = letterIntervals.filter(
(interval) => interval.type === "off" && interval.gapRole === "intra"
);
const ambiguities = [...marks, ...internalGaps].filter((interval) =>
crossingThreshold(
interval,
interval.type === "on" ? MARK_THRESHOLD : GAP_THRESHOLD
)
);
const classifiedPattern = marks
.map((interval) => (interval.duration < MARK_THRESHOLD ? "." : "-"))
.join("");
state.letters.push({
source: char,
intervalIds: letterIntervals.map((interval) => interval.id),
marks,
ambiguities,
classifiedPattern,
candidates: knownAlphabet().filter(
(candidate) => MORSE[candidate] === classifiedPattern
)
});
});
state.totalUnits = cursor;
state.totalMs = cursor * UNIT_MS;
if (state.letters[state.current]?.intervalIds.length) {
state.selectedIntervalId = state.letters[state.current].intervalIds[0];
}
$("transmissionLabel").textContent =
`Transmission ${String(state.transmissionNumber).padStart(2, "0")}`;
renderAll();
}
function renderAll() {
renderSlots();
renderCurrentSymbol();
renderCandidates();
renderTimeline();
renderIntervalTable();
renderSelectedInterval();
renderTransport();
renderResult();
}
function renderSlots() {
const container = $("slots");
container.replaceChildren();
const complete = state.answers.every((answer) => answer !== null);
state.answers.forEach((answer, index) => {
const button = document.createElement("button");
button.className = "slot";
button.dataset.slot = String(index);
if (index === state.current) {
button.classList.add("current");
}
if (answer !== null) {
button.classList.add("answered");
}
if (complete) {
const correct = index === state.targetSlot
? answer === "?"
: answer === state.source[index];
button.classList.add(correct ? "correct" : "wrong");
if (index === state.targetSlot && answer === "?") {
button.classList.remove("correct");
button.classList.add("safe");
}
}
const label = document.createElement("small");
label.textContent = `S${index + 1}`;
const value = document.createElement("span");
value.textContent = answer ?? "—";
button.append(label, value);
button.setAttribute(
"aria-label",
`Symbol ${index + 1}, ${answer === null ? "unanswered" : answer}`
);
button.addEventListener("click", () => setCurrentSlot(index));
container.append(button);
});
}
function setCurrentSlot(index) {
state.current = index;
const letter = state.letters[index];
if (letter?.intervalIds.length) {
state.selectedIntervalId = letter.intervalIds[0];
}
renderAll();
}
function moveToNextUnanswered() {
let next = state.answers.findIndex(
(answer, index) => index > state.current && answer === null
);
if (next < 0) {
next = state.answers.findIndex((answer) => answer === null);
}
if (next >= 0) {
state.current = next;
const letter = state.letters[next];
if (letter?.intervalIds.length) {
state.selectedIntervalId = letter.intervalIds[0];
}
}
}
function renderCurrentSymbol() {
const letter = state.letters[state.current];
if (!letter) return;
const forcedAmbiguity = letter.ambiguities.length > 0;
const card = $("readingCard");
card.classList.toggle("ambiguous", forcedAmbiguity);
if (forcedAmbiguity) {
const interval = letter.ambiguities[0];
const reading = intervalReading(interval);
$("evidenceHeadline").textContent =
`Symbol S${state.current + 1} has conflicting evidence`;
$("evidenceText").textContent =
`Interval ${interval.id + 1} spans ${(
interval.duration - interval.uncertainty
).toFixed(2)}–${(interval.duration + interval.uncertainty).toFixed(
2
)} u, crossing its decision boundary. ${reading.label} remains possible. ` +
`Report this symbol as ambiguous instead of choosing an unsupported letter.`;
} else {
$("evidenceHeadline").textContent = `Inspect symbol S${state.current + 1}`;
$("evidenceText").textContent =
"The intervals assigned to this symbol stay clear of their decision boundaries. " +
"Compare their durations with the known Morse table, then choose a symbol.";
}
const pattern = letter.marks
.map((interval) => {
const reading = intervalReading(interval);
if (reading.ambiguous) return "?";
return reading.label === "DOT" ? "·" : "—";
})
.join(" ");
$("observedPattern").textContent = pattern;
$("reportButton").disabled = state.answers[state.current] === "?";
$("reportButton").textContent =
state.answers[state.current] === "?"
? "Reported as ambiguous"
: "Report ambiguous symbol";
}
function renderCandidates() {
const grid = $("candidateGrid");
grid.replaceChildren();
const letter = state.letters[state.current];
const forcedAmbiguity = Boolean(letter?.ambiguities.length);
$("candidateHint").textContent = forcedAmbiguity
? "This symbol has conflicting interval evidence. It must be reported as “?”; letter choices are disabled."
: "Choose the symbol supported by the current interval evidence. You can revisit any slot.";
knownAlphabet().forEach((char) => {
const button = document.createElement("button");
button.className = "candidate";
button.textContent = char;
button.title = `${char} = ${MORSE[char]}`;
button.setAttribute("aria-label", `${char}, Morse ${MORSE[char]}`);
button.disabled = forcedAmbiguity;
button.addEventListener("click", () => {
if (forcedAmbiguity) return;
state.answers[state.current] = char;
moveToNextUnanswered();
renderAll();
});
grid.append(button);
});
}
function renderTimeline() {
const timeline = $("timeline");
timeline.replaceChildren();
state.intervals.forEach((interval) => {
const segment = document.createElement("button");
segment.className = `timeline-segment ${interval.type}`;
segment.dataset.intervalId = String(interval.id);
segment.style.left = `${(interval.start / state.totalUnits) * 100}%`;
segment.style.width = `${(interval.duration / state.totalUnits) * 100}%`;
segment.title =
`Interval ${interval.id + 1}: ${interval.duration.toFixed(2)} ± ` +
`${interval.uncertainty.toFixed(2)} u`;
segment.setAttribute("aria-label", segment.title);
if (interval.type === "on") {
const number = document.createElement("span");
number.textContent = String(interval.id + 1);
segment.append(number);
}
segment.addEventListener("click", () => selectInterval(interval.id));
timeline.append(segment);
});
const playhead = document.createElement("div");
playhead.id = "playhead";
timeline.append(playhead);
$("timelineLength").textContent = `${state.totalUnits.toFixed(2)} u`;
$("timelineEnd").textContent = `${state.totalUnits.toFixed(2)} u`;
updatePlayhead();
updateTimelineSelection();
}
function selectInterval(id) {
state.selectedIntervalId = id;
renderIntervalTable();
renderSelectedInterval();
updateTimelineSelection();
}
function updateTimelineSelection() {
document.querySelectorAll(".timeline-segment").forEach((segment) => {
segment.classList.toggle(
"selected",
Number(segment.dataset.intervalId) === state.selectedIntervalId
);
});
}
function renderIntervalTable() {
const rows = $("intervalRows");
rows.replaceChildren();
state.intervals.forEach((interval) => {
const row = document.createElement("tr");
row.dataset.intervalId = String(interval.id);
row.tabIndex = 0;
if (interval.id === state.selectedIntervalId) {
row.classList.add("selected");
}
const reading = intervalReading(interval);
const slot = document.createElement("td");
slot.textContent = `S${interval.letterIndex + 1}`;
const edge = document.createElement("td");
edge.textContent = interval.type === "on" ? "Mark" : "Gap";
const measured = document.createElement("td");
measured.textContent =
`${interval.duration.toFixed(2)} ± ${interval.uncertainty.toFixed(2)} u`;
const evidence = document.createElement("td");
evidence.textContent = reading.label;
if (reading.ambiguous) {
evidence.classList.add("table-ambiguous");
}
row.append(slot, edge, measured, evidence);
const select = () => selectInterval(interval.id);
row.addEventListener("click", select);
row.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
select();
}
});
rows.append(row);
});
}
function renderSelectedInterval() {
const interval = state.intervals.find(
(candidate) => candidate.id === state.selectedIntervalId
);
const card = $("selectedReading");
const chip = $("readingChip");
if (!interval) {
card.classList.remove("ambiguous");
$("selectedTitle").textContent = "No interval selected";
chip.textContent = "—";
chip.classList.remove("ambiguous");
$("selectedExplanation").textContent = "Select a timeline segment or table row.";
$("rangeBand").style.width = "0%";
$("threshold").style.left = "50%";
$("rangeMin").textContent = "—";
$("rangeMax").textContent = "—";
$("inspectorBadge").textContent = "Ready";
return;
}
const threshold =
interval.type === "on" ? MARK_THRESHOLD : GAP_THRESHOLD;
const min = interval.duration - interval.uncertainty;
const max = interval.duration + interval.uncertainty;
const reading = intervalReading(interval);
card.classList.toggle("ambiguous", reading.ambiguous);
chip.classList.toggle("ambiguous", reading.ambiguous);
$("selectedTitle").textContent =
`Interval ${interval.id + 1} · ${interval.type === "on" ? "mark" : "silence"}`;
chip.textContent = reading.label;
$("inspectorBadge").textContent = reading.ambiguous
? "Conflict"
: "Clear";
const visualMax = interval.type === "on" ? 3.0 : 2.0;
const left = Math.max(0, (min / visualMax) * 100);
const right = Math.min(100, (max / visualMax) * 100);
$("rangeBand").style.left = `${left}%`;
$("rangeBand").style.width = `${Math.max(2, right - left)}%`;
$("rangeBand").classList.toggle("ambiguous", reading.ambiguous);
$("threshold").style.left = `${(threshold / visualMax) * 100}%`;
$("rangeMin").textContent = `${min.toFixed(2)} u`;
$("rangeMax").textContent = `${max.toFixed(2)} u`;
if (reading.ambiguous) {
$("selectedExplanation").textContent =
`The uncertainty interval crosses the ${threshold.toFixed(
2
)} u decision boundary. More than one measurement class remains plausible, ` +
`so the system will not assert a single symbol for this evidence.`;
} else {
$("selectedExplanation").textContent =
`The complete uncertainty interval remains on one side of the ${threshold.toFixed(
2
)} u decision boundary. The measured class is ${reading.label.toLowerCase()}.`;
}
}
function renderTransport() {
$("playButton").textContent = state.playing
? "❚❚ Pause"
: state.playhead >= state.totalMs
? "▶ Play again"
: "▶ Play";
}
function renderResult() {
const result = $("result");
const complete = state.answers.every((answer) => answer !== null);
result.hidden = !complete;
if (!complete) return;
const safe =
state.targetSlot < 0
? state.answers.every(
(answer, index) => answer === state.source[index]
)
: state.answers[state.targetSlot] === "?" &&
state.answers.every(
(answer, index) =>
index === state.targetSlot || answer === state.source[index]
);
result.classList.toggle("bad", !safe);
if (safe) {
result.innerHTML = `
<strong>Solved without overclaiming.</strong>
<p>
The conflicting symbol was reported as “?”, and every unambiguous symbol
was read from the known alphabet.
</p>
`;
} else {
const wrong = state.answers
.map((answer, index) => ({ answer, index }))
.filter(({ answer, index }) =>
index === state.targetSlot
? answer !== "?"
: answer !== state.source[index]
)
.map(({ index }) => `S${index + 1}`)
.join(", ");
result.innerHTML = `
<strong>Review the intervals.</strong>
<p>
${wrong || "One or more readings"} did not match the supported evidence.
Revisit the sequence or generate a new transmission.
</p>
`;
}
}
function openReportDialog() {
const letter = state.letters[state.current];
if (!letter || state.answers[state.current] === "?") return;
const select = $("reportInterval");
select.replaceChildren();
letter.intervalIds.forEach((id) => {
const interval = state.intervals.find((candidate) => candidate.id === id);
const reading = intervalReading(interval);
const option = document.createElement("option");
option.value = String(interval.id);
option.textContent =
`Interval ${interval.id + 1} · ${interval.type === "on" ? "mark" : "gap"} · ` +
`${interval.duration.toFixed(2)} ± ${interval.uncertainty.toFixed(2)} u · ${reading.label}`;
select.append(option);
});
if (
state.selectedIntervalId !== null &&
letter.intervalIds.includes(state.selectedIntervalId)
) {
select.value = String(state.selectedIntervalId);
} else if (letter.ambiguities.length) {
select.value = String(letter.ambiguities[0].id);
}
$("reportReason").selectedIndex = 0;
$("reportNote").value = "";
$("reportDialog").showModal();
}
$("recordReport").addEventListener("click", (event) => {
event.preventDefault();
const intervalId = Number($("reportInterval").value);
state.answers[state.current] = "?";
state.reports.push({
slot: state.current,
intervalId,
reason: $("reportReason").value,
note: $("reportNote").value.trim()
});
$("reportDialog").close();
moveToNextUnanswered();
renderAll();
});
function renderAlphabetTable() {
const grid = $("alphabetGrid");
grid.replaceChildren();
Object.entries(MORSE).forEach(([char, pattern]) => {
const item = document.createElement("div");
item.className = "alphabet-item";
const name = document.createElement("strong");
name.textContent = char;
const code = document.createElement("code");
code.textContent = pattern.replaceAll(".", "·").replaceAll("-", "—");
item.append(name, code);
grid.append(item);
});
}
async function ensureAudio() {
if (!audioContext) {
const AudioContextClass =
window.AudioContext || window.webkitAudioContext;
if (!AudioContextClass) return;
audioContext = new AudioContextClass();
}
if (audioContext.state === "suspended") {
await audioContext.resume();
}
}
function stopAudio() {
activeOscillators.forEach((oscillator) => {
try {
oscillator.stop();
} catch {
// The oscillator may already have ended.
}
});
activeOscillators = [];
}
function scheduleAudio(fromMs) {
stopAudio();
if (!$("soundOn").checked || !audioContext) return;
state.intervals.forEach((interval) => {
if (interval.type !== "on" || interval.endMs <= fromMs) return;
const startMs = Math.max(fromMs, interval.startMs);
const delay = Math.max(0, (startMs - fromMs) / 1000 / state.speed);
const duration = Math.max(0.015, (interval.endMs - startMs) / 1000 / state.speed);
const startTime = audioContext.currentTime + delay;
const oscillator = audioContext.createOscillator();
const gain = audioContext.createGain();
oscillator.type = "sine";
oscillator.frequency.value = 520 + (interval.markIndex % 3) * 75;
gain.gain.setValueAtTime(0.0001, startTime);
gain.gain.exponentialRampToValueAtTime(0.15, startTime + 0.008);
gain.gain.setValueAtTime(0.15, startTime + Math.max(0.009, duration - 0.012));
gain.gain.exponentialRampToValueAtTime(0.0001, startTime + duration);
oscillator.connect(gain);
gain.connect(audioContext.destination);
oscillator.start(startTime);
oscillator.stop(startTime + duration + 0.02);
activeOscillators.push(oscillator);
});
}
async function playTransmission() {
if (state.playing) {
pausePlayback();
renderTransport();
return;
}
await ensureAudio();
if (state.playhead >= state.totalMs) {
state.playhead = 0;
}
state.playing = true;
state.playStartWall = performance.now();
state.playStartTimeline = state.playhead;
scheduleAudio(state.playhead);
renderTransport();
}
function pausePlayback() {
if (state.playing) {
updatePlayhead(performance.now());
}
state.playing = false;
stopAudio();
}
function updatePlayhead(now = performance.now()) {
if (!state.playing) return;
const elapsed = (now - state.playStartWall) * state.speed;
state.playhead = Math.min(
state.totalMs,
state.playStartTimeline + elapsed
);
}
function updateTimelinePlayhead() {
const playhead = $("playhead");
if (!playhead) return;
const percent = state.totalMs
? (state.playhead / state.totalMs) * 100
: 0;
playhead.style.left = `${percent}%`;
}
$("playButton").addEventListener("click", playTransmission);
$("replayButton").addEventListener("click", async () => {
pausePlayback();
state.playhead = 0;
renderAll();
await playTransmission();
});
$("newButton").addEventListener("click", buildPuzzle);
$("reportButton").addEventListener("click", openReportDialog);
$("speed").addEventListener("change", (event) => {
const wasPlaying = state.playing;
if (wasPlaying) pausePlayback();
state.speed = Number(event.target.value);
if (wasPlaying) {
playTransmission();
}
renderTransport();
});
$("alphabetScope").addEventListener("change", (event) => {
state.scope = event.target.value;
buildPuzzle();
});
$("openAlphabet").addEventListener("click", () => {
$("alphabetDialog").showModal();
});
document.querySelectorAll("[data-close]").forEach((button) => {
button.addEventListener("click", () => {
$(button.dataset.close).close();
});
});
document.addEventListener("visibilitychange", () => {
if (document.hidden && state.playing) {
pausePlayback();
renderTransport();
}
});
renderAlphabetTable();
/*
* Three.js scene. Camera controls are implemented directly below;
* no controls addons are imported.
*/
const canvas = $("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131e);
scene.fog = new THREE.FogExp2(0x07131e, 0.035);
const camera = new THREE.PerspectiveCamera(
46,
window.innerWidth / window.innerHeight,
0.1,
120
);
const cameraState = {
yaw: 0.62,
pitch: 0.38,
distance: 18,
target: new THREE.Vector3(0, 2.8, 0)
};
function updateCamera() {
const { yaw, pitch, distance, target } = cameraState;
const horizontal = Math.sin(pitch) * distance;
camera.position.set(
target.x + horizontal * Math.sin(yaw),
target.y + Math.cos(pitch) * distance,
target.z + horizontal * Math.cos(yaw)
);
camera.lookAt(target);
}
updateCamera();
let dragging = false;
let dragX = 0;
let dragY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
dragX = event.clientX;
dragY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - dragX;
const dy = event.clientY - dragY;
dragX = event.clientX;
dragY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.0045,
0.12,
1.13
);
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * 0.012,
10,
29
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraState.yaw = 0.62;
cameraState.pitch = 0.38;
cameraState.distance = 18;
updateCamera();
});
const hemisphere = new THREE.HemisphereLight(0xa7d9e4, 0x18202a, 1.5);
scene.add(hemisphere);
const moonLight = new THREE.DirectionalLight(0xb9ddff, 2.2);
moonLight.position.set(-8, 14, 7);
moonLight.castShadow = true;
moonLight.shadow.mapSize.set(1024, 1024);
moonLight.shadow.camera.left = -14;
moonLight.shadow.camera.right = 14;
moonLight.shadow.camera.top = 14;
moonLight.shadow.camera.bottom = -14;
scene.add(moonLight);
const warmLight = new THREE.PointLight(0xffb35f, 2, 18, 2);
warmLight.position.set(0, 6.2, 0);
scene.add(warmLight);
const world = new THREE.Group();
scene.add(world);
const waterGeometry = new THREE.PlaneGeometry(60, 60, 18, 18);
const waterPositions = waterGeometry.attributes.position;
for (let index = 0; index < waterPositions.count; index += 1) {
const x = waterPositions.getX(index);
const y = waterPositions.getY(index);
const distance = Math.hypot(x, y);
const ripple =
Math.sin(x * 0.65) * 0.055 +
Math.cos(y * 0.52) * 0.045 +
Math.sin((x + y) * 0.3) * 0.025;
waterPositions.setZ(
index,
ripple * Math.min(1, distance / 7)
);
}
waterGeometry.computeVertexNormals();
const water = new THREE.Mesh(
waterGeometry,
new THREE.MeshStandardMaterial({
color: 0x0b3441,
roughness: 0.84,
metalness: 0.08,
flatShading: true,
transparent: true,
opacity: 0.92
})
);
water.rotation.x = -Math.PI / 2;
water.position.y = -0.38;
water.receiveShadow = true;
world.add(water);
const island = new THREE.Mesh(
new THREE.CylinderGeometry(3.7, 4.5, 1.1, 9),
new THREE.MeshStandardMaterial({
color: 0x33413d,
roughness: 0.95,
flatShading: true
})
);
island.position.y = 0.08;
island.castShadow = true;
island.receiveShadow = true;
world.add(island);
const islandTop = new THREE.Mesh(
new THREE.CylinderGeometry(3.5, 3.7, 0.28, 9),
new THREE.MeshStandardMaterial({
color: 0x405c4e,
roughness: 0.96,
flatShading: true
})
);
islandTop.position.y = 0.72;
islandTop.castShadow = true;
islandTop.receiveShadow = true;
world.add(islandTop);
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x45545a,
roughness: 1,
flatShading: true
});
[
[-3.2, 0.2, 0.8, 0.8],
[2.8, 0.0, 1.1, 0.58],
[-1.8, -0.05, 3.0, 0.48],
[2.2, -0.1, -2.4, 0.66],
[-3.0, -0.2, -1.6, 0.43]
].forEach(([x, y, z, scale]) => {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(scale, 0),
rockMaterial
);
rock.position.set(x, y, z);
rock.rotation.set(Math.random(), Math.random(), Math.random());
rock.scale.y = 0.72;
rock.castShadow = true;
world.add(rock);
});
const tower = new THREE.Group();
tower.position.y = 0.83;
world.add(tower);
const towerMaterial = new THREE.MeshStandardMaterial({
color: 0xb85f3d,
roughness: 0.68,
metalness: 0.12,
flatShading: true
});
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x263b42,
roughness: 0.75,
metalness: 0.35,
flatShading: true
});
const base = new THREE.Mesh(
new THREE.CylinderGeometry(1.25, 1.55, 0.65, 8),
towerMaterial
);
base.position.y = 0.28;
base.castShadow = true;
tower.add(base);
const mast = new THREE.Mesh(
new THREE.CylinderGeometry(0.2, 0.48, 5.4, 6),
towerMaterial
);
mast.position.y = 3.0;
mast.castShadow = true;
tower.add(mast);
const collar = new THREE.Mesh(
new THREE.CylinderGeometry(0.55, 0.62, 0.2, 8),
darkMetal
);
collar.position.y = 1.15;
collar.castShadow = true;
tower.add(collar);
const cabin = new THREE.Mesh(
new THREE.CylinderGeometry(0.72, 0.72, 0.9, 8),
darkMetal
);
cabin.position.y = 5.82;
cabin.castShadow = true;
tower.add(cabin);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(0.95, 0.7, 8),
towerMaterial
);
roof.position.y = 6.6;
roof.castShadow = true;
tower.add(roof);
const antenna = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.035, 1.05, 6),
darkMetal
);
antenna.position.y = 7.35;
tower.add(antenna);
const lampMaterial = new THREE.MeshStandardMaterial({
color: 0xffc16c,
emissive: 0xff9e32,
emissiveIntensity: 0.35,
roughness: 0.28,
metalness: 0.08,
flatShading: true
});
const lamp = new THREE.Mesh(
new THREE.OctahedronGeometry(0.38, 0),
lampMaterial
);
lamp.position.y = 5.86;
lamp.scale.y = 1.25;
tower.add(lamp);
const beamGroup = new THREE.Group();
beamGroup.position.y = 5.86;
tower.add(beamGroup);
const beamMaterial = new THREE.MeshBasicMaterial({
color: 0xffc16c,
transparent: true,
opacity: 0.035,
side: THREE.DoubleSide,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const beam = new THREE.Mesh(
new THREE.ConeGeometry(2.4, 13, 8, 1, true),
beamMaterial
);
beam.rotation.z = -Math.PI / 2;
beam.position.x = 6.5;
beamGroup.add(beam);
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0x75e5d2,
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide
});
const rings = Array.from({ length: 5 }, () => {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1, 0.025, 4, 36),
ringMaterial.clone()
);
ring.rotation.x = Math.PI / 2;
ring.position.y = -1.16;
ring.userData.birth = -Infinity;
world.add(ring);
return ring;
});
const starCount = 180;
const starPositions = new Float32Array(starCount * 3);
for (let index = 0; index < starCount; index += 1) {
const radius = randomBetween(18, 48);
const theta = randomBetween(0, Math.PI * 2);
const height = randomBetween(7, 30);
starPositions[index * 3] = Math.cos(theta) * radius;
starPositions[index * 3 + 1] = height;
starPositions[index * 3 + 2] = Math.sin(theta) * radius;
}
const starGeometry = new THREE.BufferGeometry();
starGeometry.setAttribute(
"position",
new THREE.BufferAttribute(starPositions, 3)
);
const stars = new THREE.Points(
starGeometry,
new THREE.PointsMaterial({
color: 0xc5e7ef,
size: 0.11,
transparent: true,
opacity: 0.65,
sizeAttenuation: true
})
);
scene.add(stars);
const floaters = [];
const floaterGeometry = new THREE.IcosahedronGeometry(0.055, 0);
const floaterMaterial = new THREE.MeshBasicMaterial({
color: 0x8fe8dc,
transparent: true,
opacity: 0.42
});
for (let index = 0; index < 26; index += 1) {
const floater = new THREE.Mesh(floaterGeometry, floaterMaterial);
floater.position.set(
randomBetween(-8, 8),
randomBetween(0.4, 7),
randomBetween(-8, 8)
);
floater.userData.phase = Math.random() * Math.PI * 2;
floater.userData.baseY = floater.position.y;
world.add(floater);
floaters.push(floater);
}
function currentActiveInterval() {
const time = state.playhead;
return state.intervals.find(
(interval) =>
time >= interval.startMs && time < interval.endMs
);
}
let lastVisualInterval = null;
let nextRing = 0;
function animate(now) {
requestAnimationFrame(animate);
if (state.playing) {
updatePlayhead(now);
updateTimelinePlayhead();
if (state.playhead >= state.totalMs) {
state.playing = false;
stopAudio();
renderTransport();
}
}
const active = currentActiveInterval();
const isOn = active?.type === "on";
lampMaterial.emissiveIntensity = isOn ? 3.4 : 0.3;
warmLight.intensity = isOn ? 28 : 2.2;
beamMaterial.opacity = isOn ? 0.13 : 0.028;
beamGroup.rotation.y = now * 0.00035;
if (isOn && active.id !== lastVisualInterval) {
const ring = rings[nextRing % rings.length];
ring.userData.birth = now;
nextRing += 1;
}
if (isOn) {
lastVisualInterval = active.id;
} else {
lastVisualInterval = null;
}
rings.forEach((ring) => {
const age = (now - ring.userData.birth) / 1400;
if (age >= 0 && age <= 1) {
const scale = 1 + age * 4.5;
ring.scale.setScalar(scale);
ring.material.opacity = (1 - age) * 0.52;
} else {
ring.material.opacity = 0;
}
});
floaters.forEach((floater) => {
floater.position.y =
floater.userData.baseY +
Math.sin(now * 0.0012 + floater.userData.phase) * 0.22;
floater.rotation.x += 0.004;
floater.rotation.y += 0.006;
});
stars.rotation.y = now * 0.000015;
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
buildPuzzle();
requestAnimationFrame(animate);
</script>
</body>
</html>
```