Prompt specification
Build or customize the Three.js 3D scene "Signed-change exploration path" 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: Signed-change exploration path
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/signed-change-exploration-path-x1704
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: signed-change exploration path. Let users apply a sequence of gains and losses to a token position; track initial value, each signed change, and final value separately with reversible steps. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (signed-change-exploration-path-x1704):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#0a0d13" />
<title>Signpath — Signed-Change Token Explorer</title>
<style>
:root {
color-scheme: dark;
--bg: #090c12;
--panel: #111620;
--panel-2: #151b26;
--panel-3: #1b2230;
--line: rgba(255, 255, 255, 0.09);
--text: #f3f6fb;
--muted: #8792a5;
--muted-2: #5f6a7c;
--gain: #64e6aa;
--gain-soft: rgba(100, 230, 170, 0.12);
--loss: #ff737d;
--loss-soft: rgba(255, 115, 125, 0.12);
--accent: #7ed7ff;
--gold: #f4c56b;
--shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
--radius: 18px;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
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,
input {
font: inherit;
}
button {
color: inherit;
}
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 3px;
}
.app {
display: grid;
grid-template-rows: 66px minmax(0, 1fr);
height: 100vh;
min-height: 620px;
}
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 22px;
border-bottom: 1px solid var(--line);
background: rgba(9, 12, 18, 0.9);
backdrop-filter: blur(18px);
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
position: relative;
width: 34px;
height: 34px;
flex: 0 0 auto;
background: linear-gradient(145deg, var(--gain), var(--accent));
clip-path: polygon(50% 0, 95% 24%, 87% 78%, 50% 100%, 13% 78%, 5% 24%);
box-shadow: 0 0 30px rgba(126, 215, 255, 0.2);
}
.brand-mark::after {
content: "";
position: absolute;
inset: 8px;
background: #0b1018;
clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}
.brand-copy {
min-width: 0;
}
.brand-name {
display: block;
font-size: 14px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
line-height: 1.1;
}
.brand-subtitle {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.04em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.top-status {
display: flex;
align-items: center;
gap: 9px;
padding: 8px 12px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted);
background: rgba(255, 255, 255, 0.025);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--gain);
box-shadow: 0 0 12px var(--gain);
}
.workspace {
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
gap: 12px;
min-height: 0;
padding: 12px;
}
.scene-card,
.control-panel {
position: relative;
min-width: 0;
min-height: 0;
border: 1px solid var(--line);
border-radius: var(--radius);
background: var(--panel);
box-shadow: var(--shadow);
overflow: hidden;
}
.stage {
position: absolute;
inset: 0;
overflow: hidden;
background:
radial-gradient(circle at 45% 38%, rgba(62, 90, 121, 0.12), transparent 38%),
linear-gradient(180deg, #111824, #090d14);
}
.stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
.stage canvas:active {
cursor: grabbing;
}
.scene-overlay {
position: absolute;
inset: 0;
pointer-events: none;
z-index: 2;
}
.scene-heading {
position: absolute;
top: 22px;
left: 24px;
max-width: 390px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 18px;
height: 1px;
background: currentColor;
}
.scene-heading h1 {
margin: 9px 0 6px;
font-size: clamp(24px, 3vw, 38px);
line-height: 1;
letter-spacing: -0.045em;
}
.scene-heading p {
max-width: 360px;
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.scene-metrics {
position: absolute;
top: 20px;
right: 20px;
display: grid;
grid-template-columns: repeat(3, minmax(105px, 1fr));
gap: 8px;
}
.metric {
min-width: 112px;
padding: 11px 13px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 13px;
background: rgba(12, 17, 25, 0.72);
backdrop-filter: blur(14px);
box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}
.metric-label {
display: block;
margin-bottom: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metric-value {
display: block;
font-size: 15px;
font-weight: 800;
letter-spacing: -0.02em;
white-space: nowrap;
}
.metric-value.positive {
color: var(--gain);
}
.metric-value.negative {
color: var(--loss);
}
.metric-value.neutral {
color: var(--muted);
}
.scene-footer {
position: absolute;
right: 20px;
bottom: 18px;
left: 20px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 16px;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.legend-chip {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 9px;
color: var(--muted);
background: rgba(9, 13, 20, 0.76);
backdrop-filter: blur(12px);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
}
.legend-dot {
width: 7px;
height: 7px;
transform: rotate(45deg);
background: currentColor;
}
.legend-dot.gain {
color: var(--gain);
}
.legend-dot.loss {
color: var(--loss);
}
.legend-dot.start {
color: var(--gold);
}
.legend-dot.final {
color: var(--accent);
}
.control-hint {
padding: 8px 10px;
border-radius: 9px;
color: #748094;
background: rgba(9, 13, 20, 0.66);
font-size: 10px;
white-space: nowrap;
}
.inspect-card {
position: absolute;
bottom: 76px;
left: 24px;
display: none;
align-items: center;
gap: 12px;
max-width: calc(100% - 48px);
padding: 10px 12px;
border: 1px solid rgba(126, 215, 255, 0.22);
border-radius: 12px;
background: rgba(11, 16, 24, 0.88);
backdrop-filter: blur(14px);
box-shadow: 0 14px 35px rgba(0, 0, 0, 0.26);
pointer-events: auto;
}
.inspect-card.visible {
display: flex;
}
.inspect-index {
min-width: 42px;
padding: 7px 8px;
border-radius: 8px;
color: var(--accent);
background: rgba(126, 215, 255, 0.1);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
text-align: center;
text-transform: uppercase;
}
.inspect-copy strong,
.inspect-copy span {
display: block;
}
.inspect-copy strong {
font-size: 12px;
}
.inspect-copy span {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.inspect-close {
width: 26px;
height: 26px;
margin-left: 4px;
border: 0;
border-radius: 7px;
color: var(--muted);
background: transparent;
cursor: pointer;
}
.inspect-close:hover {
color: var(--text);
background: rgba(255, 255, 255, 0.07);
}
.labels-layer {
position: absolute;
inset: 0;
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.node-label {
position: absolute;
top: 0;
left: 0;
min-width: 92px;
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 9px;
color: var(--text);
background: rgba(9, 13, 20, 0.82);
backdrop-filter: blur(9px);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
text-align: left;
cursor: pointer;
pointer-events: auto;
will-change: transform;
transition: border-color 160ms ease, background 160ms ease;
}
.node-label:hover {
border-color: rgba(255, 255, 255, 0.32);
background: rgba(15, 21, 31, 0.95);
}
.node-label.initial {
border-color: rgba(244, 197, 107, 0.34);
}
.node-label.gain {
border-color: rgba(100, 230, 170, 0.34);
}
.node-label.loss {
border-color: rgba(255, 115, 125, 0.36);
}
.node-label.final {
border-color: rgba(126, 215, 255, 0.45);
}
.label-kicker {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.node-label.initial .label-kicker {
color: var(--gold);
}
.node-label.gain .label-kicker {
color: var(--gain);
}
.node-label.loss .label-kicker {
color: var(--loss);
}
.node-label.final .label-kicker {
color: var(--accent);
}
.label-value {
display: block;
font-size: 11px;
font-weight: 800;
white-space: nowrap;
}
.label-delta {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
white-space: nowrap;
}
.control-panel {
display: flex;
flex-direction: column;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: #2b3445 transparent;
}
.panel-section {
padding: 20px;
border-bottom: 1px solid var(--line);
}
.panel-section:last-child {
border-bottom: 0;
}
.section-title-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.section-title {
margin: 0;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-caption {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.field-label {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.field-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.input-wrap {
position: relative;
}
.input-prefix,
.input-suffix {
position: absolute;
top: 50%;
color: var(--muted-2);
font-size: 12px;
font-weight: 700;
transform: translateY(-50%);
pointer-events: none;
}
.input-prefix {
left: 12px;
}
.input-suffix {
right: 12px;
}
.field-wrap.has-prefix input {
padding-left: 29px;
}
.field-wrap.has-suffix input {
padding-right: 42px;
}
input[type="number"] {
width: 100%;
height: 43px;
padding: 0 12px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 10px;
color: var(--text);
background: #0c1119;
font-size: 13px;
font-weight: 700;
appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
margin: 0;
appearance: none;
}
input[type="number"]:disabled {
color: var(--muted);
cursor: not-allowed;
opacity: 0.58;
}
.field-help {
min-height: 16px;
margin: 7px 0 0;
color: var(--muted-2);
font-size: 9px;
line-height: 1.4;
}
.action-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 13px;
}
.action-button {
display: flex;
align-items: center;
justify-content: center;
gap: 9px;
height: 47px;
border: 1px solid transparent;
border-radius: 11px;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.04em;
cursor: pointer;
transition: transform 120ms ease, filter 120ms ease, border-color 120ms ease;
}
.action-button:hover {
filter: brightness(1.08);
transform: translateY(-1px);
}
.action-button:active {
transform: translateY(0);
}
.action-button.gain {
color: #07130e;
background: var(--gain);
box-shadow: 0 8px 25px rgba(100, 230, 170, 0.14);
}
.action-button.loss {
color: #1b090c;
background: var(--loss);
box-shadow: 0 8px 25px rgba(255, 115, 125, 0.13);
}
.action-icon {
display: grid;
place-items: center;
width: 20px;
height: 20px;
border: 1px solid currentColor;
border-radius: 6px;
font-size: 15px;
line-height: 1;
}
.history-actions {
display: flex;
gap: 6px;
}
.icon-button {
display: inline-grid;
place-items: center;
width: 31px;
height: 31px;
padding: 0;
border: 1px solid var(--line);
border-radius: 8px;
color: var(--muted);
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
}
.icon-button:hover:not(:disabled) {
color: var(--text);
border-color: rgba(255, 255, 255, 0.2);
background: rgba(255, 255, 255, 0.06);
}
.icon-button:disabled {
opacity: 0.28;
cursor: not-allowed;
}
.ledger {
position: relative;
max-height: 390px;
overflow-y: auto;
padding: 3px 5px 5px 0;
scrollbar-width: thin;
scrollbar-color: #2b3445 transparent;
}
.ledger-row {
position: relative;
display: grid;
grid-template-columns: 34px minmax(0, 1fr) auto;
align-items: center;
gap: 10px;
min-height: 57px;
padding: 9px 10px;
border: 1px solid transparent;
border-radius: 11px;
transition: background 150ms ease, border-color 150ms ease;
}
.ledger-row.initial {
background: rgba(244, 197, 107, 0.055);
border-color: rgba(244, 197, 107, 0.13);
}
.ledger-row.final {
margin-top: 8px;
background: rgba(126, 215, 255, 0.06);
border-color: rgba(126, 215, 255, 0.18);
}
.ledger-step {
cursor: pointer;
}
.ledger-step:hover,
.ledger-step.selected {
background: rgba(255, 255, 255, 0.035);
border-color: rgba(255, 255, 255, 0.08);
}
.ledger-step.selected {
box-shadow: inset 2px 0 var(--accent);
}
.step-marker {
display: grid;
place-items: center;
width: 30px;
height: 30px;
border-radius: 9px;
color: var(--muted);
background: rgba(255, 255, 255, 0.055);
font-size: 10px;
font-weight: 850;
}
.ledger-step.gain .step-marker {
color: var(--gain);
background: var(--gain-soft);
}
.ledger-step.loss .step-marker {
color: var(--loss);
background: var(--loss-soft);
}
.ledger-step.initial .step-marker {
color: var(--gold);
background: rgba(244, 197, 107, 0.11);
}
.ledger-step.final .step-marker {
color: var(--accent);
background: rgba(126, 215, 255, 0.11);
}
.ledger-copy {
min-width: 0;
}
.ledger-copy strong,
.ledger-copy span {
display: block;
}
.ledger-copy strong {
overflow: hidden;
font-size: 12px;
font-weight: 800;
text-overflow: ellipsis;
white-space: nowrap;
}
.ledger-copy span {
margin-top: 4px;
color: var(--muted);
font-size: 9px;
}
.ledger-value {
text-align: right;
}
.ledger-value strong,
.ledger-value span {
display: block;
}
.ledger-value strong {
font-size: 12px;
font-weight: 800;
white-space: nowrap;
}
.ledger-value span {
margin-top: 4px;
color: var(--muted);
font-size: 9px;
}
.ledger-step .ledger-value strong.gain {
color: var(--gain);
}
.ledger-step .ledger-value strong.loss {
color: var(--loss);
}
.remove-step {
position: absolute;
top: 4px;
right: 4px;
display: grid;
place-items: center;
width: 20px;
height: 20px;
padding: 0;
border: 0;
border-radius: 6px;
color: var(--muted-2);
background: transparent;
font-size: 14px;
opacity: 0;
cursor: pointer;
transition: opacity 120ms ease, color 120ms ease, background 120ms ease;
}
.ledger-step:hover .remove-step,
.remove-step:focus-visible {
opacity: 1;
}
.remove-step:hover {
color: var(--loss);
background: var(--loss-soft);
}
.ledger-connector {
width: 1px;
height: 11px;
margin: 0 0 0 24px;
background: rgba(255, 255, 255, 0.12);
}
.empty-ledger {
padding: 17px 13px;
border: 1px dashed rgba(255, 255, 255, 0.11);
border-radius: 10px;
color: var(--muted-2);
font-size: 10px;
line-height: 1.55;
text-align: center;
}
.preset-list {
display: grid;
gap: 7px;
}
.preset-button {
display: grid;
grid-template-columns: 78px minmax(0, 1fr) auto;
align-items: center;
gap: 10px;
width: 100%;
padding: 10px;
border: 1px solid var(--line);
border-radius: 11px;
color: var(--text);
background: rgba(255, 255, 255, 0.02);
text-align: left;
cursor: pointer;
transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}
.preset-button:hover {
border-color: rgba(255, 255, 255, 0.18);
background: rgba(255, 255, 255, 0.045);
transform: translateX(2px);
}
.preset-name {
font-size: 11px;
font-weight: 800;
}
.preset-path {
display: flex;
align-items: center;
gap: 3px;
}
.preset-path i {
display: block;
width: 18px;
height: 3px;
border-radius: 2px;
background: var(--muted);
}
.preset-path i.gain {
background: var(--gain);
}
.preset-path i.loss {
background: var(--loss);
}
.preset-arrow {
color: var(--muted-2);
font-size: 12px;
}
.keyboard-note {
margin-top: 12px;
color: var(--muted-2);
font-size: 9px;
line-height: 1.6;
}
kbd {
display: inline-block;
min-width: 18px;
padding: 2px 5px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-bottom-width: 2px;
border-radius: 5px;
color: var(--muted);
background: rgba(255, 255, 255, 0.035);
font-family: inherit;
font-size: 8px;
text-align: center;
}
.toast {
position: fixed;
left: 50%;
bottom: 24px;
z-index: 50;
max-width: min(420px, calc(100vw - 32px));
padding: 11px 15px;
border: 1px solid rgba(126, 215, 255, 0.22);
border-radius: 11px;
color: var(--text);
background: rgba(15, 21, 31, 0.94);
backdrop-filter: blur(14px);
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.38);
font-size: 11px;
font-weight: 700;
text-align: center;
opacity: 0;
transform: translate(-50%, 12px);
pointer-events: none;
transition: opacity 180ms ease, transform 180ms ease;
}
.toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 1100px) {
.scene-metrics {
grid-template-columns: 1fr;
}
.metric {
min-width: 128px;
}
}
@media (max-width: 880px) {
body {
overflow: auto;
}
.app {
display: block;
height: auto;
min-height: 100vh;
}
.topbar {
height: 64px;
}
.workspace {
display: block;
padding: 10px;
}
.scene-card {
height: 62vh;
min-height: 490px;
}
.control-panel {
margin-top: 10px;
overflow: visible;
}
.scene-metrics {
top: auto;
right: 16px;
bottom: 66px;
grid-template-columns: repeat(3, minmax(92px, 1fr));
}
.metric {
min-width: 0;
padding: 9px 10px;
}
.scene-heading {
top: 18px;
left: 18px;
}
.scene-heading p {
display: none;
}
.control-hint {
display: none;
}
}
@media (max-width: 560px) {
.brand-subtitle,
.top-status span:last-child {
display: none;
}
.topbar {
padding: 0 15px;
}
.scene-card {
height: 58vh;
min-height: 430px;
}
.scene-heading h1 {
font-size: 26px;
}
.scene-metrics {
right: 10px;
bottom: 64px;
left: 10px;
grid-template-columns: repeat(3, 1fr);
}
.metric {
padding: 8px;
}
.metric-value {
font-size: 12px;
}
.metric-label {
font-size: 7px;
}
.panel-section {
padding: 17px;
}
.field-grid {
grid-template-columns: 1fr;
}
.inspect-card {
bottom: 125px;
left: 10px;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<span class="brand-name">Signpath</span>
<span class="brand-subtitle">Signed-change exploration for token positions</span>
</div>
</div>
<div class="top-status">
<span class="status-dot" aria-hidden="true"></span>
<span>Local exploration model</span>
</div>
</header>
<main class="workspace">
<section class="scene-card" aria-label="Three-dimensional signed-change path">
<div class="stage" id="stage">
<div class="labels-layer" id="labelsLayer"></div>
<div class="scene-overlay">
<div class="scene-heading">
<div class="eyebrow">3D position explorer</div>
<h1>Follow every signed move.</h1>
<p>
Build a sequence of gains and losses. Height shows the position
relative to its starting value; color shows the direction of change.
</p>
</div>
<div class="scene-metrics" aria-live="polite">
<div class="metric">
<span class="metric-label">Current value</span>
<span class="metric-value" id="currentMetric">$10,000</span>
</div>
<div class="metric">
<span class="metric-label">Net signed change</span>
<span class="metric-value neutral" id="netMetric">$0</span>
</div>
<div class="metric">
<span class="metric-label">From start</span>
<span class="metric-value neutral" id="relativeMetric">0.0%</span>
</div>
</div>
<div class="inspect-card" id="inspectCard">
<div class="inspect-index" id="inspectIndex">00</div>
<div class="inspect-copy">
<strong id="inspectTitle">Initial position</strong>
<span id="inspectDetail"></span>
</div>
<button class="inspect-close" id="inspectClose" aria-label="Close inspector">×</button>
</div>
<div class="scene-footer">
<div class="legend" aria-label="Path legend">
<span class="legend-chip"><i class="legend-dot start"></i>Start</span>
<span class="legend-chip"><i class="legend-dot gain"></i>Gain</span>
<span class="legend-chip"><i class="legend-dot loss"></i>Loss</span>
<span class="legend-chip"><i class="legend-dot final"></i>Final</span>
</div>
<div class="control-hint">Drag to orbit · Scroll to zoom · Click a node</div>
</div>
</div>
</div>
</section>
<aside class="control-panel" aria-label="Position controls and ledger">
<section class="panel-section">
<div class="section-title-row">
<div>
<h2 class="section-title">Position controls</h2>
<p class="section-caption">Set a baseline, then apply signed changes.</p>
</div>
</div>
<div class="field-grid">
<div>
<label class="field-label" for="initialInput">Initial value</label>
<div class="field-wrap has-prefix">
<span class="input-prefix">$</span>
<input
id="initialInput"
type="number"
min="0.01"
step="100"
value="10000"
inputmode="decimal"
/>
</div>
</div>
<div>
<label class="field-label" for="amountInput">Change amount</label>
<div class="field-wrap has-prefix">
<span class="input-prefix">$</span>
<input
id="amountInput"
type="number"
min="0.01"
step="100"
value="1200"
inputmode="decimal"
/>
</div>
</div>
</div>
<p class="field-help" id="baselineHelp">
Clear the path before changing the initial value.
</p>
<div class="action-grid">
<button class="action-button gain" id="gainButton" type="button">
<span class="action-icon">+</span>
Apply gain
</button>
<button class="action-button loss" id="lossButton" type="button">
<span class="action-icon">−</span>
Apply loss
</button>
</div>
</section>
<section class="panel-section">
<div class="section-title-row">
<div>
<h2 class="section-title">Step ledger</h2>
<p class="section-caption">Initial, each signed change, and final.</p>
</div>
<div class="history-actions">
<button class="icon-button" id="undoButton" type="button" title="Undo" aria-label="Undo">
↶
</button>
<button class="icon-button" id="redoButton" type="button" title="Redo" aria-label="Redo">
↷
</button>
<button class="icon-button" id="clearButton" type="button" title="Clear path" aria-label="Clear path">
×
</button>
</div>
</div>
<div class="ledger" id="ledger"></div>
</section>
<section class="panel-section">
<div class="section-title-row">
<div>
<h2 class="section-title">Explore a pattern</h2>
<p class="section-caption">Load a reversible example path.</p>
</div>
</div>
<div class="preset-list">
<button class="preset-button" type="button" data-preset="steady">
<span class="preset-name">Steady climb</span>
<span class="preset-path" aria-hidden="true">
<i class="gain"></i><i class="gain"></i><i class="gain"></i>
</span>
<span class="preset-arrow">→</span>
</button>
<button class="preset-button" type="button" data-preset="drawdown">
<span class="preset-name">Drawdown</span>
<span class="preset-path" aria-hidden="true">
<i class="loss"></i><i class="loss"></i><i class="gain"></i>
</span>
<span class="preset-arrow">→</span>
</button>
<button class="preset-button" type="button" data-preset="whipsaw">
<span class="preset-name">Whipsaw</span>
<span class="preset-path" aria-hidden="true">
<i class="gain"></i><i class="loss"></i><i class="gain"></i><i class="loss"></i>
</span>
<span class="preset-arrow">→</span>
</button>
</div>
<div class="keyboard-note">
<kbd>G</kbd> gain · <kbd>L</kbd> loss ·
<kbd>Ctrl</kbd> + <kbd>Z</kbd> undo ·
<kbd>Ctrl</kbd> + <kbd>⇧</kbd> + <kbd>Z</kbd> redo
</div>
</section>
</aside>
</main>
</div>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const ui = {
stage: document.getElementById("stage"),
labelsLayer: document.getElementById("labelsLayer"),
initialInput: document.getElementById("initialInput"),
amountInput: document.getElementById("amountInput"),
baselineHelp: document.getElementById("baselineHelp"),
gainButton: document.getElementById("gainButton"),
lossButton: document.getElementById("lossButton"),
undoButton: document.getElementById("undoButton"),
redoButton: document.getElementById("redoButton"),
clearButton: document.getElementById("clearButton"),
ledger: document.getElementById("ledger"),
currentMetric: document.getElementById("currentMetric"),
netMetric: document.getElementById("netMetric"),
relativeMetric: document.getElementById("relativeMetric"),
inspectCard: document.getElementById("inspectCard"),
inspectIndex: document.getElementById("inspectIndex"),
inspectTitle: document.getElementById("inspectTitle"),
inspectDetail: document.getElementById("inspectDetail"),
inspectClose: document.getElementById("inspectClose"),
toast: document.getElementById("toast")
};
const COLORS = {
gain: 0x64e6aa,
loss: 0xff737d,
initial: 0xf4c56b,
final: 0x7ed7ff,
floor: -1.85
};
const presets = {
steady: [
{ type: "gain", amount: 1200 },
{ type: "gain", amount: 800 },
{ type: "gain", amount: 1500 }
],
drawdown: [
{ type: "loss", amount: 1800 },
{ type: "loss", amount: 900 },
{ type: "gain", amount: 2400 }
],
whipsaw: [
{ type: "gain", amount: 2200 },
{ type: "loss", amount: 1700 },
{ type: "gain", amount: 1300 },
{ type: "loss", amount: 2400 }
]
};
let state = {
initial: 10000,
operations: []
};
const undoStack = [];
const redoStack = [];
let selectedIndex = null;
let toastTimer = null;
const cloneState = (source) => ({
initial: source.initial,
operations: source.operations.map((operation) => ({ ...operation }))
});
const currencyFormatter = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
minimumFractionDigits: 0,
maximumFractionDigits: 0
});
function formatCurrency(value) {
const absolute = Math.abs(value);
return `${value < 0 ? "−" : ""}${currencyFormatter.format(absolute)}`;
}
function formatSigned(value) {
return `${value >= 0 ? "+" : "−"}${currencyFormatter.format(Math.abs(value))}`;
}
function computeValues() {
const values = [state.initial];
let running = state.initial;
for (const operation of state.operations) {
running += operation.type === "gain" ? operation.amount : -operation.amount;
values.push(running);
}
return values;
}
function showToast(message) {
ui.toast.textContent = message;
ui.toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => ui.toast.classList.remove("visible"), 2100);
}
function commitState(nextState, message) {
const current = cloneState(state);
const next = cloneState(nextState);
if (
current.initial === next.initial &&
JSON.stringify(current.operations) === JSON.stringify(next.operations)
) {
return;
}
undoStack.push(current);
if (undoStack.length > 60) undoStack.shift();
state = next;
redoStack.length = 0;
if (selectedIndex !== null && selectedIndex > state.operations.length) {
selectedIndex = null;
}
rebuildScene();
renderUI();
showToast(message);
}
function undo() {
if (!undoStack.length) return;
redoStack.push(cloneState(state));
state = cloneState(undoStack.pop());
selectedIndex = null;
rebuildScene();
renderUI();
showToast("Undid the previous action.");
}
function redo() {
if (!redoStack.length) return;
undoStack.push(cloneState(state));
state = cloneState(redoStack.pop());
selectedIndex = null;
rebuildScene();
renderUI();
showToast("Redid the action.");
}
function applyChange(type) {
const amount = Number(ui.amountInput.value);
if (!Number.isFinite(amount) || amount <= 0) {
showToast("Enter a change amount greater than zero.");
ui.amountInput.focus();
return;
}
const operation = { type, amount };
commitState(
{
...state,
operations: [...state.operations, operation]
},
`${type === "gain" ? "Gain" : "Loss"} of ${formatCurrency(amount)} applied.`
);
}
function renderUI() {
const values = computeValues();
const current = values[values.length - 1];
const net = current - state.initial;
const relative = state.initial ? (net / state.initial) * 100 : 0;
const signClass = net > 0 ? "positive" : net < 0 ? "negative" : "neutral";
ui.currentMetric.textContent = formatCurrency(current);
ui.netMetric.textContent = formatSigned(net);
ui.netMetric.className = `metric-value ${signClass}`;
ui.relativeMetric.textContent = `${relative >= 0 ? "+" : "−"}${Math.abs(relative).toFixed(1)}%`;
ui.relativeMetric.className = `metric-value ${signClass}`;
if (document.activeElement !== ui.initialInput) {
ui.initialInput.value = state.initial;
}
const hasOperations = state.operations.length > 0;
ui.initialInput.disabled = hasOperations;
ui.baselineHelp.textContent = hasOperations
? "Clear or undo back to the start before changing the initial value."
: "Clear the path before changing the initial value.";
ui.undoButton.disabled = undoStack.length === 0;
ui.redoButton.disabled = redoStack.length === 0;
ui.clearButton.disabled = !hasOperations && undoStack.length === 0;
renderLedger(values);
updateSelectedUI();
}
function renderLedger(values) {
const initialMarkup = `
<div class="ledger-row initial" data-inspect="0" tabindex="0" role="button">
<div class="step-marker">00</div>
<div class="ledger-copy">
<strong>Initial position</strong>
<span>Starting value</span>
</div>
<div class="ledger-value">
<strong>${formatCurrency(state.initial)}</strong>
<span>Baseline</span>
</div>
</div>
`;
const operationMarkup = state.operations
.map((operation, index) => {
const signedAmount = operation.type === "gain" ? operation.amount : -operation.amount;
const result = values[index + 1];
return `
<div class="ledger-step ${operation.type}" data-inspect="${index + 1}" tabindex="0" role="button">
<div class="step-marker">${String(index + 1).padStart(2, "0")}</div>
<div class="ledger-copy">
<strong>${operation.type === "gain" ? "Gain" : "Loss"}</strong>
<span>Signed change ${formatSigned(signedAmount)}</span>
</div>
<div class="ledger-value">
<strong class="${operation.type}">${formatCurrency(result)}</strong>
<span>Result</span>
</div>
<button class="remove-step" data-remove="${index}" type="button" aria-label="Remove step ${index + 1}">×</button>
</div>
`;
})
.join("");
const emptyMarkup = state.operations.length
? ""
: `<div class="empty-ledger">No changes yet. Apply a gain or loss to create the first segment.</div>`;
const finalMarkup = `
<div class="ledger-row final" data-inspect="${state.operations.length}" tabindex="0" role="button">
<div class="step-marker">Σ</div>
<div class="ledger-copy">
<strong>Final position</strong>
<span>${state.operations.length} signed change${state.operations.length === 1 ? "" : "s"}</span>
</div>
<div class="ledger-value">
<strong>${formatCurrency(values[values.length - 1])}</strong>
<span>${formatSigned(values[values.length - 1] - state.initial)} from start</span>
</div>
</div>
`;
ui.ledger.innerHTML = `
${initialMarkup}
${operationMarkup ? `<div class="ledger-connector"></div>${operationMarkup}` : ""}
${emptyMarkup}
${operationMarkup ? `<div class="ledger-connector"></div>` : ""}
${finalMarkup}
`;
}
function selectStep(index) {
const values = computeValues();
selectedIndex = index;
if (index === 0) {
ui.inspectIndex.textContent = "00";
ui.inspectTitle.textContent = "Initial position";
ui.inspectDetail.textContent = `Starting value ${formatCurrency(state.initial)}`;
} else if (index === state.operations.length && state.operations.length > 0) {
const operation = state.operations[state.operations.length - 1];
ui.inspectIndex.textContent = "Σ";
ui.inspectTitle.textContent = "Final position";
ui.inspectDetail.textContent =
`${formatCurrency(values[values.length - 1])} · ` +
`final ${operation.type} ${formatCurrency(operation.amount)}`;
} else if (state.operations[index - 1]) {
const operation = state.operations[index - 1];
ui.inspectIndex.textContent = String(index).padStart(2, "0");
ui.inspectTitle.textContent = `${operation.type === "gain" ? "Gain" : "Loss"} step`;
ui.inspectDetail.textContent =
`${formatSigned(operation.type === "gain" ? operation.amount : -operation.amount)} · ` +
`result ${formatCurrency(values[index])}`;
}
ui.inspectCard.classList.add("visible");
updateSelectedUI();
}
function updateSelectedUI() {
ui.ledger.querySelectorAll("[data-inspect]").forEach((row) => {
row.classList.toggle(
"selected",
selectedIndex !== null && Number(row.dataset.inspect) === selectedIndex
);
});
}
// Three.js scene
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x0a0f17, 0.026);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive 3D token position path");
renderer.domElement.setAttribute("role", "img");
ui.stage.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(43, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.65, 0);
const orbit = {
azimuth: 0,
polar: 1.16,
radius: 15.2,
targetAzimuth: 0,
targetPolar: 1.16,
targetRadius: 15.2
};
const hemisphere = new THREE.HemisphereLight(0xa6cfff, 0x11141b, 1.7);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(5, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const gainLight = new THREE.PointLight(COLORS.gain, 34, 15, 2);
gainLight.position.set(-7, 2, -4);
scene.add(gainLight);
const lossLight = new THREE.PointLight(COLORS.loss, 28, 15, 2);
lossLight.position.set(7, 0, -3);
scene.add(lossLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(38, 26),
new THREE.MeshStandardMaterial({
color: 0x0d131c,
roughness: 0.94,
metalness: 0.05
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = COLORS.floor;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(34, 34, 0x33465b, 0x1b2735);
grid.position.y = COLORS.floor + 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.38;
scene.add(grid);
const dustGeometry = new THREE.BufferGeometry();
const dustPositions = new Float32Array(220 * 3);
for (let index = 0; index < 220; index += 1) {
dustPositions[index * 3] = (Math.random() - 0.5) * 34;
dustPositions[index * 3 + 1] = Math.random() * 12 - 1;
dustPositions[index * 3 + 2] = (Math.random() - 0.5) * 25;
}
dustGeometry.setAttribute("position", new THREE.BufferAttribute(dustPositions, 3));
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0x6b8299,
size: 0.035,
transparent: true,
opacity: 0.42,
sizeAttenuation: true
})
);
scene.add(dust);
function seededRandom(seed) {
const value = Math.sin(seed * 9301 + 49297) * 233280;
return value - Math.floor(value);
}
for (let index = 0; index < 20; index += 1) {
const side = index % 2 === 0 ? -1 : 1;
const stone = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.15 + seededRandom(index + 2) * 0.34, 0),
new THREE.MeshStandardMaterial({
color: index % 3 === 0 ? 0x1b2734 : 0x141d28,
roughness: 0.88,
metalness: 0.08,
flatShading: true
})
);
stone.position.set(
(seededRandom(index + 20) - 0.5) * 26,
COLORS.floor + 0.12,
side * (4.5 + seededRandom(index + 40) * 5)
);
stone.scale.y = 0.55 + seededRandom(index + 60) * 0.9;
stone.rotation.set(
seededRandom(index + 70),
seededRandom(index + 80),
seededRandom(index + 90)
);
stone.castShadow = true;
stone.receiveShadow = true;
scene.add(stone);
}
const dynamicGroup = new THREE.Group();
scene.add(dynamicGroup);
let nodeGroups = [];
let pathLabels = [];
let selectedNode = null;
function disposeObject(object) {
object.traverse((child) => {
if (child.geometry) child.geometry.dispose();
if (child.material) {
const materials = Array.isArray(child.material) ? child.material : [child.material];
materials.forEach((material) => material.dispose());
}
});
}
function heightForValue(value) {
const relative = (value - state.initial) / Math.max(Math.abs(state.initial), 1);
const shaped = Math.tanh(relative * 3.4) * 2.5;
return 1.8 + THREE.MathUtils.clamp(shaped, -1.9, 2.85);
}
function createSegment(start, end, color) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const midpoint = new THREE.Vector3().addVectors(start, end).multiplyScalar(0.5);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.14,
roughness: 0.42,
metalness: 0.18,
flatShading: true
});
const segment = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.075, length, 6, 1, false),
material
);
segment.position.copy(midpoint);
segment.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
segment.castShadow = true;
dynamicGroup.add(segment);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.145, 0.3, 6),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.12,
roughness: 0.4,
metalness: 0.15,
flatShading: true
})
);
arrow.position.lerpVectors(start, end, 0.58);
arrow.quaternion.copy(segment.quaternion);
arrow.castShadow = true;
dynamicGroup.add(arrow);
}
function createFloorMarker(position, color, isFinal = false) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(isFinal ? 0.54 : 0.38, 0.022, 4, 28),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: isFinal ? 0.72 : 0.36
})
);
ring.rotation.x = Math.PI / 2;
ring.position.set(position.x, COLORS.floor + 0.025, position.z);
dynamicGroup.add(ring);
}
function createStem(position, color) {
const length = Math.max(0.05, position.y - COLORS.floor);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.012, 0.012, length, 4),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.23
})
);
stem.position.set(position.x, COLORS.floor + length / 2, position.z);
dynamicGroup.add(stem);
}
function createNode(position, color, index, isFinal) {
const group = new THREE.Group();
group.position.copy(position);
group.userData.stepIndex = index;
const geometry =
index === 0
? new THREE.OctahedronGeometry(0.46, 0)
: isFinal
? new THREE.DodecahedronGeometry(0.39, 0)
: new THREE.IcosahedronGeometry(0.34, 0);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: index === 0 ? 0.16 : 0.1,
roughness: 0.3,
metalness: 0.32,
flatShading: true
});
const core = new THREE.Mesh(geometry, material);
core.castShadow = true;
core.receiveShadow = true;
group.add(core);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 18),
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.19
})
);
group.add(edges);
if (isFinal) {
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.55, 0.025, 4, 36),
new THREE.MeshBasicMaterial({
color: COLORS.final,
transparent: true,
opacity: 0.58
})
);
halo.rotation.x = Math.PI / 2;
group.add(halo);
}
const baseScale = index === 0 ? 1.1 : isFinal ? 1.08 : 1;
group.scale.setScalar(baseScale);
group.userData.baseScale = baseScale;
dynamicGroup.add(group);
nodeGroups.push(group);
return group;
}
function buildLabel(position, className, kicker, value, delta) {
const label = document.createElement("button");
label.type = "button";
label.className = `node-label ${className}`;
label.innerHTML = `
<span class="label-kicker">${kicker}</span>
<span class="label-value">${value}</span>
${delta ? `<span class="label-delta">${delta}</span>` : ""}
`;
label.addEventListener("click", (event) => {
event.stopPropagation();
selectStep(position.userData.stepIndex);
});
ui.labelsLayer.appendChild(label);
pathLabels.push({ element: label, position: position.clone() });
}
function rebuildScene() {
disposeObject(dynamicGroup);
dynamicGroup.clear();
nodeGroups = [];
pathLabels = [];
ui.labelsLayer.innerHTML = "";
selectedNode = null;
const values = computeValues();
const count = values.length;
const spacing = count > 1 ? 11 / (count - 1) : 0;
const positions = [];
for (let index = 0; index < count; index += 1) {
const x = count === 1 ? 0 : -5.5 + index * spacing;
const z = Math.sin(index * 1.12) * 1.05 + Math.cos(index * 0.51) * 0.24;
const y = heightForValue(values[index]);
positions.push(new THREE.Vector3(x, y, z));
}
for (let index = 0; index < count; index += 1) {
const isInitial = index === 0;
const isFinal = index === count - 1 && state.operations.length > 0;
const operation = state.operations[index - 1];
const signed = operation
? operation.type === "gain"
? operation.amount
: -operation.amount
: 0;
const color = isInitial
? COLORS.initial
: isFinal
? COLORS.final
: operation.type === "gain"
? COLORS.gain
: COLORS.loss;
const group = createNode(positions[index], color, index, isFinal);
if (selectedIndex === index) selectedNode = group;
createFloorMarker(positions[index], color, isFinal);
createStem(positions[index], color);
if (index > 0) {
createSegment(positions[index - 1], positions[index], color);
}
const labelClass = isFinal
? "final"
: isInitial
? "initial"
: operation.type;
const kicker = isFinal
? `Final · Step ${index}`
: isInitial
? "Start"
: `${operation.type === "gain" ? "Gain" : "Loss"} · Step ${index}`;
const labelPosition = positions[index].clone();
labelPosition.userData = { stepIndex: index };
buildLabel(
labelPosition,
labelClass,
kicker,
formatCurrency(values[index]),
operation ? formatSigned(signed) : "Initial position"
);
}
}
function resizeRenderer() {
const width = ui.stage.clientWidth;
const height = ui.stage.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(ui.stage);
resizeRenderer();
// Direct camera controls: no addons are used.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let pointerMoved = false;
let previousX = 0;
let previousY = 0;
function setPointerFromEvent(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;
}
function pickNode(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(nodeGroups, true);
if (!intersections.length) return null;
let object = intersections[0].object;
while (object) {
if (
object.userData &&
Number.isInteger(object.userData.stepIndex)
) {
return object.userData.stepIndex;
}
object = object.parent;
}
return null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerMoved = false;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
if (Math.abs(deltaX) + Math.abs(deltaY) > 2) pointerMoved = true;
orbit.targetAzimuth -= deltaX * 0.007;
orbit.targetPolar = THREE.MathUtils.clamp(
orbit.targetPolar - deltaY * 0.006,
0.48,
1.43
);
previousX = event.clientX;
previousY = event.clientY;
} else {
renderer.domElement.style.cursor = pickNode(event) !== null ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (dragging && !pointerMoved) {
const index = pickNode(event);
if (index !== null) selectStep(index);
}
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
pointerMoved = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.targetRadius = THREE.MathUtils.clamp(
orbit.targetRadius + event.deltaY * 0.012,
8.5,
25
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
orbit.targetAzimuth = 0;
orbit.targetPolar = 1.16;
orbit.targetRadius = 15.2;
showToast("Camera reset.");
});
function updateCamera() {
orbit.azimuth += (orbit.targetAzimuth - orbit.azimuth) * 0.12;
orbit.polar += (orbit.targetPolar - orbit.polar) * 0.12;
orbit.radius += (orbit.targetRadius - orbit.radius) * 0.12;
const sinPolar = Math.sin(orbit.polar);
camera.position.set(
cameraTarget.x + orbit.radius * sinPolar * Math.sin(orbit.azimuth),
cameraTarget.y + orbit.radius * Math.cos(orbit.polar),
cameraTarget.z + orbit.radius * sinPolar * Math.cos(orbit.azimuth)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function updateLabels() {
const width = ui.stage.clientWidth;
const height = ui.stage.clientHeight;
for (const label of pathLabels) {
const projected = label.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.transform = `translate3d(${x}px, ${y}px, 0) translate(-50%, -50%)`;
}
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera();
nodeGroups.forEach((group, index) => {
group.rotation.y += delta * (index === 0 ? 0.28 : 0.42);
group.rotation.x = Math.sin(elapsed * 0.65 + index) * 0.08;
const isSelected = group === selectedNode;
const pulse = isSelected
? 1 + Math.sin(elapsed * 4.8) * 0.09
: 1 + Math.sin(elapsed * 1.8 + index * 0.7) * 0.025;
group.scale.setScalar(group.userData.baseScale * pulse);
});
dust.rotation.y += delta * 0.007;
updateLabels();
renderer.render(scene, camera);
}
// Interface events
ui.gainButton.addEventListener("click", () => applyChange("gain"));
ui.lossButton.addEventListener("click", () => applyChange("loss"));
ui.undoButton.addEventListener("click", undo);
ui.redoButton.addEventListener("click", redo);
ui.clearButton.addEventListener("click", () => {
if (!state.operations.length) return;
commitState(
{ ...state, operations: [] },
"Path cleared. Use undo to restore it."
);
});
ui.initialInput.addEventListener("change", () => {
if (state.operations.length) {
ui.initialInput.value = state.initial;
showToast("Clear the path before changing the initial value.");
return;
}
const value = Number(ui.initialInput.value);
if (!Number.isFinite(value) || value <= 0) {
ui.initialInput.value = state.initial;
showToast("The initial value must be greater than zero.");
return;
}
commitState(
{ initial: value, operations: [] },
`Initial value set to ${formatCurrency(value)}.`
);
});
ui.amountInput.addEventListener("keydown", (event) => {
if (event.key === "Enter") applyChange("gain");
});
ui.inspectClose.addEventListener("click", () => {
selectedIndex = null;
selectedNode = null;
ui.inspectCard.classList.remove("visible");
updateSelectedUI();
});
ui.ledger.addEventListener("click", (event) => {
const removeButton = event.target.closest("[data-remove]");
if (removeButton) {
event.stopPropagation();
const index = Number(removeButton.dataset.remove);
commitState(
{
...state,
operations: state.operations.filter((_, operationIndex) => operationIndex !== index)
},
`Step ${index + 1} removed.`
);
return;
}
const row = event.target.closest("[data-inspect]");
if (row) selectStep(Number(row.dataset.inspect));
});
ui.ledger.addEventListener("keydown", (event) => {
if (event.key !== "Enter" && event.key !== " ") return;
const row = event.target.closest("[data-inspect]");
if (!row || event.target.closest("[data-remove]")) return;
event.preventDefault();
selectStep(Number(row.dataset.inspect));
});
document.querySelectorAll("[data-preset]").forEach((button) => {
button.addEventListener("click", () => {
const name = button.dataset.preset;
const pattern = presets[name];
if (!pattern) return;
commitState(
{
...state,
operations: pattern.map((operation) => ({ ...operation }))
},
`${button.querySelector(".preset-name").textContent} loaded.`
);
});
});
window.addEventListener("keydown", (event) => {
const tag = document.activeElement?.tagName;
const editing =
tag === "INPUT" ||
tag === "TEXTAREA" ||
document.activeElement?.isContentEditable;
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "z") {
event.preventDefault();
if (event.shiftKey) redo();
else undo();
return;
}
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "y") {
event.preventDefault();
redo();
return;
}
if (editing) return;
if (event.key.toLowerCase() === "g") {
event.preventDefault();
applyChange("gain");
}
if (event.key.toLowerCase() === "l") {
event.preventDefault();
applyChange("loss");
}
if (event.key === "Escape") {
selectedIndex = null;
selectedNode = null;
ui.inspectCard.classList.remove("visible");
updateSelectedUI();
}
});
rebuildScene();
renderUI();
animate();
</script>
</body>
</html>
```