Prompt specification
Build or customize the Three.js 3D scene "Festival pattern-making workshop" 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: Festival pattern-making workshop
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/festival-pattern-making-workshop-x0348
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a kaleidoscope. Build a creative booth that turns selected bead patterns into a rotating projected ornament; keep the original seed pattern visible so transformation and repetition remain traceable. Low-poly.
Working Three.js Starter (festival-pattern-making-workshop-x0348):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Kaleido Projection Booth</title>
<style>
:root {
--paper: #f4f0e6;
--paper-deep: #e7e1d3;
--ink: #17324a;
--muted: #6e776f;
--coral: #ef6b52;
--gold: #efba3d;
--teal: #4d948a;
--sky: #7eb5c4;
--plum: #aa89b5;
--line: rgba(23, 50, 74, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(
circle at 50% 43%,
transparent 40%,
rgba(23, 50, 74, 0.045) 100%
);
}
.topbar {
position: fixed;
z-index: 5;
top: 0;
left: 0;
right: 0;
display: flex;
align-items: flex-start;
justify-content: space-between;
padding: 24px 28px;
pointer-events: none;
}
.brand {
max-width: 430px;
}
.eyebrow,
.console-kicker,
.readout-label,
.hint,
.mini-label {
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.eyebrow {
margin-bottom: 8px;
color: var(--coral);
font-size: 10px;
font-weight: 800;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 43px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.045em;
}
.brand-subtitle {
margin-top: 9px;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.015em;
}
.readout {
display: flex;
align-items: center;
gap: 12px;
padding: 10px 12px;
border: 1px solid var(--line);
background: rgba(244, 240, 230, 0.76);
backdrop-filter: blur(10px);
pointer-events: auto;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(77, 148, 138, 0.14);
}
.readout-copy {
display: grid;
gap: 3px;
}
.readout-label {
color: var(--muted);
font-size: 8px;
}
.readout-value {
font-size: 11px;
font-weight: 800;
letter-spacing: 0.05em;
}
.view-button {
margin-left: 4px;
border: 1px solid var(--line);
padding: 8px 9px;
background: transparent;
cursor: pointer;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
transition: 160ms ease;
}
.view-button:hover {
border-color: var(--ink);
background: var(--ink);
color: var(--paper);
}
.console {
position: fixed;
z-index: 6;
left: 50%;
bottom: 24px;
width: min(760px, calc(100vw - 32px));
transform: translateX(-50%);
padding: 16px;
border: 1px solid rgba(23, 50, 74, 0.23);
background: rgba(248, 244, 234, 0.94);
box-shadow:
0 18px 50px rgba(23, 50, 74, 0.14),
0 2px 0 rgba(255, 255, 255, 0.75) inset;
backdrop-filter: blur(16px);
}
.console-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin-bottom: 12px;
}
.console-kicker {
display: block;
margin-bottom: 4px;
color: var(--coral);
font-size: 9px;
font-weight: 800;
}
.console-description {
color: var(--muted);
font-size: 11px;
}
.console-actions {
display: flex;
gap: 7px;
flex: 0 0 auto;
}
.console-button {
min-width: 72px;
padding: 8px 10px;
border: 1px solid var(--ink);
background: transparent;
cursor: pointer;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
transition: 150ms ease;
}
.console-button.primary {
background: var(--ink);
color: var(--paper);
}
.console-button:hover {
background: var(--coral);
border-color: var(--coral);
color: white;
}
.patterns {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 8px;
margin-bottom: 14px;
}
.pattern-button {
display: flex;
min-width: 0;
align-items: center;
gap: 10px;
padding: 9px;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.25);
text-align: left;
cursor: pointer;
transition: 150ms ease;
}
.pattern-button:hover {
border-color: var(--ink);
transform: translateY(-1px);
}
.pattern-button.active {
border-color: var(--ink);
background: white;
box-shadow: 3px 3px 0 var(--ink);
}
.mini-grid {
display: grid;
flex: 0 0 auto;
grid-template-columns: repeat(6, 1fr);
width: 30px;
height: 30px;
gap: 1px;
padding: 2px;
border: 1px solid var(--line);
background: var(--paper-deep);
}
.mini-grid span {
background: transparent;
}
.pattern-copy {
min-width: 0;
}
.pattern-name {
display: block;
overflow: hidden;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.09em;
text-overflow: ellipsis;
white-space: nowrap;
}
.pattern-count {
display: block;
margin-top: 3px;
color: var(--muted);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 8px;
}
.control-row {
display: grid;
grid-template-columns: 1fr 1fr auto;
align-items: end;
gap: 16px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
.slider-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 7px;
color: var(--muted);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.slider-label output {
color: var(--ink);
font-size: 9px;
}
input[type="range"] {
width: 100%;
height: 3px;
margin: 0;
appearance: none;
background: var(--paper-deep);
cursor: pointer;
outline: none;
}
input[type="range"]::-webkit-slider-thumb {
width: 13px;
height: 13px;
appearance: none;
border: 2px solid var(--paper);
border-radius: 0;
background: var(--coral);
box-shadow: 0 0 0 1px var(--ink);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 2px solid var(--paper);
border-radius: 0;
background: var(--coral);
box-shadow: 0 0 0 1px var(--ink);
}
.mapping-note {
max-width: 130px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
text-align: right;
}
.hint {
position: fixed;
z-index: 4;
left: 28px;
bottom: 26px;
max-width: 210px;
color: rgba(23, 50, 74, 0.62);
font-size: 8px;
font-weight: 800;
line-height: 1.6;
pointer-events: none;
}
@media (max-width: 900px) {
.hint {
display: none;
}
.mapping-note {
display: none;
}
.control-row {
grid-template-columns: 1fr 1fr;
}
}
@media (max-width: 620px) {
.topbar {
padding: 16px;
}
.brand-subtitle {
display: none;
}
.readout {
padding: 8px;
}
.readout-label,
.view-button {
display: none;
}
.console {
bottom: 10px;
width: calc(100vw - 20px);
padding: 12px;
}
.console-description {
display: none;
}
.patterns {
gap: 5px;
}
.pattern-button {
justify-content: center;
padding: 7px 4px;
}
.pattern-copy {
display: none;
}
.mini-grid {
width: 32px;
height: 32px;
}
.control-row {
gap: 11px;
}
.console-button {
min-width: 60px;
padding: 7px;
font-size: 8px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D kaleidoscope projection booth"></canvas>
<div class="vignette"></div>
<header class="topbar">
<div class="brand">
<div class="eyebrow">Form studies / Booth No. 08</div>
<h1>Kaleido Projection Booth</h1>
<div class="brand-subtitle">
A small machine for turning quiet grids into spinning ornaments.
</div>
</div>
<div class="readout">
<span class="live-dot"></span>
<div class="readout-copy">
<span class="readout-label">Projection status</span>
<span class="readout-value" id="readoutValue">SOLAR / 0 CELLS</span>
</div>
<button class="view-button" id="resetView" type="button">
RESET VIEW
</button>
</div>
</header>
<section class="console" aria-label="Projection controls">
<div class="console-heading">
<div>
<span class="console-kicker">01 / Choose a seed</span>
<span class="console-description">
Colors carry from the source board into every repeated projection.
</span>
</div>
<div class="console-actions">
<button class="console-button" id="restoreSeed" type="button">
RESTORE
</button>
<button class="console-button primary" id="pauseButton" type="button">
PAUSE
</button>
</div>
</div>
<div class="patterns" id="patternButtons"></div>
<div class="control-row">
<label>
<span class="slider-label">
Repetitions
<output id="repeatOutput">5×</output>
</span>
<input
id="repeatSlider"
type="range"
min="3"
max="8"
step="1"
value="5"
/>
</label>
<label>
<span class="slider-label">
Rotation speed
<output id="speedOutput">0.65×</output>
</span>
<input
id="speedSlider"
type="range"
min="0.15"
max="1.6"
step="0.05"
value="0.65"
/>
</label>
<div class="mapping-note">
Click a board socket to add or remove a bead. Every source color remains visible.
</div>
</div>
</section>
<div class="hint">
Drag to orbit · scroll to zoom · double-click to reset<br />
Click the left seed board to edit the pattern
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// DOM / application state
// ------------------------------------------------------------
const canvas = document.querySelector("#scene");
const readoutValue = document.querySelector("#readoutValue");
const patternButtonsElement = document.querySelector("#patternButtons");
const repeatSlider = document.querySelector("#repeatSlider");
const repeatOutput = document.querySelector("#repeatOutput");
const speedSlider = document.querySelector("#speedSlider");
const speedOutput = document.querySelector("#speedOutput");
const pauseButton = document.querySelector("#pauseButton");
const restoreButton = document.querySelector("#restoreSeed");
const resetViewButton = document.querySelector("#resetView");
const palette = [
"#ef6b52",
"#efba3d",
"#4d948a",
"#7eb5c4",
"#aa89b5"
];
const paletteThree = palette.map(
(color) => new THREE.Color(color).convertSRGBToLinear()
);
const GRID_SIZE = 8;
const gridKey = (x, y) => y * GRID_SIZE + x;
let currentPreset = "solar";
let customPattern = false;
let repetitions = 5;
let rotationSpeed = 0.65;
let paused = false;
let elapsed = 0;
function makeSolar() {
const cells = new Map();
for (let y = 0; y < GRID_SIZE; y++) {
for (let x = 0; x < GRID_SIZE; x++) {
const dx = x - 3.5;
const dy = y - 3.5;
const distance = Math.hypot(dx, dy);
if (distance > 3.55) continue;
let color;
if (distance > 3.05) {
color = 0;
} else if (distance < 0.72) {
color = 1;
} else {
const sector = Math.floor(
(Math.atan2(dy, dx) + Math.PI) / (Math.PI / 4)
);
color = 2 + (sector % 3);
}
cells.set(gridKey(x, y), color);
}
}
return cells;
}
function makeDiamond() {
const cells = new Map();
for (let y = 0; y < GRID_SIZE; y++) {
for (let x = 0; x < GRID_SIZE; x++) {
const dx = Math.abs(x - 3.5);
const dy = Math.abs(y - 3.5);
const distance = dx + dy;
if (distance > 3.8) continue;
let color;
if (distance > 3.15) {
color = 0;
} else if (distance < 0.72) {
color = 1;
} else {
color = 2 + ((x + y) % 3);
}
cells.set(gridKey(x, y), color);
}
}
return cells;
}
function makeTide() {
const cells = new Map();
for (let x = 0; x < GRID_SIZE; x++) {
const center = 3.5 + Math.sin(x * 0.82) * 1.55;
for (let offset = -1; offset <= 1; offset++) {
const y = Math.round(center) + offset;
if (y < 0 || y >= GRID_SIZE) continue;
const color = 2 + ((x + Math.floor((y + 8) / 2)) % 3);
cells.set(gridKey(x, y), color);
}
}
return cells;
}
function makeScatter() {
const positions = [
[0, 2], [1, 2], [1, 3], [2, 4], [0, 5],
[2, 1], [3, 1], [3, 2], [4, 3], [3, 4],
[4, 5], [2, 6], [3, 6], [5, 1], [5, 2],
[6, 3], [5, 4], [6, 4], [7, 5], [5, 6],
[6, 6], [7, 2], [4, 0], [2, 3], [4, 2],
[1, 6], [5, 3], [6, 1], [2, 5], [7, 6]
];
const cells = new Map();
positions.forEach(([x, y], index) => {
cells.set(gridKey(x, y), index % palette.length);
});
return cells;
}
const patterns = {
solar: {
label: "SOLAR",
make: makeSolar
},
diamond: {
label: "DIAMOND",
make: makeDiamond
},
tide: {
label: "TIDE",
make: makeTide
},
scatter: {
label: "SCATTER",
make: makeScatter
}
};
let seedCells = patterns.solar.make();
// ------------------------------------------------------------
// Three.js 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, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#ede9dd");
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 2.05, 0);
const cameraState = {
azimuth: 0.055,
polar: 1.33,
zoom: 1,
fitScale: 1
};
function updateCamera() {
const radius = 12.6 * cameraState.fitScale * cameraState.zoom;
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraTarget.x + radius * sinPolar * Math.sin(cameraState.azimuth),
cameraTarget.y + radius * Math.cos(cameraState.polar),
cameraTarget.z + radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraTarget);
}
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.76,
metalness: 0,
flatShading: true,
...options
});
}
const materials = {
ink: standardMaterial("#17324a"),
inkSoft: standardMaterial("#29465a"),
coral: standardMaterial("#ef6b52"),
gold: standardMaterial("#efba3d", {
roughness: 0.52,
metalness: 0.12
}),
teal: standardMaterial("#4d948a"),
sky: standardMaterial("#7eb5c4"),
cream: standardMaterial("#f7f2e7"),
paper: standardMaterial("#e8e1d2"),
socket: standardMaterial("#c8c5bb", {
roughness: 0.9
})
};
const paletteMaterials = palette.map((color) =>
standardMaterial(color, {
roughness: 0.48,
metalness: 0.06
})
);
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Faceted floor
const floorGeometry = new THREE.PlaneGeometry(18, 12, 9, 6).toNonIndexed();
const floorPositions = floorGeometry.getAttribute("position");
const floorColors = [];
const floorPalette = ["#e7e0d1", "#eae3d5", "#e3ddcf", "#eee7da"];
for (let i = 0; i < floorPositions.count; i += 3) {
const x = (floorPositions.getX(i) + floorPositions.getX(i + 1)) / 2;
const y = (floorPositions.getY(i) + floorPositions.getY(i + 1)) / 2;
const index = Math.abs(Math.floor(x * 1.7 + y * 1.1)) % floorPalette.length;
const color = new THREE.Color(floorPalette[index]);
for (let j = 0; j < 3; j++) {
floorColors.push(color.r, color.g, color.b);
}
}
floorGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(floorColors, 3)
);
floorGeometry.computeVertexNormals();
const floor = new THREE.Mesh(
floorGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.95,
flatShading: true
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.035;
floor.receiveShadow = true;
scene.add(floor);
// Booth frame and back wall
const booth = new THREE.Group();
scene.add(booth);
addBox(
booth,
[11.2, 5.35, 0.16],
[0, 2.64, -1.45],
materials.cream
);
addBox(
booth,
[0.3, 5.65, 0.38],
[-5.6, 2.72, -1.2],
materials.ink
);
addBox(
booth,
[0.3, 5.65, 0.38],
[5.6, 2.72, -1.2],
materials.ink
);
addBox(
booth,
[11.5, 0.3, 0.38],
[0, 5.48, -1.2],
materials.ink
);
addBox(
booth,
[11.35, 0.12, 0.34],
[0, 5.2, -1.0],
materials.coral
);
// Low-poly feet
for (const x of [-5.6, 5.6]) {
addBox(
booth,
[0.9, 0.22, 1.25],
[x, 0.05, -0.78],
materials.gold
);
}
// Lighting
scene.add(new THREE.HemisphereLight("#fff8e8", "#81909a", 2.1));
const keyLight = new THREE.DirectionalLight("#fff2d2", 3.1);
keyLight.position.set(-4.5, 8, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight("#9dc8d5", 1.25);
fillLight.position.set(7, 4, 3);
scene.add(fillLight);
const projectorLight = new THREE.PointLight("#efba3d", 2.2, 8, 2);
projectorLight.position.set(0.35, 0.9, 0.25);
scene.add(projectorLight);
// ------------------------------------------------------------
// Canvas-generated booth signs
// ------------------------------------------------------------
function makeLabel(mainText, subText, accent = "#ef6b52") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 1024;
labelCanvas.height = 220;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 1024, 220);
context.fillStyle = "#f7f2e7";
context.fillRect(0, 0, 1024, 220);
context.strokeStyle = "#17324a";
context.lineWidth = 8;
context.strokeRect(4, 4, 1016, 212);
context.fillStyle = accent;
context.fillRect(4, 4, 34, 212);
context.fillStyle = "#17324a";
context.font = "700 58px Arial, sans-serif";
context.fillText(mainText, 78, 91);
context.fillStyle = "#6e776f";
context.font = "700 27px monospace";
context.fillText(subText, 80, 150);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
});
return new THREE.Sprite(material);
}
const mainSign = makeLabel(
"KALEIDO / PROJECTION BOOTH",
"FORM STUDIES · LOW-POLY ATELIER · No. 08",
"#efba3d"
);
mainSign.position.set(0, 4.82, -0.86);
mainSign.scale.set(4.65, 1, 1);
scene.add(mainSign);
const seedLabel = makeLabel(
"01 SOURCE MATRIX",
"ORIGINAL SEED / EDITABLE SOCKETS",
"#ef6b52"
);
seedLabel.position.set(-3.2, 0.57, 0.18);
seedLabel.scale.set(2.65, 0.57, 1);
scene.add(seedLabel);
const outputLabel = makeLabel(
"02 PROJECTED ORNAMENT",
"RADIAL REPETITION / LIVE ROTATION",
"#4d948a"
);
outputLabel.position.set(3.05, 0.57, 0.18);
outputLabel.scale.set(2.65, 0.57, 1);
scene.add(outputLabel);
// ------------------------------------------------------------
// Seed board
// ------------------------------------------------------------
const boardAnchor = new THREE.Group();
boardAnchor.position.set(-3.2, 2.32, 0);
scene.add(boardAnchor);
addBox(
boardAnchor,
[3.04, 3.04, 0.18],
[0, 0, 0],
materials.inkSoft
);
addBox(
boardAnchor,
[2.84, 2.84, 0.08],
[0, 0, 0.12],
materials.cream
);
const boardFrameParts = [
[[3.13, 0.12, 0.2], [0, 1.53, 0.15]],
[[3.13, 0.12, 0.2], [0, -1.53, 0.15]],
[[0.12, 3.18, 0.2], [-1.53, 0, 0.15]],
[[0.12, 3.18, 0.2], [1.53, 0, 0.15]]
];
boardFrameParts.forEach(([size, position]) => {
addBox(boardAnchor, size, position, materials.coral);
});
const boardGrid = new THREE.Group();
boardAnchor.add(boardGrid);
const socketGeometry = new THREE.CylinderGeometry(
0.105,
0.105,
0.035,
8
);
const beadGeometry = new THREE.IcosahedronGeometry(0.13, 0);
const boardHitMeshes = [];
function rebuildBoard() {
boardGrid.clear();
boardHitMeshes.length = 0;
for (let y = 0; y < GRID_SIZE; y++) {
for (let x = 0; x < GRID_SIZE; x++) {
const cell = gridKey(x, y);
const px = (x - 3.5) * 0.34;
const py = (y - 3.5) * 0.34;
const socket = new THREE.Mesh(socketGeometry, materials.socket);
socket.position.set(px, py, 0.19);
socket.rotation.x = Math.PI / 2;
socket.receiveShadow = true;
socket.userData.cell = cell;
boardGrid.add(socket);
boardHitMeshes.push(socket);
if (seedCells.has(cell)) {
const bead = new THREE.Mesh(
beadGeometry,
paletteMaterials[seedCells.get(cell)]
);
bead.position.set(px, py, 0.28);
bead.rotation.set(
(x * 0.37) % Math.PI,
(y * 0.29) % Math.PI,
((x + y) * 0.19) % Math.PI
);
bead.castShadow = true;
bead.userData.cell = cell;
boardGrid.add(bead);
boardHitMeshes.push(bead);
}
}
}
boardGrid.updateMatrixWorld(true);
updateReadout();
}
// Seed-board support
addBox(
scene,
[0.18, 0.68, 0.18],
[-3.2, 0.42, -0.12],
materials.ink
);
addBox(
scene,
[1.28, 0.22, 0.9],
[-3.2, 0.12, -0.1],
materials.gold
);
// ------------------------------------------------------------
// Projector and projection beam
// ------------------------------------------------------------
const projector = new THREE.Group();
projector.position.set(-0.25, 0.55, 0.2);
scene.add(projector);
addBox(
projector,
[0.78, 0.62, 0.78],
[0, 0, 0],
materials.ink
);
addBox(
projector,
[0.66, 0.16, 0.68],
[0, 0.37, 0],
materials.coral
);
const lens = new THREE.Mesh(
new THREE.CylinderGeometry(0.17, 0.17, 0.18, 10),
materials.gold
);
lens.rotation.z = Math.PI / 2;
lens.position.set(0.47, 0.02, 0);
lens.castShadow = true;
projector.add(lens);
const indicator = new THREE.Mesh(
new THREE.OctahedronGeometry(0.07, 0),
materials.teal
);
indicator.position.set(0.2, 0.47, 0.12);
projector.add(indicator);
addBox(
scene,
[0.72, 0.18, 0.72],
[-0.25, 0.08, 0.2],
materials.inkSoft
);
const beamStart = new THREE.Vector3(0.24, 0.72, 0.18);
const beamEnd = new THREE.Vector3(3.05, 2.25, 0);
const beamDirection = new THREE.Vector3().subVectors(
beamEnd,
beamStart
);
const beamLength = beamDirection.length();
const beamGeometry = new THREE.CylinderGeometry(
1.32,
0.055,
beamLength,
10,
1,
true
);
const beamMaterial = new THREE.MeshBasicMaterial({
color: "#efba3d",
transparent: true,
opacity: 0.085,
depthWrite: false,
side: THREE.DoubleSide
});
const beam = new THREE.Mesh(beamGeometry, beamMaterial);
beam.position.copy(beamStart).add(beamEnd).multiplyScalar(0.5);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
beamDirection.normalize()
);
scene.add(beam);
const beamLineGeometry = new THREE.BufferGeometry().setFromPoints([
beamStart,
beamEnd
]);
const beamLine = new THREE.Line(
beamLineGeometry,
new THREE.LineBasicMaterial({
color: "#d7a52e",
transparent: true,
opacity: 0.42
})
);
scene.add(beamLine);
// Output platform
const outputPedestal = new THREE.Mesh(
new THREE.CylinderGeometry(0.88, 1.04, 0.27, 6),
materials.gold
);
outputPedestal.position.set(3.05, 0.13, 0);
outputPedestal.castShadow = true;
outputPedestal.receiveShadow = true;
scene.add(outputPedestal);
const outputGlow = new THREE.Mesh(
new THREE.CircleGeometry(1.12, 32),
new THREE.MeshBasicMaterial({
color: "#efba3d",
transparent: true,
opacity: 0.12,
depthWrite: false
})
);
outputGlow.rotation.x = -Math.PI / 2;
outputGlow.position.set(3.05, 0.012, 0);
scene.add(outputGlow);
// ------------------------------------------------------------
// Projected ornament
// ------------------------------------------------------------
const ornamentRoot = new THREE.Group();
ornamentRoot.position.copy(beamEnd);
scene.add(ornamentRoot);
const ornamentSpin = new THREE.Group();
ornamentRoot.add(ornamentSpin);
const ornamentBeadMaterial = standardMaterial("#ffffff", {
roughness: 0.45,
metalness: 0.08
});
const coreGeometry = new THREE.IcosahedronGeometry(0.48, 0);
const coreMaterial = standardMaterial("#efba3d", {
roughness: 0.38,
metalness: 0.18,
emissive: "#6d4b0d",
emissiveIntensity: 0.13
});
const haloMaterial = standardMaterial("#4d948a", {
roughness: 0.5,
metalness: 0.12
});
function rebuildOrnament() {
ornamentSpin.clear();
const points = [];
for (const [cell, colorIndex] of seedCells.entries()) {
const x = cell % GRID_SIZE;
const y = Math.floor(cell / GRID_SIZE);
const dx = x - 3.5;
const dy = y - 3.5;
const sourceAngle = Math.atan2(dy, dx);
const normalizedDistance = Math.min(
1,
Math.hypot(dx, dy) / 4.95
);
for (let repetition = 0; repetition < repetitions; repetition++) {
const angle =
sourceAngle +
(repetition * Math.PI * 2) / repetitions;
const radius = 0.52 + normalizedDistance * 1.13;
const position = new THREE.Vector3(
Math.cos(angle) * radius,
Math.sin(angle) * radius * 0.78,
((repetition + 0.5) / repetitions - 0.5) * 0.72 +
Math.sin(angle * 2 + normalizedDistance * 4) * 0.16
);
points.push({
position,
color: colorIndex,
sourceAngle,
scale: 0.78 + normalizedDistance * 0.38
});
}
}
if (points.length) {
const beads = new THREE.InstancedMesh(
beadGeometry,
ornamentBeadMaterial,
points.length
);
const dummy = new THREE.Object3D();
points.forEach((point, index) => {
dummy.position.copy(point.position);
dummy.rotation.set(
point.sourceAngle * 0.5,
point.sourceAngle + index * 0.17,
point.sourceAngle * 0.75
);
dummy.scale.setScalar(point.scale);
dummy.updateMatrix();
beads.setMatrixAt(index, dummy.matrix);
beads.setColorAt(index, paletteThree[point.color]);
});
beads.instanceMatrix.needsUpdate = true;
if (beads.instanceColor) beads.instanceColor.needsUpdate = true;
beads.castShadow = true;
beads.receiveShadow = true;
ornamentSpin.add(beads);
const linePositions = [];
const lineColors = [];
points.forEach((point) => {
linePositions.push(
0, 0, 0,
point.position.x,
point.position.y,
point.position.z
);
const color = paletteThree[point.color];
lineColors.push(
color.r, color.g, color.b,
color.r, color.g, color.b
);
});
const lineGeometry = new THREE.BufferGeometry();
lineGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(linePositions, 3)
);
lineGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(lineColors, 3)
);
const spokes = new THREE.LineSegments(
lineGeometry,
new THREE.LineBasicMaterial({
vertexColors: true,
transparent: true,
opacity: 0.28,
depthWrite: false
})
);
ornamentSpin.add(spokes);
}
const core = new THREE.Mesh(coreGeometry, coreMaterial);
core.castShadow = true;
ornamentSpin.add(core);
const ringA = new THREE.Mesh(
new THREE.TorusGeometry(1.43, 0.027, 4, 32),
haloMaterial
);
ringA.rotation.x = 0.34;
ringA.rotation.y = 0.12;
ornamentSpin.add(ringA);
const ringB = new THREE.Mesh(
new THREE.TorusGeometry(1.1, 0.018, 4, 28),
materials.coral
);
ringB.rotation.x = 1.12;
ringB.rotation.y = 0.45;
ornamentSpin.add(ringB);
const innerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.72, 0.018, 4, 24),
materials.sky
);
innerRing.rotation.x = 0.74;
innerRing.rotation.z = 0.25;
ornamentSpin.add(innerRing);
}
// ------------------------------------------------------------
// UI / pattern previews
// ------------------------------------------------------------
function makePreview(cells) {
const preview = document.createElement("div");
preview.className = "mini-grid";
for (let py = 0; py < 6; py++) {
for (let px = 0; px < 6; px++) {
const sampleX = Math.round((px * 7) / 5);
const sampleY = Math.round((py * 7) / 5);
const cell = gridKey(sampleX, sampleY);
const span = document.createElement("span");
if (cells.has(cell)) {
span.style.background = palette[cells.get(cell)];
}
preview.appendChild(span);
}
}
return preview;
}
const patternButtons = [];
Object.entries(patterns).forEach(([id, pattern]) => {
const button = document.createElement("button");
button.className = "pattern-button";
button.type = "button";
button.dataset.pattern = id;
const cells = pattern.make();
button.appendChild(makePreview(cells));
const copy = document.createElement("span");
copy.className = "pattern-copy";
const name = document.createElement("span");
name.className = "pattern-name";
name.textContent = pattern.label;
const count = document.createElement("span");
count.className = "pattern-count";
count.textContent = `${cells.size} CELLS`;
copy.append(name, count);
button.appendChild(copy);
button.addEventListener("click", () => {
currentPreset = id;
customPattern = false;
seedCells = pattern.make();
rebuildBoard();
rebuildOrnament();
updatePatternSelection();
});
patternButtonsElement.appendChild(button);
patternButtons.push(button);
});
function updatePatternSelection() {
patternButtons.forEach((button) => {
button.classList.toggle(
"active",
!customPattern && button.dataset.pattern === currentPreset
);
});
}
function updateReadout() {
const label = customPattern
? "CUSTOM"
: patterns[currentPreset].label;
readoutValue.textContent =
`${label} / ${seedCells.size} CELLS / ${repetitions}×`;
}
repeatSlider.addEventListener("input", () => {
repetitions = Number(repeatSlider.value);
repeatOutput.textContent = `${repetitions}×`;
rebuildOrnament();
updateReadout();
});
speedSlider.addEventListener("input", () => {
rotationSpeed = Number(speedSlider.value);
speedOutput.textContent = `${rotationSpeed.toFixed(2)}×`;
});
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "RESUME" : "PAUSE";
pauseButton.classList.toggle("primary", !paused);
});
restoreButton.addEventListener("click", () => {
seedCells = patterns[currentPreset].make();
customPattern = false;
rebuildBoard();
rebuildOrnament();
updatePatternSelection();
});
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, reset
// ------------------------------------------------------------
function resetCamera() {
cameraState.azimuth = 0.055;
cameraState.polar = 1.33;
cameraState.zoom = 1;
updateCamera();
}
resetViewButton.addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let activePointer = null;
let pointerStartX = 0;
let pointerStartY = 0;
let lastPointerX = 0;
let lastPointerY = 0;
let dragDistance = 0;
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0 || activePointer !== null) return;
activePointer = event.pointerId;
pointerStartX = lastPointerX = event.clientX;
pointerStartY = lastPointerY = event.clientY;
dragDistance = 0;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (event.pointerId !== activePointer) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
cameraState.azimuth -= deltaX * 0.005;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar + deltaY * 0.004,
0.78,
1.48
);
dragDistance += Math.hypot(deltaX, deltaY);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
});
function editSeedAtPointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(boardHitMeshes, false);
if (!hits.length) return;
const cell = hits[0].object.userData.cell;
if (seedCells.has(cell)) {
seedCells.delete(cell);
} else {
const x = cell % GRID_SIZE;
const y = Math.floor(cell / GRID_SIZE);
seedCells.set(cell, (x * 3 + y * 2) % palette.length);
}
customPattern = true;
rebuildBoard();
rebuildOrnament();
updatePatternSelection();
}
canvas.addEventListener("pointerup", (event) => {
if (event.pointerId !== activePointer) return;
const totalMovement = Math.hypot(
event.clientX - pointerStartX,
event.clientY - pointerStartY
);
if (totalMovement < 6 && dragDistance < 6) {
editSeedAtPointer(event);
}
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
activePointer = null;
});
canvas.addEventListener("pointercancel", () => {
activePointer = null;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * (1 + event.deltaY * 0.001),
0.72,
1.42
);
updateCamera();
},
{ passive: false }
);
// ------------------------------------------------------------
// Resize / render loop
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
camera.aspect = aspect;
camera.updateProjectionMatrix();
cameraState.fitScale = Math.max(1, 1.25 / aspect);
updateCamera();
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
elapsed += delta;
}
ornamentSpin.rotation.y = elapsed * rotationSpeed * 0.48;
ornamentSpin.rotation.z = Math.sin(elapsed * 0.52) * 0.055;
ornamentSpin.rotation.x = Math.sin(elapsed * 0.31) * 0.035;
const ringA = ornamentSpin.children.find(
(child) => child.geometry?.type === "TorusGeometry"
);
if (ringA) {
ringA.rotation.z += delta * rotationSpeed * 0.16;
}
beamMaterial.opacity = 0.075 + Math.sin(elapsed * 2.1) * 0.015;
projectorLight.intensity = 2.1 + Math.sin(elapsed * 2.1) * 0.18;
renderer.render(scene, camera);
}
rebuildBoard();
rebuildOrnament();
updatePatternSelection();
resize();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```