Prompt specification
Build or customize the Three.js 3D scene "All Red Blocks Inside One Ring" 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: All Red Blocks Inside One Ring
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/all-red-blocks-inside-one-ring-x3405
Scene Description Prompt:
Create a standalone stylized scene in one HTML file using Three.js from cdnjs. Arrange blocks differing in shape and color around a ring. Make set membership inspectable and include examples that separate all red blocks from all blocks.
Working Three.js Starter (all-red-blocks-inside-one-ring-x3405):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ring Set Lab — Three.js</title>
<style>
:root {
color-scheme: dark;
--bg: #070b13;
--panel: rgba(13, 20, 33, 0.92);
--panel-solid: #0d1421;
--line: rgba(151, 180, 218, 0.16);
--text: #edf5ff;
--muted: #91a4bc;
--cyan: #59e7ff;
--pink: #ff62ce;
--green: #74f0b4;
--yellow: #ffd166;
--red: #ef476f;
}
* {
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;
}
button,
input {
font: inherit;
}
button:focus-visible,
input:focus-visible,
canvas:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 3px;
}
#viewport {
position: absolute;
inset: 0 408px 0 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 42%, #17243a 0%, #0a101c 45%, #060911 100%);
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
.hero {
position: absolute;
z-index: 3;
top: 28px;
left: 30px;
width: min(480px, calc(100% - 60px));
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 13px;
color: var(--cyan);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 1px;
content: "";
background: var(--cyan);
box-shadow: 0 0 10px var(--cyan);
}
.hero h1 {
margin: 0;
font-size: clamp(34px, 4.3vw, 64px);
font-weight: 720;
letter-spacing: -0.055em;
line-height: 0.98;
}
.hero p {
max-width: 430px;
margin: 17px 0 0;
color: #a6b7cc;
font-size: 14px;
line-height: 1.6;
}
.hero strong {
color: var(--text);
font-weight: 650;
}
.panel {
position: absolute;
z-index: 5;
top: 16px;
right: 16px;
bottom: 16px;
width: 392px;
overflow: auto;
border: 1px solid var(--line);
border-radius: 22px;
background: var(--panel);
box-shadow:
0 24px 80px rgba(0, 0, 0, 0.42),
inset 0 1px rgba(255, 255, 255, 0.035);
backdrop-filter: blur(18px);
scrollbar-color: #34445b transparent;
scrollbar-width: thin;
}
.panel-head {
padding: 24px 24px 19px;
border-bottom: 1px solid var(--line);
}
.panel-kicker {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.universe-pill {
padding: 4px 8px;
border: 1px solid rgba(89, 231, 255, 0.24);
border-radius: 999px;
color: var(--cyan);
background: rgba(89, 231, 255, 0.07);
letter-spacing: 0.08em;
}
.panel h2 {
margin: 0;
font-size: 22px;
font-weight: 680;
letter-spacing: -0.025em;
}
.panel-intro {
margin: 7px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.panel section {
padding: 19px 24px;
border-bottom: 1px solid var(--line);
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 0 12px;
color: #cbd8e8;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.section-title span {
color: #63758d;
font-size: 10px;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: none;
}
.inspector {
display: grid;
grid-template-columns: 46px 1fr;
gap: 12px;
align-items: center;
}
.selected-swatch {
position: relative;
width: 46px;
height: 46px;
border: 1px solid rgba(255, 255, 255, 0.22);
border-radius: 13px;
box-shadow:
inset 0 1px rgba(255, 255, 255, 0.25),
0 8px 20px rgba(0, 0, 0, 0.2);
}
.selected-swatch::after {
position: absolute;
inset: 6px;
border: 1px solid rgba(255, 255, 255, 0.24);
border-radius: 7px;
content: "";
}
.selected-name {
margin-bottom: 3px;
font-size: 15px;
font-weight: 700;
}
.selected-meta {
color: var(--muted);
font-size: 11px;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 12px;
grid-column: 1 / -1;
}
.chip {
padding: 5px 8px;
border: 1px solid #293548;
border-radius: 999px;
color: #708198;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.05em;
}
.chip.on-a {
border-color: rgba(89, 231, 255, 0.55);
color: var(--cyan);
background: rgba(89, 231, 255, 0.09);
}
.chip.on-b {
border-color: rgba(255, 98, 206, 0.55);
color: var(--pink);
background: rgba(255, 98, 206, 0.09);
}
.examples {
display: grid;
gap: 9px;
}
.example {
display: grid;
grid-template-columns: 32px 1fr;
gap: 10px;
width: 100%;
padding: 12px;
border: 1px solid #253247;
border-radius: 13px;
color: var(--text);
text-align: left;
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.example:hover {
transform: translateY(-1px);
border-color: #40536e;
background: rgba(255, 255, 255, 0.045);
}
.example.active {
border-color: rgba(89, 231, 255, 0.58);
background: rgba(89, 231, 255, 0.075);
}
.example-number {
display: grid;
width: 30px;
height: 30px;
place-items: center;
border-radius: 9px;
color: var(--cyan);
background: rgba(89, 231, 255, 0.09);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
}
.example strong {
display: block;
margin-bottom: 3px;
font-size: 12px;
font-weight: 700;
}
.example small {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.example code {
color: #c6d7e9;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
}
.status {
display: grid;
grid-template-columns: 9px 1fr;
gap: 10px;
margin-top: 13px;
padding: 12px;
border: 1px solid rgba(116, 240, 180, 0.24);
border-radius: 12px;
background: rgba(116, 240, 180, 0.055);
}
.status::before {
width: 7px;
height: 7px;
margin-top: 4px;
border-radius: 50%;
content: "";
background: var(--green);
box-shadow: 0 0 11px rgba(116, 240, 180, 0.75);
}
.status.warning {
border-color: rgba(255, 209, 102, 0.25);
background: rgba(255, 209, 102, 0.05);
}
.status.warning::before {
background: var(--yellow);
box-shadow: 0 0 11px rgba(255, 209, 102, 0.7);
}
.status strong {
display: block;
margin-bottom: 4px;
color: var(--green);
font-size: 11px;
}
.status.warning strong {
color: var(--yellow);
}
.status span {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.switch-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
margin-top: 13px;
color: #b7c6d8;
font-size: 11px;
cursor: pointer;
}
.switch {
position: relative;
width: 36px;
height: 20px;
flex: 0 0 auto;
}
.switch input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.switch-track {
position: absolute;
inset: 0;
border: 1px solid #34445b;
border-radius: 999px;
background: #182234;
transition: 150ms ease;
}
.switch-track::after {
position: absolute;
top: 3px;
left: 3px;
width: 12px;
height: 12px;
border-radius: 50%;
content: "";
background: #71839b;
transition: 150ms ease;
}
.switch input:checked + .switch-track {
border-color: rgba(89, 231, 255, 0.65);
background: rgba(89, 231, 255, 0.16);
}
.switch input:checked + .switch-track::after {
transform: translateX(16px);
background: var(--cyan);
box-shadow: 0 0 8px rgba(89, 231, 255, 0.7);
}
.stats {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin-bottom: 12px;
}
.stat {
padding: 9px 8px;
border: 1px solid #253247;
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.stat-label {
display: block;
margin-bottom: 4px;
color: #71839b;
font-size: 9px;
font-weight: 700;
}
.stat-value {
color: var(--text);
font-size: 16px;
font-weight: 720;
font-variant-numeric: tabular-nums;
}
.stat.a .stat-value {
color: var(--cyan);
}
.stat.b .stat-value {
color: var(--pink);
}
.table-wrap {
overflow: auto;
max-height: 306px;
border: 1px solid #253247;
border-radius: 12px;
scrollbar-color: #34445b transparent;
scrollbar-width: thin;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 10px;
}
th {
position: sticky;
z-index: 2;
top: 0;
padding: 9px 8px;
border-bottom: 1px solid #2a374b;
color: #7789a0;
background: #111a29;
font-weight: 700;
letter-spacing: 0.08em;
text-align: left;
}
th:first-child {
padding-left: 11px;
}
td {
padding: 8px;
border-bottom: 1px solid rgba(151, 180, 218, 0.08);
color: #b7c6d8;
}
tbody tr {
cursor: pointer;
transition: background 120ms ease;
}
tbody tr:hover,
tbody tr.selected {
background: rgba(89, 231, 255, 0.055);
}
tbody tr.selected {
box-shadow: inset 2px 0 var(--cyan);
}
td:first-child {
padding-left: 11px;
}
.block-cell {
display: flex;
align-items: center;
gap: 8px;
min-width: 108px;
}
.swatch {
width: 11px;
height: 11px;
flex: 0 0 auto;
border: 1px solid rgba(255, 255, 255, 0.26);
border-radius: 3px;
box-shadow: 0 0 8px color-mix(in srgb, currentColor 30%, transparent);
}
.block-id {
color: #ecf4ff;
font-weight: 750;
}
.shape-name {
color: #6f8199;
font-size: 9px;
}
.membership-cell {
text-align: center;
}
.membership-cell label {
display: inline-grid;
place-items: center;
cursor: pointer;
}
.membership-cell input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.membership-box {
display: grid;
width: 20px;
height: 20px;
place-items: center;
border: 1px solid #34445b;
border-radius: 6px;
color: transparent;
font-size: 12px;
font-weight: 900;
transition: 120ms ease;
}
.membership-cell.a input:checked + .membership-box {
border-color: var(--cyan);
color: #071018;
background: var(--cyan);
box-shadow: 0 0 10px rgba(89, 231, 255, 0.25);
}
.membership-cell.b input:checked + .membership-box {
border-color: var(--pink);
color: #160713;
background: var(--pink);
box-shadow: 0 0 10px rgba(255, 98, 206, 0.25);
}
.formula {
margin-top: 11px;
padding: 11px 12px;
border: 1px solid #253247;
border-radius: 11px;
color: #94a8c1;
background: #0b1220;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
line-height: 1.7;
}
.formula .a-text {
color: var(--cyan);
}
.formula .b-text {
color: var(--pink);
}
.legend {
position: absolute;
z-index: 3;
bottom: 22px;
left: 28px;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: 560px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(151, 180, 218, 0.14);
border-radius: 999px;
color: #93a6be;
background: rgba(8, 13, 23, 0.72);
backdrop-filter: blur(10px);
font-size: 10px;
}
.legend-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 8px currentColor;
}
.legend-dot.pink {
background: var(--pink);
}
.legend-dot.white {
background: #fff;
}
.legend-dot.red {
background: var(--red);
}
.reset-button {
position: absolute;
z-index: 4;
right: 18px;
bottom: 18px;
padding: 8px 11px;
border: 1px solid rgba(151, 180, 218, 0.18);
border-radius: 9px;
color: #aebfd3;
background: rgba(8, 13, 23, 0.8);
cursor: pointer;
font-size: 10px;
}
.reset-button:hover {
border-color: rgba(89, 231, 255, 0.5);
color: var(--cyan);
}
@media (max-width: 900px) {
#viewport {
inset: 0 0 52vh 0;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
height: calc(52vh - 10px);
border-radius: 18px;
}
.hero {
top: 17px;
left: 18px;
width: calc(100% - 36px);
}
.hero h1 {
font-size: 37px;
}
.hero p {
max-width: 350px;
font-size: 12px;
}
.legend,
.reset-button {
display: none;
}
.panel-head,
.panel section {
padding-right: 18px;
padding-left: 18px;
}
}
@media (max-width: 520px) {
.hero p {
display: none;
}
.eyebrow {
margin-bottom: 8px;
font-size: 9px;
}
.hero h1 {
font-size: 31px;
}
}
</style>
</head>
<body>
<main id="viewport" aria-label="Interactive three-dimensional set membership scene"></main>
<header class="hero">
<div class="eyebrow">Ring Set Lab</div>
<h1>One ring.<br />Two clean sets.</h1>
<p>
Inspect membership for every block, then compare a
<strong>color classifier</strong> with a <strong>geometric split</strong>.
Both examples isolate every red block from the complete universe.
</p>
</header>
<aside class="panel" aria-label="Set membership inspector">
<div class="panel-head">
<div class="panel-kicker">
<span>Set membership studio</span>
<span class="universe-pill">U = 12 blocks</span>
</div>
<h2>Inspect the partition</h2>
<p class="panel-intro">
Select a block in the scene or table. A and B may overlap, leave gaps,
or form an exact partition.
</p>
</div>
<section>
<h3 class="section-title">
Selected block
<span>3D + table linked</span>
</h3>
<div class="inspector">
<div id="selectedSwatch" class="selected-swatch"></div>
<div>
<div id="selectedName" class="selected-name"></div>
<div id="selectedMeta" class="selected-meta"></div>
</div>
<div class="chips">
<span id="chipA" class="chip">IN A</span>
<span id="chipB" class="chip">IN B</span>
<span id="chipNeither" class="chip">NEITHER</span>
<span id="chipSide" class="chip">RED SIDE</span>
</div>
</div>
</section>
<section>
<h3 class="section-title">
Separation examples
<span>Click to apply</span>
</h3>
<div class="examples">
<button class="example" type="button" data-example="color">
<span class="example-number">01</span>
<span>
<strong>Color rule</strong>
<small>
<code>isRed(c) → A</code><br />
A contains the 3 red positives; B contains all 9 others.
</small>
</span>
</button>
<button class="example active" type="button" data-example="spatial">
<span class="example-number">02</span>
<span>
<strong>Geometric rule</strong>
<small>
<code>0° ≤ θ ≤ 60° → A</code><br />
A straight chord places every red block on one side.
</small>
</span>
</button>
</div>
<div id="status" class="status" aria-live="polite">
<div>
<strong id="statusTitle"></strong>
<span id="statusText"></span>
</div>
</div>
<label class="switch-row">
<span>Show the verified separator in 3D</span>
<span class="switch">
<input id="separatorToggle" type="checkbox" checked />
<span class="switch-track"></span>
</span>
</label>
</section>
<section>
<h3 class="section-title">
Membership matrix
<span>Click A / B to edit</span>
</h3>
<div class="stats">
<div class="stat a">
<span class="stat-label">|A|</span>
<span id="statA" class="stat-value">0</span>
</div>
<div class="stat b">
<span class="stat-label">|B|</span>
<span id="statB" class="stat-value">0</span>
</div>
<div class="stat">
<span class="stat-label">|A ∩ B|</span>
<span id="statIntersection" class="stat-value">0</span>
</div>
<div class="stat">
<span class="stat-label">|A ∪ B|</span>
<span id="statUnion" class="stat-value">0</span>
</div>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Block</th>
<th>Shape</th>
<th class="membership-cell">A</th>
<th class="membership-cell">B</th>
</tr>
</thead>
<tbody id="membershipRows"></tbody>
</table>
</div>
<div class="formula">
<div><span class="a-text">A</span> = {<span id="formulaA"></span>}</div>
<div><span class="b-text">B</span> = {<span id="formulaB"></span>}</div>
<div>U = {R1, R2, R3, C1, C2, C3, C4, C5, C6, C7, C8, C9}</div>
</div>
</section>
</aside>
<div class="legend" aria-hidden="true">
<div class="legend-item"><span class="legend-dot"></span>Set A</div>
<div class="legend-item"><span class="legend-dot pink"></span>Set B</div>
<div class="legend-item"><span class="legend-dot white"></span>Selected</div>
<div class="legend-item"><span class="legend-dot red"></span>Red block</div>
<div class="legend-item">Drag to orbit · Scroll to zoom</div>
</div>
<button id="resetView" class="reset-button" type="button">Reset camera</button>
<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");
// ------------------------------------------------------------
// Data
// ------------------------------------------------------------
const RED = 0xef476f;
const BLOCKS = [
{ id: "R1", colorName: "Red", hex: RED, shape: "cube", shapeName: "Cube", angle: 0 },
{ id: "R2", colorName: "Red", hex: RED, shape: "cylinder", shapeName: "Cylinder", angle: 30 },
{ id: "R3", colorName: "Red", hex: RED, shape: "sphere", shapeName: "Sphere", angle: 60 },
{ id: "C1", colorName: "Blue", hex: 0x4cc9f0, shape: "octa", shapeName: "Octa", angle: 90 },
{ id: "C2", colorName: "Yellow",hex: 0xffd166, shape: "cone", shapeName: "Cone", angle: 120 },
{ id: "C3", colorName: "Teal", hex: 0x2ec4b6, shape: "torus", shapeName: "Torus", angle: 150 },
{ id: "C4", colorName: "Purple",hex: 0x9b5de5, shape: "cube", shapeName: "Cube", angle: 180 },
{ id: "C5", colorName: "Orange",hex: 0xf8961e, shape: "cylinder",shapeName: "Cylinder", angle: 210 },
{ id: "C6", colorName: "Cyan", hex: 0x00bbf9, shape: "octa", shapeName: "Octa", angle: 240 },
{ id: "C7", colorName: "Green", hex: 0x70e000, shape: "sphere", shapeName: "Sphere", angle: 270 },
{ id: "C8", colorName: "Blue", hex: 0x577590, shape: "cone", shapeName: "Cone", angle: 300 },
{ id: "C9", colorName: "Brown", hex: 0xb08968, shape: "torus", shapeName: "Torus", angle: 330 }
];
const membership = Object.fromEntries(
BLOCKS.map(block => [block.id, { A: false, B: false }])
);
let selectedId = "R1";
let hoveredId = null;
let activeExample = "spatial";
let showSeparator = true;
// ------------------------------------------------------------
// Renderer, camera, and scene
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(viewport.clientWidth, viewport.clientHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"3D ring of blocks. Drag to orbit, scroll to zoom, and click a block to inspect it."
);
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x070b13);
scene.fog = new THREE.FogExp2(0x070b13, 0.028);
const camera = new THREE.PerspectiveCamera(
42,
viewport.clientWidth / viewport.clientHeight,
0.1,
100
);
const world = new THREE.Group();
scene.add(world);
const target = new THREE.Vector3(0, 0.65, 0);
let cameraTheta = 0.58;
let cameraPhi = 1.03;
let cameraRadius = 16.2;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
target.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
target.y + cameraRadius * Math.cos(cameraPhi),
target.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(target);
}
updateCamera();
// Lighting
scene.add(new THREE.HemisphereLight(0xb9ddff, 0x101522, 1.55));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(4, 11, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x39d9ff, 24, 15, 2);
cyanLight.position.set(-6, 4, -3);
scene.add(cyanLight);
const pinkLight = new THREE.PointLight(0xff4fcf, 18, 14, 2);
pinkLight.position.set(6, 3, -5);
scene.add(pinkLight);
// Ground
const ground = new THREE.Mesh(
new THREE.CircleGeometry(9.1, 128),
new THREE.MeshStandardMaterial({
color: 0x0c1421,
roughness: 0.94,
metalness: 0.05
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.025;
ground.receiveShadow = true;
world.add(ground);
const grid = new THREE.GridHelper(16, 16, 0x25354d, 0x172338);
grid.position.y = 0.005;
grid.material.transparent = true;
grid.material.opacity = 0.28;
world.add(grid);
// Concentric ring guides
[4.6, 6.05, 7.1].forEach((radius, index) => {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius, index === 1 ? 0.035 : 0.018, 8, 128),
new THREE.MeshBasicMaterial({
color: index === 1 ? 0x3a6f8f : 0x24354c,
transparent: true,
opacity: index === 1 ? 0.8 : 0.62
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.035;
world.add(ring);
});
// Dashed orbit
const orbitPoints = [];
for (let i = 0; i <= 180; i++) {
const a = THREE.MathUtils.degToRad((i / 180) * 360);
orbitPoints.push(
new THREE.Vector3(
Math.sin(a) * 5.35,
0.08,
Math.cos(a) * 5.35
)
);
}
const orbit = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(orbitPoints),
new THREE.LineDashedMaterial({
color: 0x4c718f,
dashSize: 0.15,
gapSize: 0.11,
transparent: true,
opacity: 0.6
})
);
orbit.computeLineDistances();
world.add(orbit);
// ------------------------------------------------------------
// Text sprites, made without external assets or addons
// ------------------------------------------------------------
function roundedRect(ctx, x, y, w, h, r) {
const radius = Math.min(r, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + w, y, x + w, y + h, radius);
ctx.arcTo(x + w, y + h, x, y + h, radius);
ctx.arcTo(x, y + h, x, y, radius);
ctx.arcTo(x, y, x + w, y, radius);
ctx.closePath();
}
function makeLabel(text, accent = "#59e7ff") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 8, 496, 96, 24);
ctx.fillStyle = "rgba(7, 12, 21, 0.88)";
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = "#eef7ff";
ctx.font = "700 31px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 57);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(1.65, 0.36, 1);
sprite.renderOrder = 10;
return sprite;
}
// ------------------------------------------------------------
// Blocks
// ------------------------------------------------------------
const RING_RADIUS = 5.35;
const pedestalGeometry = new THREE.CylinderGeometry(0.7, 0.76, 0.18, 32);
function shapeFor(block) {
let geometry;
let y;
let top;
switch (block.shape) {
case "cube":
geometry = new THREE.BoxGeometry(1.05, 1.05, 1.05);
y = 0.725;
top = 1.25;
break;
case "sphere":
geometry = new THREE.SphereGeometry(0.6, 32, 22);
y = 0.8;
top = 1.4;
break;
case "cylinder":
geometry = new THREE.CylinderGeometry(0.53, 0.53, 1.15, 28);
y = 0.775;
top = 1.35;
break;
case "cone":
geometry = new THREE.ConeGeometry(0.59, 1.2, 28);
y = 0.8;
top = 1.4;
break;
case "octa":
geometry = new THREE.OctahedronGeometry(0.66, 0);
y = 0.86;
top = 1.52;
break;
case "torus":
default:
geometry = new THREE.TorusGeometry(0.44, 0.16, 18, 36);
y = 0.8;
top = 1.4;
break;
}
return { geometry, y, top };
}
for (const block of BLOCKS) {
const angle = THREE.MathUtils.degToRad(block.angle);
const group = new THREE.Group();
group.position.set(
Math.sin(angle) * RING_RADIUS,
0,
Math.cos(angle) * RING_RADIUS
);
group.userData.blockId = block.id;
world.add(group);
const pedestal = new THREE.Mesh(
pedestalGeometry,
new THREE.MeshStandardMaterial({
color: 0x172233,
roughness: 0.66,
metalness: 0.18
})
);
pedestal.position.y = 0.09;
pedestal.castShadow = true;
pedestal.receiveShadow = true;
pedestal.userData.blockId = block.id;
group.add(pedestal);
const membershipHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.84, 0.043, 12, 48),
new THREE.MeshBasicMaterial({
color: 0x39475a,
transparent: true,
opacity: 0.92
})
);
membershipHalo.rotation.x = Math.PI / 2;
membershipHalo.position.y = 0.22;
membershipHalo.userData.blockId = block.id;
group.add(membershipHalo);
const selectionHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.97, 0.028, 10, 48),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.85
})
);
selectionHalo.rotation.x = Math.PI / 2;
selectionHalo.position.y = 0.24;
selectionHalo.visible = false;
group.add(selectionHalo);
const { geometry, y, top } = shapeFor(block);
const material = new THREE.MeshStandardMaterial({
color: block.hex,
roughness: 0.32,
metalness: 0.13,
emissive: 0x000000,
emissiveIntensity: 0.35
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.y = y;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.blockId = block.id;
if (block.shape === "cube" || block.shape === "octa") {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.22
})
);
mesh.add(edges);
}
group.add(mesh);
const label = makeLabel(`${block.id} / ${block.shapeName.toUpperCase()}`);
label.position.set(0, top + 0.43, 0);
label.userData.blockId = block.id;
group.add(label);
block.group = group;
block.mesh = mesh;
block.material = material;
block.halo = membershipHalo;
block.selection = selectionHalo;
block.label = label;
}
// ------------------------------------------------------------
// Geometric separator
//
// The three red blocks occupy 0°, 30°, and 60°.
// A chord with threshold cos(angle - 30°) > 0.65 puts
// those blocks on one side and every other block on the other.
// ------------------------------------------------------------
const separatorGroup = new THREE.Group();
world.add(separatorGroup);
const separatorTheta = THREE.MathUtils.degToRad(30);
const separatorNormal = new THREE.Vector3(
Math.sin(separatorTheta),
0,
Math.cos(separatorTheta)
);
const normalizedChordDistance = 0.65;
const chordDistance = normalizedChordDistance * RING_RADIUS;
const halfChord = Math.sqrt(
RING_RADIUS * RING_RADIUS - chordDistance * chordDistance
);
const tangent = new THREE.Vector3(
Math.cos(separatorTheta),
0,
-Math.sin(separatorTheta)
);
const chordCenter = separatorNormal.clone().multiplyScalar(chordDistance);
const separatorBar = new THREE.Mesh(
new THREE.BoxGeometry(halfChord * 2, 0.035, 0.065),
new THREE.MeshBasicMaterial({
color: 0x63eaff,
transparent: true,
opacity: 0.95
})
);
separatorBar.position.copy(chordCenter);
separatorBar.position.y = 0.105;
separatorBar.rotation.y = separatorTheta;
separatorGroup.add(separatorBar);
const separatorCurtain = new THREE.Mesh(
new THREE.PlaneGeometry(halfChord * 2, 3.4),
new THREE.MeshBasicMaterial({
color: 0x48dfff,
transparent: true,
opacity: 0.065,
side: THREE.DoubleSide,
depthWrite: false
})
);
separatorCurtain.position.copy(chordCenter);
separatorCurtain.position.y = 1.7;
separatorCurtain.rotation.y = separatorTheta;
separatorGroup.add(separatorCurtain);
const separatorLabel = makeLabel("LINEAR SEPARATOR", "#59e7ff");
separatorLabel.position.copy(chordCenter);
separatorLabel.position.y = 3.45;
separatorLabel.scale.set(2.0, 0.44, 1);
separatorGroup.add(separatorLabel);
function isOnPositiveSide(block) {
const angle = THREE.MathUtils.degToRad(block.angle);
const projection =
Math.sin(angle) * separatorNormal.x +
Math.cos(angle) * separatorNormal.z;
return projection > normalizedChordDistance;
}
// ------------------------------------------------------------
// UI creation and synchronization
// ------------------------------------------------------------
const rowsElement = document.getElementById("membershipRows");
for (const block of BLOCKS) {
const row = document.createElement("tr");
row.dataset.id = block.id;
row.innerHTML = `
<td>
<div class="block-cell">
<span class="swatch" style="background:#${block.hex.toString(16).padStart(6, "0")};color:#${block.hex.toString(16).padStart(6, "0")}"></span>
<span class="block-id">${block.id}</span>
</div>
</td>
<td><span class="shape-name">${block.shapeName}</span></td>
<td class="membership-cell">
<label>
<input type="checkbox" data-set="A" data-id="${block.id}" aria-label="${block.id} in set A" />
<span class="membership-box">✓</span>
</label>
</td>
<td class="membership-cell">
<label>
<input type="checkbox" data-set="B" data-id="${block.id}" aria-label="${block.id} in set B" />
<span class="membership-box">✓</span>
</label>
</td>
`;
row.addEventListener("click", event => {
if (event.target.closest("input")) return;
selectBlock(block.id);
});
row.querySelectorAll("input").forEach(input => {
input.addEventListener("click", event => {
event.stopPropagation();
});
input.addEventListener("change", () => {
membership[block.id][input.dataset.set] = input.checked;
activeExample = "manual";
updateExampleButtons();
updateAll();
});
});
rowsElement.appendChild(row);
}
function selectBlock(id) {
selectedId = id;
updateAll();
}
function applyExample(type) {
activeExample = type;
for (const block of BLOCKS) {
if (type === "color") {
membership[block.id].A = block.colorName === "Red";
membership[block.id].B = !membership[block.id].A;
} else if (type === "spatial") {
const inRedArc = block.angle >= 0 && block.angle <= 60;
membership[block.id].A = inRedArc;
membership[block.id].B = !inRedArc;
}
}
updateExampleButtons();
updateAll();
}
function updateExampleButtons() {
document.querySelectorAll("[data-example]").forEach(button => {
button.classList.toggle("active", button.dataset.example === activeExample);
});
}
function updateRows() {
for (const block of BLOCKS) {
const row = rowsElement.querySelector(`tr[data-id="${block.id}"]`);
row.classList.toggle("selected", block.id === selectedId);
row.querySelector('input[data-set="A"]').checked = membership[block.id].A;
row.querySelector('input[data-set="B"]').checked = membership[block.id].B;
}
}
function updateInspector() {
const block = BLOCKS.find(item => item.id === selectedId);
const color = `#${block.hex.toString(16).padStart(6, "0")}`;
document.getElementById("selectedSwatch").style.background = color;
document.getElementById("selectedName").textContent =
`${block.id} · ${block.colorName} ${block.shapeName.toLowerCase()}`;
document.getElementById("selectedMeta").textContent =
`${block.angle}° around the ring · ${isOnPositiveSide(block) ? "positive side" : "negative side"} of the chord`;
const chipA = document.getElementById("chipA");
const chipB = document.getElementById("chipB");
const chipNeither = document.getElementById("chipNeither");
const chipSide = document.getElementById("chipSide");
chipA.className = `chip${membership[block.id].A ? " on-a" : ""}`;
chipB.className = `chip${membership[block.id].B ? " on-b" : ""}`;
chipNeither.className = `chip${
!membership[block.id].A && !membership[block.id].B ? " on-a" : ""
}`;
chipSide.textContent = isOnPositiveSide(block) ? "RED SIDE" : "OTHER SIDE";
chipSide.className = `chip${
isOnPositiveSide(block) ? " on-a" : " on-b"
}`;
}
function updateStats() {
const a = BLOCKS.filter(block => membership[block.id].A).map(block => block.id);
const b = BLOCKS.filter(block => membership[block.id].B).map(block => block.id);
const intersection = a.filter(id => b.includes(id));
const union = [...new Set([...a, ...b])];
document.getElementById("statA").textContent = a.length;
document.getElementById("statB").textContent = b.length;
document.getElementById("statIntersection").textContent = intersection.length;
document.getElementById("statUnion").textContent = union.length;
document.getElementById("formulaA").textContent = a.join(", ") || "∅";
document.getElementById("formulaB").textContent = b.join(", ") || "∅";
const positiveOK =
BLOCKS.filter(block => block.colorName === "Red")
.every(block => membership[block.id].A && !membership[block.id].B);
const negativeOK =
BLOCKS.filter(block => block.colorName !== "Red")
.every(block => membership[block.id].B && !membership[block.id].A);
const isExact = positiveOK && negativeOK && union.length === BLOCKS.length;
const spatialCorrect = BLOCKS.every(block => {
const side = isOnPositiveSide(block);
return block.colorName === "Red" ? side : !side;
});
const status = document.getElementById("status");
const title = document.getElementById("statusTitle");
const text = document.getElementById("statusText");
if (isExact) {
status.classList.remove("warning");
title.textContent = "Exact red / non-red separation";
if (activeExample === "color") {
text.textContent =
"3/3 red blocks are in A only, and 9/9 other blocks are in B only. The visible chord independently verifies the same partition.";
} else if (activeExample === "spatial") {
text.textContent =
"The chord is verified: 3/3 red blocks are on one side, and all 9 non-red blocks are on the other.";
} else {
text.textContent =
"Your manual memberships form the same exact partition. The geometric chord remains valid.";
}
} else {
status.classList.add("warning");
title.textContent = "Custom membership — not an exact split";
const redSummary = positiveOK
? "All red blocks are isolated in A."
: "At least one red block is missing from A or also appears in B.";
const otherSummary = negativeOK
? "All non-red blocks are isolated in B."
: "At least one non-red block is missing from B or also appears in A.";
text.textContent = `${redSummary} ${otherSummary}`;
}
separatorGroup.visible = showSeparator && isExact && spatialCorrect;
return { isExact, a, b, intersection, union, spatialCorrect };
}
function updateSceneMembership() {
for (const block of BLOCKS) {
const inA = membership[block.id].A;
const inB = membership[block.id].B;
let color = 0x39475a;
if (inA && inB) color = 0xffffff;
else if (inA) color = 0x59e7ff;
else if (inB) color = 0xff62ce;
block.halo.material.color.setHex(color);
block.selection.visible = block.id === selectedId;
if (block.id === selectedId) {
block.material.emissive.setHex(0x28536a);
block.material.emissiveIntensity = 0.55;
} else if (block.id === hoveredId) {
block.material.emissive.setHex(0x183440);
block.material.emissiveIntensity = 0.42;
} else {
block.material.emissive.setHex(0x000000);
block.material.emissiveIntensity = 0;
}
}
}
function updateAll() {
updateRows();
updateInspector();
updateStats();
updateSceneMembership();
}
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, and keyboard support
// ------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const canvas = renderer.domElement;
let pointerDown = false;
let pointerMoved = false;
let pointerStartX = 0;
let pointerStartY = 0;
let previousX = 0;
let previousY = 0;
function blockIdFromObject(object) {
let current = object;
while (current) {
if (current.userData && current.userData.blockId) {
return current.userData.blockId;
}
current = current.parent;
}
return null;
}
function pickBlock(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(world.children, true);
for (const hit of hits) {
if (!hit.object.isMesh) continue;
const id = blockIdFromObject(hit.object);
if (id) return id;
}
return null;
}
canvas.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
pointerDown = true;
pointerMoved = false;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (pointerDown) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (
Math.hypot(
event.clientX - pointerStartX,
event.clientY - pointerStartY
) > 4
) {
pointerMoved = true;
}
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(cameraPhi + dy * 0.005, 0.34, 1.46);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
} else {
const id = pickBlock(event);
if (id !== hoveredId) {
hoveredId = id;
canvas.style.cursor = id ? "pointer" : "grab";
updateSceneMembership();
}
}
});
canvas.addEventListener("pointerup", event => {
if (pointerDown && !pointerMoved) {
const id = pickBlock(event);
if (id) selectBlock(id);
}
pointerDown = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
pointerMoved = false;
});
canvas.addEventListener("pointerleave", () => {
if (!pointerDown && hoveredId !== null) {
hoveredId = null;
canvas.style.cursor = "grab";
updateSceneMembership();
}
});
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
10.5,
24
);
updateCamera();
},
{ passive: false }
);
function resetCamera() {
cameraTheta = 0.58;
cameraPhi = 1.03;
cameraRadius = 16.2;
updateCamera();
}
document.getElementById("resetView").addEventListener("click", resetCamera);
canvas.addEventListener("keydown", event => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraTheta += 0.08;
break;
case "ArrowRight":
cameraTheta -= 0.08;
break;
case "ArrowUp":
cameraPhi = Math.max(0.34, cameraPhi - 0.06);
break;
case "ArrowDown":
cameraPhi = Math.min(1.46, cameraPhi + 0.06);
break;
case "+":
case "=":
cameraRadius = Math.max(10.5, cameraRadius - 0.8);
break;
case "-":
case "_":
cameraRadius = Math.min(24, cameraRadius + 0.8);
break;
case "r":
case "R":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
// ------------------------------------------------------------
// Interface events
// ------------------------------------------------------------
document.querySelectorAll("[data-example]").forEach(button => {
button.addEventListener("click", () => {
applyExample(button.dataset.example);
});
});
document.getElementById("separatorToggle").addEventListener("change", event => {
showSeparator = event.target.checked;
updateAll();
});
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
renderer.setAnimationLoop(time => {
const selected = BLOCKS.find(block => block.id === selectedId);
if (selected) {
selected.selection.material.opacity =
0.68 + Math.sin(time * 0.0032) * 0.2;
}
renderer.render(scene, camera);
});
// Start with the geometric example active.
applyExample("spatial");
updateAll();
</script>
</body>
</html>
```