Prompt specification
Build or customize the Three.js 3D scene "Repeated Beads and Count Tokens" 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: Repeated Beads and Count Tokens
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/repeated-beads-and-count-tokens-x3369
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this low-poly scene: Display a run of identical beads beside a symbol-plus-count representation. Show the exact expanded sequence so compression does not silently discard ordering information.
Working Three.js Starter (repeated-beads-and-count-tokens-x3369):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Ordered Beads — Symbol and Count</title>
<style>
:root {
--ink: #19352f;
--muted: #64766f;
--paper: #f5f2e9;
--panel: #fffef9;
--line: #d9ded7;
--coral: #ed704d;
--coral-dark: #c85034;
--sage: #dce7dd;
--green: #244d43;
--shadow: 0 16px 45px rgba(24, 53, 47, 0.1);
}
* {
box-sizing: border-box;
}
html {
color-scheme: light;
}
body {
margin: 0;
min-height: 100vh;
color: var(--ink);
background:
radial-gradient(circle at 10% 0%, rgba(237, 112, 77, 0.1), transparent 30%),
linear-gradient(135deg, #edf1eb, #f7f4ec);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.shell {
width: min(1440px, 100%);
margin: 0 auto;
padding: 28px;
}
header {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 24px;
margin-bottom: 22px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--coral-dark);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 3px;
border-radius: 999px;
background: var(--coral);
content: "";
}
h1 {
max-width: 760px;
margin: 0;
font-size: clamp(2rem, 4vw, 4.1rem);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.98;
}
header p {
max-width: 440px;
margin: 0 0 5px;
color: var(--muted);
line-height: 1.6;
}
.layout {
display: grid;
grid-template-columns: minmax(0, 1fr) 350px;
gap: 20px;
align-items: start;
}
.viewport {
position: relative;
min-height: 610px;
overflow: hidden;
border: 1px solid rgba(25, 53, 47, 0.1);
border-radius: 28px;
background: #e8ede6;
box-shadow: var(--shadow);
isolation: isolate;
}
.viewport canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
.viewport canvas:active {
cursor: grabbing;
}
.scene-toolbar {
position: absolute;
z-index: 3;
top: 16px;
right: 16px;
left: 16px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
pointer-events: none;
}
.scene-badge,
.scene-help,
.toolbar-button {
border: 1px solid rgba(25, 53, 47, 0.12);
background: rgba(255, 254, 249, 0.84);
box-shadow: 0 8px 25px rgba(25, 53, 47, 0.08);
backdrop-filter: blur(10px);
}
.scene-badge {
padding: 9px 12px;
border-radius: 999px;
font-size: 0.73rem;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.scene-badge span {
color: var(--coral-dark);
}
.toolbar-button {
pointer-events: auto;
padding: 9px 13px;
border-radius: 999px;
font-size: 0.78rem;
font-weight: 750;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
.toolbar-button:hover {
transform: translateY(-1px);
background: #fff;
}
.scene-help {
position: absolute;
z-index: 3;
bottom: 16px;
left: 50%;
padding: 8px 12px;
border-radius: 999px;
color: var(--muted);
font-size: 0.7rem;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
transform: translateX(-50%);
white-space: nowrap;
pointer-events: none;
}
aside {
display: grid;
gap: 14px;
}
.card {
border: 1px solid rgba(25, 53, 47, 0.1);
border-radius: 22px;
background: rgba(255, 254, 249, 0.94);
box-shadow: 0 12px 32px rgba(25, 53, 47, 0.07);
}
.card-inner {
padding: 19px;
}
.card h2 {
margin: 0 0 5px;
font-size: 0.98rem;
letter-spacing: -0.02em;
}
.card-subtitle {
margin: 0 0 16px;
color: var(--muted);
font-size: 0.78rem;
line-height: 1.45;
}
.counter-row {
display: grid;
grid-template-columns: 40px 1fr 40px 72px;
gap: 8px;
align-items: center;
}
.counter-row button,
.copy-button {
border: 1px solid var(--line);
border-radius: 12px;
background: #fff;
font-weight: 800;
cursor: pointer;
transition: border-color 150ms ease, transform 150ms ease;
}
.counter-row button {
height: 40px;
}
.counter-row button:hover,
.copy-button:hover {
border-color: var(--coral);
transform: translateY(-1px);
}
.counter-row input {
width: 100%;
height: 40px;
border: 1px solid var(--line);
border-radius: 12px;
outline: none;
background: #f8f8f3;
color: var(--ink);
font-weight: 800;
text-align: center;
}
.counter-row input:focus {
border-color: var(--coral);
box-shadow: 0 0 0 3px rgba(237, 112, 77, 0.14);
}
.apply-button {
color: white;
background: var(--green) !important;
border-color: var(--green) !important;
}
.summary-card {
overflow: hidden;
color: #f9f4e7;
background:
radial-gradient(circle at 85% 15%, rgba(237, 112, 77, 0.25), transparent 33%),
var(--green);
}
.summary-card .card-inner {
padding: 21px;
}
.summary-card .card-subtitle {
color: rgba(249, 244, 231, 0.67);
}
.notation {
display: flex;
align-items: center;
justify-content: center;
gap: 13px;
min-height: 82px;
font-size: 2.3rem;
font-weight: 800;
letter-spacing: -0.04em;
}
.notation .times {
color: rgba(249, 244, 231, 0.58);
font-weight: 500;
}
.gem {
position: relative;
display: inline-block;
flex: 0 0 auto;
width: 38px;
height: 38px;
background: var(--coral);
clip-path: polygon(
50% 0%,
83% 13%,
100% 48%,
79% 88%,
50% 100%,
18% 86%,
0% 48%,
17% 14%
);
filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.16));
}
.gem::after {
position: absolute;
top: 13px;
left: 13px;
width: 12px;
height: 12px;
border-radius: 50%;
background: var(--green);
content: "";
}
.summary-note {
margin: 3px 0 0;
color: rgba(249, 244, 231, 0.66);
font-size: 0.72rem;
line-height: 1.45;
text-align: center;
}
.exact-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 5px;
}
.exact-header h2 {
margin: 0;
}
.status {
padding: 5px 8px;
border-radius: 999px;
color: #326a55;
background: #e4f0e5;
font-size: 0.62rem;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.sequence-code {
overflow-wrap: anywhere;
margin: 13px 0;
padding: 11px 12px;
border: 1px solid #e1e4dd;
border-radius: 12px;
color: #40564f;
background: #f6f7f2;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: 0.72rem;
line-height: 1.7;
}
.sequence-list {
display: grid;
gap: 6px;
max-height: 210px;
margin: 0;
padding: 0;
overflow: auto;
list-style: none;
}
.sequence-list li {
display: flex;
align-items: center;
gap: 10px;
padding: 7px 9px;
border-radius: 10px;
background: #faf9f4;
font-size: 0.78rem;
}
.sequence-list .position {
min-width: 30px;
color: var(--muted);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 0.7rem;
font-weight: 750;
}
.sequence-list .gem {
width: 20px;
height: 20px;
filter: none;
}
.sequence-list .gem::after {
top: 7px;
left: 7px;
width: 6px;
height: 6px;
background: #28493f;
}
.sequence-list .name {
font-weight: 750;
}
.card-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 14px;
}
.card-footer p {
margin: 0;
color: var(--muted);
font-size: 0.7rem;
line-height: 1.4;
}
.copy-button {
flex: 0 0 auto;
padding: 8px 10px;
font-size: 0.72rem;
}
.explanation {
padding: 15px 18px;
border: 1px solid rgba(237, 112, 77, 0.22);
border-radius: 18px;
color: #6d564d;
background: rgba(255, 239, 229, 0.76);
font-size: 0.78rem;
line-height: 1.55;
}
.explanation strong {
color: #9c422d;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 1000px) {
header {
align-items: flex-start;
flex-direction: column;
}
header p {
max-width: 700px;
}
.layout {
grid-template-columns: 1fr;
}
aside {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.exact-card,
.explanation {
grid-column: 1 / -1;
}
}
@media (max-width: 650px) {
.shell {
padding: 16px;
}
header {
margin-bottom: 16px;
}
h1 {
font-size: clamp(2.25rem, 12vw, 3.2rem);
}
.viewport {
min-height: 500px;
border-radius: 20px;
}
aside {
grid-template-columns: 1fr;
}
.exact-card,
.explanation {
grid-column: auto;
}
.scene-help {
font-size: 0.6rem;
}
}
</style>
</head>
<body>
<main class="shell">
<header>
<div>
<div class="eyebrow">Order-preserving visualizer</div>
<h1>A run, not just a total.</h1>
</div>
<p>
Compare an ordered run of identical low-poly beads with a compact
symbol-plus-count form. The exact sequence remains visible and authoritative.
</p>
</header>
<div class="layout">
<section
id="viewport"
class="viewport"
aria-label="Interactive Three.js scene showing beads beside a symbol and count"
>
<div class="scene-toolbar">
<div class="scene-badge"><span>●</span> Expanded ↔ Compact</div>
<button id="resetView" class="toolbar-button" type="button">
Reset view
</button>
</div>
<div class="scene-help">Drag to orbit · Scroll to zoom · Double-click to reset</div>
</section>
<aside aria-label="Representation details">
<section class="card">
<div class="card-inner">
<h2>Run size</h2>
<p class="card-subtitle">Change the number of identical beads.</p>
<div class="counter-row">
<button id="minus" type="button" aria-label="Remove one bead">−</button>
<input
id="count"
type="number"
min="1"
max="10"
step="1"
value="8"
aria-label="Number of beads"
/>
<button id="plus" type="button" aria-label="Add one bead">+</button>
<button id="apply" class="apply-button" type="button">Apply</button>
</div>
</div>
</section>
<section class="card summary-card">
<div class="card-inner">
<h2>Compact representation</h2>
<p class="card-subtitle">A derived summary of the ordered run.</p>
<div class="notation" aria-label="Symbol multiplied by count">
<span class="gem" aria-hidden="true"></span>
<span class="times">×</span>
<strong id="summaryCount">8</strong>
</div>
<p class="summary-note">
Compact form: one symbol multiplied by the run length.
</p>
</div>
</section>
<section class="card exact-card">
<div class="card-inner">
<div class="exact-header">
<h2>Exact expanded sequence</h2>
<span class="status">Order retained</span>
</div>
<p class="card-subtitle">
Every position is explicit. Compression does not replace this list.
</p>
<div id="sequenceCode" class="sequence-code"></div>
<ol id="sequenceList" class="sequence-list"></ol>
<div class="card-footer">
<p>Indexed tokens preserve the original left-to-right order.</p>
<button id="copySequence" class="copy-button" type="button">
Copy
</button>
</div>
</div>
</section>
<div class="explanation">
<strong>Order-safe by design:</strong> “symbol × count” is only a summary.
The numbered expansion is kept alongside it, so no ordering information is
silently discarded.
</div>
<div id="liveStatus" class="sr-only" aria-live="polite"></div>
</aside>
</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const countInput = document.getElementById("count");
const summaryCount = document.getElementById("summaryCount");
const sequenceCode = document.getElementById("sequenceCode");
const sequenceList = document.getElementById("sequenceList");
const copyButton = document.getElementById("copySequence");
const liveStatus = document.getElementById("liveStatus");
let beadCount = 8;
let exactSequence = "";
// -------------------------------------------------------------------------
// Renderer, scene, camera, and lights
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional ordered bead run. Drag to orbit and scroll to zoom."
);
viewport.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8ede6);
scene.fog = new THREE.Fog(0xe8ede6, 20, 38);
const camera = new THREE.OrthographicCamera(-7, 7, 5, -5, 0.1, 100);
const cameraTarget = new THREE.Vector3(-0.45, -0.05, 0);
const cameraState = {
radius: 18,
phi: 1.05,
theta: 0.24,
zoom: 1
};
function updateCamera() {
const { radius, phi, theta } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.sin(phi) * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
function resetCamera() {
cameraState.phi = 1.05;
cameraState.theta = 0.24;
cameraState.zoom = 1;
updateCamera();
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff8e9, 0x91a89c, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2dc, 4.2);
keyLight.position.set(-5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc5ddff, 1.35);
fillLight.position.set(8, 4, -7);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0xe4e9e2,
roughness: 1,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.55;
floor.receiveShadow = true;
scene.add(floor);
const staticGroup = new THREE.Group();
const runGroup = new THREE.Group();
const summaryGroup = new THREE.Group();
const expandedGroup = new THREE.Group();
scene.add(staticGroup, runGroup, summaryGroup, expandedGroup);
// Shared materials and geometry ensure every bead is genuinely identical.
const beadGeometry = new THREE.IcosahedronGeometry(0.31, 1);
const beadMaterial = new THREE.MeshStandardMaterial({
color: 0xed704d,
roughness: 0.62,
metalness: 0.04,
flatShading: true
});
const holeGeometry = new THREE.TorusGeometry(0.078, 0.024, 4, 10);
const holeMaterial = new THREE.MeshStandardMaterial({
color: 0x19352f,
roughness: 0.9,
metalness: 0,
flatShading: true
});
const stringGeometry = new THREE.CylinderGeometry(0.018, 0.018, 1, 6);
const stringMaterial = new THREE.MeshStandardMaterial({
color: 0x49685f,
roughness: 0.9
});
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0xd4dfd4,
roughness: 0.82,
metalness: 0,
flatShading: true
});
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0xf7f0df,
roughness: 0.78,
flatShading: true
});
const boardMaterial = new THREE.MeshStandardMaterial({
color: 0x244d43,
roughness: 0.72,
metalness: 0.02,
flatShading: true
});
const beadPlatform = new THREE.Mesh(
new THREE.BoxGeometry(8, 0.25, 2.5),
platformMaterial
);
beadPlatform.position.set(-2.65, -0.61, 0);
beadPlatform.receiveShadow = true;
beadPlatform.castShadow = true;
staticGroup.add(beadPlatform);
const summaryPlatform = new THREE.Mesh(
new THREE.BoxGeometry(3.55, 0.25, 2.5),
platformMaterial
);
summaryPlatform.position.set(3.65, -0.61, 0);
summaryPlatform.receiveShadow = true;
summaryPlatform.castShadow = true;
staticGroup.add(summaryPlatform);
const boardFrame = new THREE.Mesh(
new THREE.BoxGeometry(3.15, 1.95, 0.18),
frameMaterial
);
boardFrame.position.set(3.65, 0.12, -0.22);
boardFrame.castShadow = true;
boardFrame.receiveShadow = true;
staticGroup.add(boardFrame);
const board = new THREE.Mesh(
new THREE.BoxGeometry(3, 1.8, 0.22),
boardMaterial
);
board.position.set(3.65, 0.12, -0.1);
board.castShadow = true;
board.receiveShadow = true;
staticGroup.add(board);
// -------------------------------------------------------------------------
// Canvas-based text sprites. No external fonts or addons are required.
// -------------------------------------------------------------------------
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeTextSprite(
text,
{
worldWidth = 2,
worldHeight = 0.45,
color = "#19352f",
fontSize = 96,
fontWeight = 800,
background = null,
canvasWidth = 768,
canvasHeight = 256
} = {}
) {
const canvas = document.createElement("canvas");
canvas.width = canvasWidth;
canvas.height = canvasHeight;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (background) {
ctx.fillStyle = background;
roundedRect(ctx, 4, 4, canvas.width - 8, canvas.height - 8, 30);
ctx.fill();
}
let size = fontSize;
ctx.font = `${fontWeight} ${size}px Inter, system-ui, sans-serif`;
while (ctx.measureText(text).width > canvas.width * 0.88 && size > 24) {
size -= 2;
ctx.font = `${fontWeight} ${size}px Inter, system-ui, sans-serif`;
}
ctx.fillStyle = color;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 3);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldHeight, 1);
sprite.renderOrder = 10;
sprite.userData.ownedTexture = texture;
return sprite;
}
function makeExpandedStrip(count) {
const canvas = document.createElement("canvas");
canvas.width = 1800;
canvas.height = 220;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(255, 254, 249, 0.96)";
roundedRect(ctx, 5, 5, canvas.width - 10, canvas.height - 10, 34);
ctx.fill();
ctx.strokeStyle = "rgba(25, 53, 47, 0.13)";
ctx.lineWidth = 5;
ctx.stroke();
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillStyle = "#64766f";
ctx.font = "800 30px Inter, system-ui, sans-serif";
ctx.fillText("EXPANDED SEQUENCE • ORDERED", 42, 47);
const cellWidth = (canvas.width - 80) / count;
for (let i = 0; i < count; i++) {
const x = 40 + cellWidth * (i + 0.5);
const number = String(i + 1).padStart(2, "0");
ctx.fillStyle = "#64766f";
ctx.font = "800 30px SFMono-Regular, Consolas, monospace";
ctx.textAlign = "right";
ctx.fillText(number, x - 18, 139);
const symbolX = x + 12;
const symbolY = 139;
const radius = 24;
ctx.beginPath();
for (let side = 0; side < 8; side++) {
const angle = (Math.PI * 2 * side) / 8 - Math.PI / 2;
const px = symbolX + Math.cos(angle) * radius;
const py = symbolY + Math.sin(angle) * radius;
if (side === 0) ctx.moveTo(px, py);
else ctx.lineTo(px, py);
}
ctx.closePath();
ctx.fillStyle = "#ed704d";
ctx.fill();
ctx.beginPath();
ctx.arc(symbolX, symbolY, 7, 0, Math.PI * 2);
ctx.fillStyle = "#244d43";
ctx.fill();
if (i < count - 1) {
ctx.fillStyle = "#9ba9a3";
ctx.font = "700 28px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.fillText("→", x + cellWidth * 0.5, 139);
}
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(7.25, 0.89, 1);
sprite.renderOrder = 12;
sprite.userData.ownedTexture = texture;
return sprite;
}
const runTitle = makeTextSprite("IDENTICAL BEADS", {
worldWidth: 3.25,
worldHeight: 0.43,
color: "#19352f",
fontSize: 84
});
runTitle.position.set(-2.65, 1.38, 0);
staticGroup.add(runTitle);
const runSubtitle = makeTextSprite("ordered left to right", {
worldWidth: 2.35,
worldHeight: 0.3,
color: "#708078",
fontSize: 55,
fontWeight: 650
});
runSubtitle.position.set(-2.65, 0.96, 0);
staticGroup.add(runSubtitle);
const summaryTitle = makeTextSprite("SYMBOL + COUNT", {
worldWidth: 2.9,
worldHeight: 0.43,
color: "#19352f",
fontSize: 84
});
summaryTitle.position.set(3.65, 1.38, 0);
staticGroup.add(summaryTitle);
const summarySubtitle = makeTextSprite("compact summary", {
worldWidth: 2.15,
worldHeight: 0.3,
color: "#708078",
fontSize: 55,
fontWeight: 650
});
summarySubtitle.position.set(3.65, 0.96, 0);
staticGroup.add(summarySubtitle);
const arrow = makeTextSprite("→", {
worldWidth: 0.52,
worldHeight: 0.52,
color: "#9a6b59",
fontSize: 170,
fontWeight: 600
});
arrow.position.set(1.72, 0.14, 0.35);
staticGroup.add(arrow);
const detailsNote = makeTextSprite("ORDER KEPT BELOW", {
worldWidth: 2.25,
worldHeight: 0.26,
color: "#f8f0dc",
fontSize: 52
});
detailsNote.position.set(3.65, -1.02, 0.42);
staticGroup.add(detailsNote);
// -------------------------------------------------------------------------
// Dynamic scene construction
// -------------------------------------------------------------------------
function disposeDynamicSprites(group) {
group.traverse((object) => {
if (object.isSprite && object.userData.ownedTexture) {
object.material.map?.dispose();
object.material.dispose();
}
});
group.clear();
}
function createBead() {
const group = new THREE.Group();
const body = new THREE.Mesh(beadGeometry, beadMaterial);
body.castShadow = true;
body.receiveShadow = true;
const hole = new THREE.Mesh(holeGeometry, holeMaterial);
hole.position.z = 0.292;
group.add(body, hole);
return group;
}
function rebuildScene() {
disposeDynamicSprites(runGroup);
disposeDynamicSprites(summaryGroup);
disposeDynamicSprites(expandedGroup);
const count = beadCount;
const spacing = count === 1 ? 0 : Math.min(0.82, 6.8 / (count - 1));
const totalWidth = spacing * (count - 1);
const runCenter = -2.65;
const string = new THREE.Mesh(stringGeometry, stringMaterial);
string.rotation.z = Math.PI / 2;
string.scale.y = Math.max(1.2, totalWidth + 1.1);
string.position.set(runCenter, -0.16, 0);
runGroup.add(string);
for (let i = 0; i < count; i++) {
const x = runCenter - totalWidth / 2 + i * spacing;
const bead = createBead();
bead.position.set(x, -0.16, 0);
runGroup.add(bead);
const indexLabel = makeTextSprite(String(i + 1).padStart(2, "0"), {
worldWidth: 0.42,
worldHeight: 0.25,
color: "#526b62",
fontSize: 105,
fontWeight: 800,
canvasWidth: 256,
canvasHeight: 160
});
indexLabel.position.set(x, -0.77, 0.72);
runGroup.add(indexLabel);
}
const expandedStrip = makeExpandedStrip(count);
expandedStrip.position.set(runCenter, -1.07, 0.95);
expandedGroup.add(expandedStrip);
const summarySymbol = createBead();
summarySymbol.position.set(3.0, 0.19, 0.24);
summarySymbol.scale.setScalar(1.18);
summaryGroup.add(summarySymbol);
const countLabel = makeTextSprite(`× ${count}`, {
worldWidth: 1.65,
worldHeight: 0.78,
color: "#fff8e8",
fontSize: 185,
fontWeight: 800
});
countLabel.position.set(3.9, 0.2, 0.4);
summaryGroup.add(countLabel);
updateDOM();
}
function updateDOM() {
summaryCount.textContent = String(beadCount);
const tokens = Array.from(
{ length: beadCount },
(_, index) => `●[${String(index + 1).padStart(2, "0")}]`
);
exactSequence = tokens.join(" → ");
sequenceCode.textContent = exactSequence;
sequenceList.replaceChildren();
for (let i = 0; i < beadCount; i++) {
const item = document.createElement("li");
const position = document.createElement("span");
position.className = "position";
position.textContent = String(i + 1).padStart(2, "0");
const symbol = document.createElement("span");
symbol.className = "gem";
symbol.setAttribute("aria-hidden", "true");
const name = document.createElement("span");
name.className = "name";
name.textContent = `Bead ${String(i + 1).padStart(2, "0")}`;
item.append(position, symbol, name);
sequenceList.append(item);
}
liveStatus.textContent =
`Updated to ${beadCount} beads. The exact ordered sequence is displayed.`;
}
function applyCount() {
const parsed = Number.parseInt(countInput.value, 10);
const safeCount = Number.isFinite(parsed)
? THREE.MathUtils.clamp(parsed, 1, 10)
: 8;
beadCount = safeCount;
countInput.value = String(beadCount);
rebuildScene();
}
document.getElementById("apply").addEventListener("click", applyCount);
document.getElementById("minus").addEventListener("click", () => {
countInput.value = String(Math.max(1, beadCount - 1));
applyCount();
});
document.getElementById("plus").addEventListener("click", () => {
countInput.value = String(Math.min(10, beadCount + 1));
applyCount();
});
countInput.addEventListener("keydown", (event) => {
if (event.key === "Enter") {
event.preventDefault();
applyCount();
}
});
copyButton.addEventListener("click", async () => {
try {
await navigator.clipboard.writeText(exactSequence);
} catch {
const textarea = document.createElement("textarea");
textarea.value = exactSequence;
textarea.style.position = "fixed";
textarea.style.opacity = "0";
document.body.append(textarea);
textarea.select();
document.execCommand("copy");
textarea.remove();
}
const oldText = copyButton.textContent;
copyButton.textContent = "Copied";
setTimeout(() => {
copyButton.textContent = oldText;
}, 1200);
});
document.getElementById("resetView").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Custom camera controls, implemented without Three.js addons.
// -------------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
cameraState.theta -= deltaX * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.005,
0.48,
1.43
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = event.deltaY > 0 ? 0.9 : 1.1;
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * factor,
0.65,
1.85
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") {
cameraState.theta += step;
} else if (event.key === "ArrowRight") {
cameraState.theta -= step;
} else if (event.key === "ArrowUp") {
cameraState.phi = Math.max(0.48, cameraState.phi - step);
} else if (event.key === "ArrowDown") {
cameraState.phi = Math.min(1.43, cameraState.phi + step);
} else if (event.key === "+" || event.key === "=") {
cameraState.zoom = Math.min(1.85, cameraState.zoom * 1.1);
} else if (event.key === "-") {
cameraState.zoom = Math.max(0.65, cameraState.zoom * 0.9);
} else if (event.key.toLowerCase() === "r") {
resetCamera();
} else {
return;
}
event.preventDefault();
updateCamera();
});
// -------------------------------------------------------------------------
// Responsive sizing and render loop
// -------------------------------------------------------------------------
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
const aspect = width / height;
const visibleHeight = Math.max(7.8, 13.5 / aspect);
camera.left = (-visibleHeight * aspect) / 2;
camera.right = (visibleHeight * aspect) / 2;
camera.top = visibleHeight / 2;
camera.bottom = -visibleHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
resize();
rebuildScene();
function render() {
renderer.render(scene, camera);
requestAnimationFrame(render);
}
render();
</script>
</body>
</html>
```