Prompt specification
Build or customize the Three.js 3D scene "Bit Tiles With a Parity Slot" 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: Bit Tiles With a Parity Slot
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/bit-tiles-with-a-parity-slot-x3373
Scene Description Prompt:
Stylized binary tiles with a parity tile and visible parity calculation under a stated rule. One HTML file using Three.js from cdnjs.
Working Three.js Starter (bit-tiles-with-a-parity-slot-x3373):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Binary Parity</title>
<style>
:root {
--bg: #070b16;
--panel: rgba(15, 22, 40, 0.88);
--panel-border: rgba(148, 163, 184, 0.16);
--text: #e8eefc;
--muted: #8d9ab7;
--cyan: #55d6d2;
--orange: #ff906f;
--gold: #ffc36a;
--violet: #9b8cff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body {
background:
radial-gradient(circle at 72% 18%, rgba(73, 86, 170, 0.15), transparent 34%),
radial-gradient(circle at 20% 80%, rgba(25, 158, 164, 0.09), transparent 30%),
var(--bg);
}
.app {
display: grid;
grid-template-columns: minmax(0, 1fr) 360px;
height: 100%;
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
}
.stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
.stage canvas:active {
cursor: grabbing;
}
.topbar {
position: absolute;
z-index: 2;
top: 25px;
left: 30px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 9px;
color: var(--cyan);
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 42px);
font-weight: 750;
letter-spacing: -0.05em;
}
.subtitle {
margin-top: 10px;
color: var(--muted);
font-size: 13px;
}
.stage-hint {
position: absolute;
z-index: 2;
right: 28px;
bottom: 25px;
color: rgba(205, 215, 239, 0.58);
font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.05em;
text-align: right;
pointer-events: none;
}
.panel {
position: relative;
z-index: 3;
height: 100%;
overflow-y: auto;
padding: 28px 24px;
border-left: 1px solid var(--panel-border);
background:
linear-gradient(180deg, rgba(20, 29, 51, 0.76), rgba(10, 15, 29, 0.94));
box-shadow: -20px 0 60px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(18px);
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 22px;
}
.panel-title h2 {
margin: 0;
font-size: 13px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
}
.card {
margin-bottom: 16px;
padding: 17px;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: rgba(7, 12, 25, 0.46);
}
.card-label {
margin-bottom: 11px;
color: var(--muted);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.rule {
color: #d9e1f6;
font-size: 14px;
line-height: 1.55;
}
.rule strong {
color: var(--gold);
}
.count-row {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 13px;
}
.count-row span {
color: var(--muted);
font-size: 12px;
}
.count-row strong {
color: var(--cyan);
font: 700 27px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.xor-expression {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 5px;
min-height: 82px;
padding: 12px;
border: 1px solid rgba(148, 163, 184, 0.1);
border-radius: 11px;
background: rgba(0, 0, 0, 0.16);
font: 700 14px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.xor-expression .operator {
color: #596985;
font-style: normal;
}
.xor-expression .bit {
display: inline-grid;
width: 23px;
height: 23px;
place-items: center;
border-radius: 6px;
font-size: 12px;
}
.bit.zero {
color: var(--cyan);
background: rgba(85, 214, 210, 0.12);
}
.bit.one {
color: var(--orange);
background: rgba(255, 144, 111, 0.15);
}
.xor-expression .answer {
margin-left: 3px;
color: var(--gold);
font-size: 19px;
}
.matrix {
display: grid;
gap: 6px;
margin-top: 16px;
}
.matrix-row {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
}
.matrix-bit {
display: grid;
height: 29px;
place-items: center;
border: 1px solid rgba(148, 163, 184, 0.1);
border-radius: 7px;
font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
transition: background 180ms ease, color 180ms ease;
}
.matrix-bit.zero {
color: var(--cyan);
background: rgba(85, 214, 210, 0.08);
}
.matrix-bit.one {
color: var(--orange);
background: rgba(255, 144, 111, 0.12);
}
.result {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 17px;
padding-top: 15px;
border-top: 1px solid rgba(148, 163, 184, 0.12);
}
.result span {
color: var(--muted);
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
}
.result strong {
color: var(--gold);
font: 800 35px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
text-shadow: 0 0 18px rgba(255, 195, 106, 0.28);
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 9px 15px;
color: var(--muted);
font-size: 12px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.legend-swatch {
width: 9px;
height: 9px;
border-radius: 3px;
}
.legend-swatch.zero {
background: var(--cyan);
box-shadow: 0 0 9px rgba(85, 214, 210, 0.65);
}
.legend-swatch.one {
background: var(--orange);
box-shadow: 0 0 9px rgba(255, 144, 111, 0.65);
}
.legend-swatch.parity {
background: var(--gold);
box-shadow: 0 0 9px rgba(255, 195, 106, 0.65);
}
.buttons {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
button {
min-height: 38px;
border: 1px solid rgba(148, 163, 184, 0.18);
border-radius: 10px;
padding: 0 8px;
color: #dce5fb;
background: rgba(255, 255, 255, 0.045);
font: 700 11px/1 ui-sans-serif, system-ui, sans-serif;
cursor: pointer;
transition: border-color 160ms ease, background 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(85, 214, 210, 0.55);
background: rgba(85, 214, 210, 0.08);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.note {
margin: 14px 2px 0;
color: #65728e;
font-size: 11px;
line-height: 1.55;
}
@media (max-width: 820px) {
body {
overflow: auto;
}
.app {
grid-template-columns: 1fr;
grid-template-rows: minmax(470px, 65vh) auto;
height: auto;
min-height: 100%;
}
.panel {
height: auto;
border-top: 1px solid var(--panel-border);
border-left: 0;
}
.topbar {
top: 20px;
left: 20px;
}
.stage-hint {
right: 18px;
bottom: 15px;
}
}
</style>
</head>
<body>
<div class="app">
<main class="stage" id="stage">
<div class="topbar">
<div class="eyebrow">Logic / 01</div>
<h1>Binary Parity</h1>
<div class="subtitle">A live XOR calculation across sixteen binary tiles.</div>
</div>
<div class="stage-hint">
Click a tile to flip it<br />
Drag to orbit · Scroll to zoom
</div>
</main>
<aside class="panel">
<div class="panel-title">
<h2>Parity Monitor</h2>
<span class="live-dot" aria-hidden="true"></span>
</div>
<section class="card">
<div class="card-label">Stated Rule</div>
<div class="rule">
The parity tile is <strong>1</strong> when the number of <strong>1s</strong>
is odd, and <strong>0</strong> when it is even.
</div>
</section>
<section class="card">
<div class="card-label">Visible Calculation</div>
<div class="count-row">
<span>Number of 1s</span>
<strong id="onesCount">8</strong>
</div>
<div class="xor-expression" id="xorExpression" aria-live="polite"></div>
<div class="matrix" id="matrix" aria-label="Current binary tile values"></div>
<div class="result">
<span>PARITY</span>
<strong id="parityValue">0</strong>
</div>
</section>
<section class="card">
<div class="card-label">Legend</div>
<div class="legend">
<div class="legend-item">
<span class="legend-swatch zero"></span>
<span>Binary 0</span>
</div>
<div class="legend-item">
<span class="legend-swatch one"></span>
<span>Binary 1</span>
</div>
<div class="legend-item">
<span class="legend-swatch parity"></span>
<span>Parity output</span>
</div>
</div>
</section>
<section class="card">
<div class="card-label">Controls</div>
<div class="buttons">
<button id="resetButton">Reset</button>
<button id="randomButton">Random</button>
<button id="clearButton">Clear</button>
</div>
</section>
<p class="note">
The displayed XOR expression evaluates every tile from left to right,
top to bottom. XOR returns 1 for an odd number of 1s.
</p>
</aside>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x070b16, 0.035);
const camera = new THREE.PerspectiveCamera(
38,
stage.clientWidth / stage.clientHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(stage.clientWidth, stage.clientHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D grid of binary tiles"
);
stage.appendChild(renderer.domElement);
scene.add(new THREE.HemisphereLight(0xa9c8ff, 0x080b16, 1.65));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(3, 9, 6);
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 = -8;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x38d9dc, 18, 12, 2);
cyanLight.position.set(-5, 2.5, -3);
scene.add(cyanLight);
const violetLight = new THREE.PointLight(0x7367ff, 16, 12, 2);
violetLight.position.set(5, 3, 4);
scene.add(violetLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x080d19,
roughness: 0.82,
metalness: 0.25
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.13;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x23304c, 0x121a2d);
grid.position.y = -0.105;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
const platform = new THREE.Mesh(
new THREE.BoxGeometry(6.7, 0.34, 6.7),
new THREE.MeshStandardMaterial({
color: 0x10192c,
roughness: 0.38,
metalness: 0.68
})
);
platform.position.y = 0.08;
platform.castShadow = true;
platform.receiveShadow = true;
scene.add(platform);
const platformEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(platform.geometry),
new THREE.LineBasicMaterial({
color: 0x415274,
transparent: true,
opacity: 0.7
})
);
platformEdges.position.copy(platform.position);
scene.add(platformEdges);
const tileGeometry = new THREE.BoxGeometry(1.26, 0.3, 1.26);
const tileEdgeGeometry = new THREE.EdgesGeometry(tileGeometry);
const labelGeometry = new THREE.PlaneGeometry(1.02, 1.02);
const tiles = [];
const tilePickables = [];
const tileStates = [
1, 0, 1, 0,
0, 1, 0, 1,
1, 1, 0, 0,
0, 0, 1, 1
];
function createTextTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
return { canvas, context, texture };
}
function drawTileDigit(textState, textureData) {
const { context, texture } = textureData;
context.clearRect(0, 0, 256, 256);
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "800 146px ui-monospace, SFMono-Regular, Menlo, monospace";
context.shadowColor =
textState === 1 ? "rgba(255, 144, 111, 0.35)" : "rgba(85, 214, 210, 0.35)";
context.shadowBlur = 22;
context.fillStyle = textState === 1 ? "#ffad91" : "#79e8e4";
context.fillText(String(textState), 128, 137);
context.shadowBlur = 0;
texture.needsUpdate = true;
}
function updateTileVisual(tile) {
const value = tileStates[tile.index];
const active = value === 1;
tile.material.color.setHex(active ? 0xb9543d : 0x153a52);
tile.material.emissive.setHex(active ? 0x542016 : 0x062430);
tile.material.emissiveIntensity = active ? 0.8 : 0.52;
tile.edgeMaterial.color.setHex(active ? 0xffa083 : 0x4ad7d5);
tile.edgeMaterial.opacity = active ? 0.85 : 0.52;
drawTileDigit(value, tile.labelTexture);
}
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 4; col++) {
const index = row * 4 + col;
const group = new THREE.Group();
group.position.set(
(col - 1.5) * 1.45,
0.43,
(row - 1.5) * 1.45
);
const material = new THREE.MeshStandardMaterial({
color: 0x153a52,
emissive: 0x062430,
emissiveIntensity: 0.52,
roughness: 0.3,
metalness: 0.48
});
const mesh = new THREE.Mesh(tileGeometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.index = index;
group.add(mesh);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x4ad7d5,
transparent: true,
opacity: 0.52
});
const edges = new THREE.LineSegments(tileEdgeGeometry, edgeMaterial);
group.add(edges);
const labelTexture = createTextTexture();
const labelMaterial = new THREE.MeshBasicMaterial({
map: labelTexture.texture,
transparent: true,
depthWrite: false,
toneMapped: false
});
const label = new THREE.Mesh(labelGeometry, labelMaterial);
label.rotation.x = -Math.PI / 2;
label.position.y = 0.158;
group.add(label);
scene.add(group);
tilePickables.push(mesh);
const tile = {
index,
group,
mesh,
material,
edgeMaterial,
labelTexture
};
tiles.push(tile);
updateTileVisual(tile);
}
}
const parityGroup = new THREE.Group();
parityGroup.position.set(4.45, 0.47, 0);
const parityMaterial = new THREE.MeshStandardMaterial({
color: 0x6a55c9,
emissive: 0x30205f,
emissiveIntensity: 1,
roughness: 0.26,
metalness: 0.58
});
const parityMesh = new THREE.Mesh(
new THREE.BoxGeometry(1.65, 0.34, 1.65),
parityMaterial
);
parityMesh.castShadow = true;
parityMesh.receiveShadow = true;
parityGroup.add(parityMesh);
const parityEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(parityMesh.geometry),
new THREE.LineBasicMaterial({
color: 0xffc36a,
transparent: true,
opacity: 0.9
})
);
parityGroup.add(parityEdges);
const parityRing = new THREE.Mesh(
new THREE.TorusGeometry(1.12, 0.025, 10, 80),
new THREE.MeshBasicMaterial({
color: 0xffc36a,
transparent: true,
opacity: 0.75,
toneMapped: false
})
);
parityRing.rotation.x = Math.PI / 2;
parityRing.position.y = 0.02;
parityGroup.add(parityRing);
const parityLabelTexture = createTextTexture();
const parityLabel = new THREE.Mesh(
new THREE.PlaneGeometry(1.36, 1.36),
new THREE.MeshBasicMaterial({
map: parityLabelTexture.texture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
parityLabel.rotation.x = -Math.PI / 2;
parityLabel.position.y = 0.178;
parityGroup.add(parityLabel);
scene.add(parityGroup);
function drawParityLabel(value) {
const { context, texture } = parityLabelTexture;
context.clearRect(0, 0, 256, 256);
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "700 25px ui-monospace, SFMono-Regular, Menlo, monospace";
context.fillStyle = "#d3bd91";
context.fillText("PARITY", 128, 62);
context.font = "800 124px ui-monospace, SFMono-Regular, Menlo, monospace";
context.shadowColor = "rgba(255, 195, 106, 0.45)";
context.shadowBlur = 24;
context.fillStyle = "#ffd18b";
context.fillText(String(value), 128, 150);
context.shadowBlur = 0;
texture.needsUpdate = true;
}
drawParityLabel(0);
const matrixElement = document.getElementById("matrix");
const matrixBits = [];
for (let row = 0; row < 4; row++) {
const rowElement = document.createElement("div");
rowElement.className = "matrix-row";
for (let col = 0; col < 4; col++) {
const bitElement = document.createElement("span");
bitElement.className = "matrix-bit";
rowElement.appendChild(bitElement);
matrixBits.push(bitElement);
}
matrixElement.appendChild(rowElement);
}
const xorExpressionElement = document.getElementById("xorExpression");
const onesCountElement = document.getElementById("onesCount");
const parityValueElement = document.getElementById("parityValue");
function updateCalculation() {
const ones = tileStates.reduce((sum, value) => sum + value, 0);
const parity = ones % 2;
onesCountElement.textContent = ones;
parityValueElement.textContent = parity;
xorExpressionElement.replaceChildren();
tileStates.forEach((value, index) => {
if (index > 0) {
const operator = document.createElement("i");
operator.className = "operator";
operator.textContent = "⊕";
xorExpressionElement.appendChild(operator);
}
const bit = document.createElement("span");
bit.className = `bit ${value ? "one" : "zero"}`;
bit.textContent = value;
xorExpressionElement.appendChild(bit);
});
const equals = document.createElement("i");
equals.className = "operator";
equals.textContent = "=";
xorExpressionElement.appendChild(equals);
const answer = document.createElement("strong");
answer.className = "answer";
answer.textContent = parity;
xorExpressionElement.appendChild(answer);
tileStates.forEach((value, index) => {
matrixBits[index].className = `matrix-bit ${value ? "one" : "zero"}`;
matrixBits[index].textContent = value;
updateTileVisual(tiles[index]);
});
parityMaterial.color.setHex(parity ? 0xc68735 : 0x6a55c9);
parityMaterial.emissive.setHex(parity ? 0x6a4317 : 0x30205f);
parityMaterial.emissiveIntensity = parity ? 1.25 : 1;
drawParityLabel(parity);
}
updateCalculation();
let yaw = 0.57;
let pitch = 0.68;
let radius = 11.7;
const cameraTarget = new THREE.Vector3(0.1, 0.45, 0);
function updateCamera() {
const horizontalRadius = radius * Math.cos(pitch);
camera.position.set(
cameraTarget.x + horizontalRadius * Math.sin(yaw),
cameraTarget.y + radius * Math.sin(pitch),
cameraTarget.z + horizontalRadius * Math.cos(yaw)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let hoveredIndex = -1;
let dragging = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
function getPointer(event) {
const bounds = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - bounds.left) / bounds.width) * 2 - 1;
pointer.y = -((event.clientY - bounds.top) / bounds.height) * 2 + 1;
}
function findTile(event) {
getPointer(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(tilePickables, false);
return intersections.length ? intersections[0].object.userData.index : -1;
}
function setHover(index) {
if (hoveredIndex === index) return;
if (hoveredIndex >= 0) {
tiles[hoveredIndex].group.scale.setScalar(1);
}
hoveredIndex = index;
if (hoveredIndex >= 0) {
tiles[hoveredIndex].group.scale.setScalar(1.055);
renderer.domElement.style.cursor = "pointer";
} else {
renderer.domElement.style.cursor = dragging ? "grabbing" : "grab";
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerMoved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
if (Math.abs(deltaX) + Math.abs(deltaY) > 2) {
pointerMoved = true;
}
yaw -= deltaX * 0.008;
pitch += deltaY * 0.006;
pitch = THREE.MathUtils.clamp(pitch, 0.28, 1.22);
radius = THREE.MathUtils.clamp(radius, 7.4, 17);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
} else {
setHover(findTile(event));
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
const wasDragging = dragging;
dragging = false;
renderer.domElement.releasePointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grab";
if (wasDragging && !pointerMoved) {
const index = findTile(event);
if (index >= 0) {
tileStates[index] = tileStates[index] ? 0 : 1;
updateCalculation();
}
}
setHover(findTile(event));
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!dragging) setHover(-1);
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius + event.deltaY * 0.008,
7.4,
17
);
updateCamera();
},
{ passive: false }
);
document.getElementById("resetButton").addEventListener("click", () => {
tileStates.splice(
0,
tileStates.length,
1, 0, 1, 0,
0, 1, 0, 1,
1, 1, 0, 0,
0, 0, 1, 1
);
updateCalculation();
});
document.getElementById("clearButton").addEventListener("click", () => {
tileStates.fill(0);
updateCalculation();
});
document.getElementById("randomButton").addEventListener("click", () => {
for (let index = 0; index < tileStates.length; index++) {
tileStates[index] = Math.random() > 0.5 ? 1 : 0;
}
updateCalculation();
});
const resizeObserver = new ResizeObserver(() => {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
});
resizeObserver.observe(stage);
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
parityRing.rotation.z = elapsed * 0.35;
parityRing.material.opacity = 0.62 + Math.sin(elapsed * 2.2) * 0.14;
parityGroup.position.y = 0.47 + Math.sin(elapsed * 1.35) * 0.035;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```