Prompt specification
Build or customize the Three.js 3D scene "Equal-part fraction disk collection" 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: Equal-part fraction disk collection
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/equal-part-fraction-disk-collection-x1693
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring fractions represented by equal partitions. Create disks divided into halves, thirds, and quarters with clearly equal sectors; highlight selected parts and keep the chosen whole visible in every display. Low-poly.
Working Three.js Starter (equal-part-fraction-disk-collection-x1693):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Equal Parts — Interactive Fraction Disks</title>
<style>
:root {
color-scheme: dark;
--bg: #09111b;
--panel: #111c29;
--panel-light: #172434;
--text: #f2f6fb;
--muted: #9baabd;
--line: rgba(255, 255, 255, 0.1);
}
* {
box-sizing: border-box;
}
body {
min-height: 100vh;
margin: 0;
background:
radial-gradient(circle at 12% 0%, rgba(48, 116, 151, 0.2), transparent 35rem),
radial-gradient(circle at 90% 15%, rgba(88, 65, 135, 0.16), transparent 32rem),
var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
.page {
width: min(1240px, calc(100% - 32px));
margin: 0 auto;
padding: 46px 0 36px;
}
header {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 28px;
margin-bottom: 30px;
}
.eyebrow {
margin: 0 0 10px;
color: #7dd3fc;
font-size: 0.75rem;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(2.2rem, 5vw, 4.4rem);
line-height: 0.98;
letter-spacing: -0.055em;
}
.intro {
max-width: 580px;
margin: 16px 0 0;
color: var(--muted);
font-size: 1rem;
line-height: 1.65;
}
.reset-button {
flex: 0 0 auto;
border: 1px solid var(--line);
border-radius: 999px;
padding: 11px 17px;
background: rgba(255, 255, 255, 0.045);
color: var(--text);
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.reset-button:hover {
border-color: rgba(255, 255, 255, 0.25);
background: rgba(255, 255, 255, 0.09);
transform: translateY(-1px);
}
.legend {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px 22px;
margin-bottom: 22px;
padding: 13px 17px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(12, 21, 32, 0.68);
color: var(--muted);
font-size: 0.82rem;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 16px;
height: 16px;
border-radius: 4px;
}
.swatch.selected {
background: #f6c85f;
box-shadow: 0 0 18px rgba(246, 200, 95, 0.25);
}
.swatch.unselected {
border: 1px solid #43566b;
background: #26384a;
}
.swatch.whole {
border: 2px solid #91a4b7;
border-radius: 50%;
background: transparent;
}
.cards {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 20px;
}
.fraction-card {
--accent: #ff6b6b;
position: relative;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 24px;
background:
linear-gradient(145deg, rgba(255, 255, 255, 0.035), transparent 45%),
var(--panel);
box-shadow: 0 22px 60px rgba(0, 0, 0, 0.18);
}
.fraction-card::before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 3px;
background: var(--accent);
content: "";
opacity: 0.9;
}
.card-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 22px 22px 0;
}
.card-heading h2 {
margin: 0;
font-size: 1.08rem;
letter-spacing: -0.02em;
}
.equal-parts {
border: 1px solid var(--line);
border-radius: 999px;
padding: 6px 10px;
color: var(--muted);
font-size: 0.68rem;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.stage {
position: relative;
height: clamp(270px, 29vw, 350px);
margin: 12px 12px 0;
overflow: hidden;
border-radius: 18px;
background:
radial-gradient(circle at 50% 47%, rgba(255, 255, 255, 0.07), transparent 48%),
linear-gradient(180deg, #132130, #0c1622);
}
.stage::after {
position: absolute;
inset: 0;
border: 1px solid rgba(255, 255, 255, 0.055);
border-radius: inherit;
pointer-events: none;
content: "";
}
.stage canvas {
position: absolute;
inset: 0;
z-index: 1;
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
.stage canvas:active {
cursor: grabbing;
}
.stage-label,
.stage-number {
position: absolute;
z-index: 2;
top: 15px;
color: #8194a8;
font-size: 0.62rem;
font-weight: 800;
letter-spacing: 0.14em;
pointer-events: none;
}
.stage-label {
left: 16px;
}
.stage-number {
right: 16px;
color: var(--accent);
}
.fraction-info {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 20px 22px 14px;
}
.fraction {
display: flex;
align-items: baseline;
color: var(--accent);
font-size: 2.9rem;
font-weight: 780;
line-height: 1;
letter-spacing: -0.07em;
}
.fraction .slash {
margin: 0 0.08em;
color: #718398;
font-weight: 400;
}
.fraction .denominator {
color: #dbe4ed;
}
.selection-copy {
max-width: 170px;
color: var(--muted);
font-size: 0.79rem;
line-height: 1.45;
text-align: right;
}
.stepper {
display: grid;
grid-template-columns: 42px 1fr 42px;
align-items: center;
gap: 8px;
margin: 0 22px;
padding: 9px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(4, 10, 17, 0.28);
}
.stepper button {
width: 42px;
height: 42px;
border: 0;
border-radius: 10px;
background: var(--panel-light);
color: var(--text);
font-size: 1.3rem;
cursor: pointer;
transition:
background 140ms ease,
opacity 140ms ease;
}
.stepper button:hover:not(:disabled) {
background: var(--accent);
color: #111820;
}
.stepper button:disabled {
cursor: not-allowed;
opacity: 0.3;
}
.stepper-center {
text-align: center;
}
.stepper-center strong {
display: block;
font-size: 0.92rem;
}
.stepper-center small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 0.64rem;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.card-hint {
margin: 0;
padding: 13px 22px 20px;
color: #73869a;
font-size: 0.7rem;
line-height: 1.45;
text-align: center;
}
footer {
padding: 23px 4px 0;
color: #718398;
font-size: 0.74rem;
text-align: center;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 860px) {
.cards {
grid-template-columns: 1fr;
}
.stage {
height: min(78vw, 380px);
}
header {
align-items: flex-start;
flex-direction: column;
}
.page {
padding-top: 30px;
}
}
@media (max-width: 480px) {
.page {
width: min(100% - 20px, 1240px);
}
.legend {
align-items: flex-start;
flex-direction: column;
}
.card-heading,
.fraction-info {
padding-left: 17px;
padding-right: 17px;
}
.stepper {
margin-right: 17px;
margin-left: 17px;
}
}
</style>
</head>
<body>
<main class="page">
<header>
<div>
<p class="eyebrow">Interactive fraction models</p>
<h1>Equal Parts</h1>
<p class="intro">
Explore halves, thirds, and quarters. Highlight any equal sectors while
the complete disk and its boundary remain visible.
</p>
</div>
<button class="reset-button" id="reset-all" type="button">
Reset all
</button>
</header>
<div class="legend" aria-label="Diagram legend">
<span class="legend-item">
<span class="swatch selected"></span>
Highlighted part
</span>
<span class="legend-item">
<span class="swatch unselected"></span>
Remaining equal part
</span>
<span class="legend-item">
<span class="swatch whole"></span>
Whole-disk boundary
</span>
</div>
<section class="cards" aria-label="Fraction disks">
<article
class="fraction-card"
data-denominator="2"
data-name="halves"
data-accent="#ff6b6b"
style="--accent: #ff6b6b"
>
<div class="card-heading">
<h2>Halves</h2>
<span class="equal-parts">2 equal sectors</span>
</div>
<div class="stage">
<span class="stage-label">Whole visible</span>
<span class="stage-number">01</span>
</div>
<div class="fraction-info">
<div class="fraction" aria-live="polite">
<span class="numerator">1</span>
<span class="slash">/</span>
<span class="denominator">2</span>
</div>
<div class="selection-copy">
1 of 2 equal parts highlighted
</div>
</div>
<div class="stepper">
<button type="button" data-action="down" aria-label="Highlight fewer parts">
−
</button>
<div class="stepper-center">
<strong class="highlight-count">1</strong>
<small>highlighted</small>
</div>
<button type="button" data-action="up" aria-label="Highlight more parts">
+
</button>
</div>
<p class="card-hint">Click a sector to toggle it · Drag to orbit · Scroll to zoom</p>
</article>
<article
class="fraction-card"
data-denominator="3"
data-name="thirds"
data-accent="#f6c85f"
style="--accent: #f6c85f"
>
<div class="card-heading">
<h2>Thirds</h2>
<span class="equal-parts">3 equal sectors</span>
</div>
<div class="stage">
<span class="stage-label">Whole visible</span>
<span class="stage-number">02</span>
</div>
<div class="fraction-info">
<div class="fraction" aria-live="polite">
<span class="numerator">1</span>
<span class="slash">/</span>
<span class="denominator">3</span>
</div>
<div class="selection-copy">
1 of 3 equal parts highlighted
</div>
</div>
<div class="stepper">
<button type="button" data-action="down" aria-label="Highlight fewer parts">
−
</button>
<div class="stepper-center">
<strong class="highlight-count">1</strong>
<small>highlighted</small>
</div>
<button type="button" data-action="up" aria-label="Highlight more parts">
+
</button>
</div>
<p class="card-hint">Click a sector to toggle it · Drag to orbit · Scroll to zoom</p>
</article>
<article
class="fraction-card"
data-denominator="4"
data-name="quarters"
data-accent="#4fd1c5"
style="--accent: #4fd1c5"
>
<div class="card-heading">
<h2>Quarters</h2>
<span class="equal-parts">4 equal sectors</span>
</div>
<div class="stage">
<span class="stage-label">Whole visible</span>
<span class="stage-number">03</span>
</div>
<div class="fraction-info">
<div class="fraction" aria-live="polite">
<span class="numerator">1</span>
<span class="slash">/</span>
<span class="denominator">4</span>
</div>
<div class="selection-copy">
1 of 4 equal parts highlighted
</div>
</div>
<div class="stepper">
<button type="button" data-action="down" aria-label="Highlight fewer parts">
−
</button>
<div class="stepper-center">
<strong class="highlight-count">1</strong>
<small>highlighted</small>
</div>
<button type="button" data-action="up" aria-label="Highlight more parts">
+
</button>
</div>
<p class="card-hint">Click a sector to toggle it · Drag to orbit · Scroll to zoom</p>
</article>
</section>
<footer>
Every sector has the same angle and area within its disk.
<span class="sr-only" id="announcement" aria-live="polite"></span>
</footer>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const cards = [...document.querySelectorAll(".fraction-card")];
const announcement = document.getElementById("announcement");
const views = [];
const unselectedFront = new THREE.Color("#26384a");
const unselectedSide = new THREE.Color("#111c28");
const wholeRimColor = new THREE.Color("#91a4b7");
function createSectorGeometry(radius, startAngle, endAngle, curveSegments) {
const shape = new THREE.Shape();
shape.moveTo(0, 0);
shape.lineTo(
Math.cos(startAngle) * radius,
Math.sin(startAngle) * radius
);
shape.absarc(0, 0, radius, startAngle, endAngle, true);
shape.lineTo(0, 0);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.14,
steps: 1,
bevelEnabled: false,
curveSegments
});
geometry.computeVertexNormals();
return geometry;
}
function createView(card) {
const denominator = Number(card.dataset.denominator);
const accent = new THREE.Color(card.dataset.accent);
const stage = card.querySelector(".stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const canvas = renderer.domElement;
canvas.setAttribute("role", "img");
canvas.setAttribute(
"aria-label",
`Interactive disk divided into ${denominator} equal sectors`
);
canvas.tabIndex = 0;
stage.appendChild(canvas);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(35, 1, 0.1, 100);
const hemisphere = new THREE.HemisphereLight(0xe2f2ff, 0x172231, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(-3.5, 4.5, 6);
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x88bfff, 1.15);
fillLight.position.set(4, -2, 4);
scene.add(fillLight);
const diskGroup = new THREE.Group();
scene.add(diskGroup);
// Soft colored halo behind each disk.
const halo = new THREE.Mesh(
new THREE.CircleGeometry(1.25, 32),
new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0.075,
depthWrite: false
})
);
halo.position.z = -0.17;
diskGroup.add(halo);
// Low-poly backing and pedestal keep the complete whole visible.
const pedestalGeometry = new THREE.CylinderGeometry(
1.09,
1.09,
0.16,
24,
1,
false
);
pedestalGeometry.rotateX(Math.PI / 2);
const pedestal = new THREE.Mesh(
pedestalGeometry,
new THREE.MeshStandardMaterial({
color: 0x172331,
roughness: 0.9,
metalness: 0.04,
flatShading: true
})
);
pedestal.position.z = -0.17;
diskGroup.add(pedestal);
const baseGeometry = new THREE.CylinderGeometry(
1.015,
1.015,
0.11,
32,
1,
false
);
baseGeometry.rotateX(Math.PI / 2);
const base = new THREE.Mesh(
baseGeometry,
new THREE.MeshStandardMaterial({
color: 0x0e1823,
roughness: 0.86,
metalness: 0.08,
flatShading: true
})
);
base.position.z = -0.065;
diskGroup.add(base);
const sectors = [];
const step = (Math.PI * 2) / denominator;
const top = Math.PI / 2;
const curveSegments = denominator * 12;
for (let index = 0; index < denominator; index++) {
const startAngle = top - index * step;
const endAngle = top - (index + 1) * step;
const frontMaterial = new THREE.MeshStandardMaterial({
color: unselectedFront,
emissive: 0x000000,
emissiveIntensity: 0,
roughness: 0.66,
metalness: 0.04,
flatShading: true
});
const sideMaterial = new THREE.MeshStandardMaterial({
color: unselectedSide,
roughness: 0.82,
metalness: 0.03,
flatShading: true
});
const sector = new THREE.Mesh(
createSectorGeometry(1, startAngle, endAngle, curveSegments),
[frontMaterial, sideMaterial]
);
sector.position.z = 0;
sector.userData.index = index;
sector.userData.frontMaterial = frontMaterial;
sector.userData.sideMaterial = sideMaterial;
diskGroup.add(sector);
sectors.push(sector);
}
// Permanent radial separators make the equal divisions explicit.
const separatorMaterial = new THREE.LineBasicMaterial({
color: 0x09121c,
transparent: true,
opacity: 0.9
});
for (let index = 0; index < denominator; index++) {
const angle = top - index * step;
const separatorGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0, 0.151),
new THREE.Vector3(
Math.cos(angle) * 0.985,
Math.sin(angle) * 0.985,
0.151
)
]);
diskGroup.add(
new THREE.Line(separatorGeometry, separatorMaterial)
);
}
// The outer ring is never hidden, even when every part is selected.
const wholeRim = new THREE.Mesh(
new THREE.TorusGeometry(1.015, 0.027, 4, 32),
new THREE.MeshStandardMaterial({
color: wholeRimColor,
roughness: 0.55,
metalness: 0.16,
flatShading: true
})
);
wholeRim.position.z = 0.145;
diskGroup.add(wholeRim);
const centerDot = new THREE.Mesh(
new THREE.CircleGeometry(0.032, 12),
new THREE.MeshBasicMaterial({ color: 0x09121c })
);
centerDot.position.z = 0.154;
diskGroup.add(centerDot);
const selection = new Set([0]);
const controls = {
radius: 5.35,
theta: -0.1,
phi: 1.38,
dragging: false,
moved: false,
pointerId: null,
lastX: 0,
lastY: 0,
apply() {
const sinPhi = Math.sin(this.phi);
camera.position.set(
this.radius * sinPhi * Math.sin(this.theta),
this.radius * Math.cos(this.phi),
this.radius * sinPhi * Math.cos(this.theta)
);
camera.lookAt(0, 0, 0);
},
reset() {
this.radius = 5.35;
this.theta = -0.1;
this.phi = 1.38;
this.apply();
}
};
controls.apply();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pickSector(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 intersections = raycaster.intersectObjects(sectors, false);
if (intersections.length) {
const index = intersections[0].object.userData.index;
if (selection.has(index)) {
if (selection.size === 1) {
announcement.textContent =
"At least one equal part must remain highlighted.";
return;
}
selection.delete(index);
} else {
selection.add(index);
}
updateSelection();
}
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
controls.dragging = true;
controls.moved = false;
controls.pointerId = event.pointerId;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging || event.pointerId !== controls.pointerId) {
return;
}
const deltaX = event.clientX - controls.lastX;
const deltaY = event.clientY - controls.lastY;
if (Math.abs(deltaX) + Math.abs(deltaY) > 2) {
controls.moved = true;
}
controls.theta = THREE.MathUtils.clamp(
controls.theta - deltaX * 0.005,
-0.58,
0.58
);
controls.phi = THREE.MathUtils.clamp(
controls.phi + deltaY * 0.004,
1.02,
1.76
);
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.apply();
});
canvas.addEventListener("pointerup", (event) => {
if (event.pointerId !== controls.pointerId) return;
controls.dragging = false;
if (!controls.moved) {
pickSector(event);
}
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
controls.dragging = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
4.45,
7.1
);
controls.apply();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
controls.reset();
});
function resize() {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
const numerator = card.querySelector(".numerator");
const countLabel = card.querySelector(".highlight-count");
const selectionCopy = card.querySelector(".selection-copy");
const downButton = card.querySelector('[data-action="down"]');
const upButton = card.querySelector('[data-action="up"]');
function updateSelection() {
const selected = selection.size;
sectors.forEach((sector, index) => {
const isSelected = selection.has(index);
const front = sector.userData.frontMaterial;
const side = sector.userData.sideMaterial;
if (isSelected) {
front.color.copy(accent);
front.emissive.copy(accent);
front.emissiveIntensity = 0.13;
side.color.copy(accent).multiplyScalar(0.58);
} else {
front.color.copy(unselectedFront);
front.emissive.set(0x000000);
front.emissiveIntensity = 0;
side.color.copy(unselectedSide);
}
});
numerator.textContent = selected;
countLabel.textContent = selected;
selectionCopy.textContent =
`${selected} of ${denominator} equal parts highlighted`;
downButton.disabled = selected <= 1;
upButton.disabled = selected >= denominator;
announcement.textContent =
`${selected} of ${denominator} equal parts highlighted.`;
}
function selectCount(count) {
selection.clear();
for (let index = 0; index < count; index++) {
selection.add(index);
}
updateSelection();
}
downButton.addEventListener("click", () => {
selectCount(Math.max(1, selection.size - 1));
});
upButton.addEventListener("click", () => {
selectCount(Math.min(denominator, selection.size + 1));
});
canvas.addEventListener("keydown", (event) => {
if (event.key === "ArrowRight" || event.key === "ArrowUp") {
event.preventDefault();
selectCount(Math.min(denominator, selection.size + 1));
}
if (event.key === "ArrowLeft" || event.key === "ArrowDown") {
event.preventDefault();
selectCount(Math.max(1, selection.size - 1));
}
if (event.key === "Home") {
controls.reset();
}
});
updateSelection();
return {
card,
renderer,
scene,
camera,
controls,
halo,
accent,
resetSelection() {
selection.clear();
selection.add(0);
updateSelection();
}
};
}
cards.forEach((card) => {
views.push(createView(card));
});
document.getElementById("reset-all").addEventListener("click", () => {
views.forEach((view) => {
view.resetSelection();
view.controls.reset();
});
});
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
for (const view of views) {
view.halo.material.opacity =
0.055 + Math.sin(elapsed * 1.5 + view.accent.r) * 0.012;
view.renderer.render(view.scene, view.camera);
}
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```