Prompt specification
Build or customize the Three.js 3D scene "Reflection and rotation symmetry specimens" 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: Reflection and rotation symmetry specimens
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/reflection-and-rotation-symmetry-specimens-x1737
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: reflection and rotation symmetry specimens. Arrange a butterfly-like planar figure and a pinwheel with marked candidate axes; distinguish reflection symmetry from rotational symmetry using visibly asymmetric details where needed. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (reflection-and-rotation-symmetry-specimens-x1737):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Symmetry Specimens — Three.js</title>
<style>
:root {
color-scheme: dark;
--bg: #08111f;
--panel: rgba(10, 20, 35, 0.82);
--border: rgba(166, 196, 224, 0.2);
--text: #eef7ff;
--muted: #9bb0c8;
--mint: #66f2c2;
--coral: #ff6b78;
--cyan: #55cfff;
--gold: #ffd166;
}
* { 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;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
header {
position: absolute;
top: 22px;
left: 26px;
max-width: 520px;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.55);
}
.eyebrow {
margin-bottom: 7px;
color: var(--mint);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3.1vw, 42px);
line-height: 1.02;
letter-spacing: -0.045em;
}
header p {
max-width: 470px;
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.controls {
position: absolute;
top: 22px;
right: 22px;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 9px;
pointer-events: auto;
}
.control-row {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
}
button {
appearance: none;
border: 1px solid var(--border);
border-radius: 999px;
padding: 9px 13px;
background: rgba(13, 26, 43, 0.78);
color: #dceaff;
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.055em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
border-color 160ms ease,
color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(102, 242, 194, 0.62);
color: white;
transform: translateY(-1px);
}
button.active {
border-color: var(--mint);
background: rgba(102, 242, 194, 0.13);
color: var(--mint);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 3px;
}
.check {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 12px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(13, 26, 43, 0.78);
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
backdrop-filter: blur(12px);
cursor: pointer;
user-select: none;
}
.check input {
width: 14px;
height: 14px;
accent-color: var(--coral);
}
.legend {
position: absolute;
left: 22px;
bottom: 22px;
width: min(390px, calc(100vw - 44px));
padding: 15px 17px;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(16px);
}
.legend-title {
margin-bottom: 10px;
color: #dbeaff;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 14px;
color: var(--muted);
font-size: 11px;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
position: relative;
display: inline-block;
width: 27px;
height: 10px;
flex: 0 0 auto;
}
.swatch.mirror::before {
content: "";
position: absolute;
top: 4px;
left: 0;
width: 27px;
height: 2px;
background: var(--mint);
box-shadow: 0 0 9px rgba(102, 242, 194, 0.7);
}
.swatch.candidate::before {
content: "";
position: absolute;
top: 4px;
left: 0;
width: 27px;
height: 2px;
background: repeating-linear-gradient(
90deg,
var(--coral) 0 5px,
transparent 5px 9px
);
}
.swatch.rotation {
border: 2px solid var(--cyan);
border-radius: 50%;
}
.swatch.rotation::after {
content: "";
position: absolute;
top: -4px;
right: -1px;
width: 0;
height: 0;
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
border-left: 6px solid var(--cyan);
transform: rotate(-24deg);
}
.legend p {
margin: 11px 0 0;
padding-top: 10px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: #8fa6be;
font-size: 10.5px;
line-height: 1.5;
}
.instructions {
position: absolute;
right: 22px;
bottom: 22px;
color: rgba(196, 216, 235, 0.72);
font-size: 10.5px;
letter-spacing: 0.025em;
text-align: right;
text-shadow: 0 2px 12px #000;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #08111f;
color: var(--mint);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
header {
top: 16px;
left: 16px;
max-width: calc(100vw - 32px);
}
header p { display: none; }
.controls {
top: auto;
right: 14px;
bottom: 14px;
align-items: stretch;
}
.control-row {
justify-content: flex-end;
}
button {
padding: 8px 10px;
font-size: 9px;
}
.legend {
left: 14px;
bottom: 102px;
width: min(330px, calc(100vw - 28px));
}
.legend-grid {
grid-template-columns: 1fr;
}
.legend p { display: none; }
.instructions { display: none; }
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive Three.js symmetry specimen display"></main>
<div class="hud">
<header>
<div class="eyebrow">Geometry Lab / Specimen 02</div>
<h1>Two kinds of symmetry.</h1>
<p>
The butterfly folds across one verified mirror line. The pinwheel turns by
90° about its center, but its curled blades cannot be folded onto themselves.
</p>
</header>
<nav class="controls" aria-label="Scene controls">
<div class="control-row" id="viewButtons">
<button class="active" data-view="all">Overview</button>
<button data-view="reflection">Reflection</button>
<button data-view="rotation">Rotation</button>
</div>
<div class="control-row">
<button id="spinButton">Turn pinwheel 90°</button>
<button id="orbitButton">Auto orbit</button>
</div>
<label class="check">
<input id="axisToggle" type="checkbox" checked />
Show candidate axes
</label>
</nav>
<section class="legend" aria-label="Symmetry legend">
<div class="legend-title">Reading the specimens</div>
<div class="legend-grid">
<div class="legend-item">
<span class="swatch mirror"></span>
Verified mirror axis
</div>
<div class="legend-item">
<span class="swatch candidate"></span>
Rejected mirror candidate
</div>
<div class="legend-item">
<span class="swatch rotation"></span>
Rotation about center
</div>
<div class="legend-item">
<span class="swatch" style="border-left:3px solid #ffb84d"></span>
Repeated chiral detail
</div>
</div>
<p>
The mint tabs on all four pinwheel blades point the same way. A turn carries
each tab onto the next; a reflection would reverse their handedness.
</p>
</section>
<div class="instructions">
Drag to orbit · Shift/right-drag to pan · Scroll to zoom
</div>
</div>
<div id="loading">Preparing specimens…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneRoot = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.setAttribute(
"aria-label",
"A low-poly butterfly and pinwheel demonstrating reflection and rotational symmetry"
);
sceneRoot.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08111f);
scene.fog = new THREE.Fog(0x08111f, 16, 35);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const Y_AXIS = new THREE.Vector3(0, 1, 0);
const candidateAxes = [];
const palette = {
board: 0x101d2f,
boardEdge: 0x263a51,
pedestal: 0x17283c,
mint: 0x66f2c2,
coral: 0xff6b78,
cyan: 0x55cfff,
gold: 0xffd166,
ink: 0x07101c
};
function standard(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.04,
flatShading: true,
...extra
});
}
const boardMaterial = standard(palette.board, { roughness: 0.92 });
const edgeMaterial = standard(palette.boardEdge, {
roughness: 0.56,
metalness: 0.28
});
const pedestalMaterial = standard(palette.pedestal, { roughness: 0.82 });
const mintMaterial = standard(palette.mint, {
emissive: 0x0d5947,
emissiveIntensity: 0.48,
roughness: 0.52
});
const coralMaterial = standard(palette.coral, {
emissive: 0x5b101a,
emissiveIntensity: 0.38
});
const cyanMaterial = standard(palette.cyan, {
emissive: 0x0b4f6b,
emissiveIntensity: 0.55
});
const bodyMaterial = standard(0x17243b, {
roughness: 0.62,
metalness: 0.12
});
const hemisphere = new THREE.HemisphereLight(0xb8ddff, 0x172033, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe7c7, 3.1);
keyLight.position.set(-4.5, 9, 8);
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 = -6;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x5fcfff, 1.6);
rimLight.position.set(7, 4, -5);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xff9866, 18, 13, 2);
warmFill.position.set(-5, 2.5, 5);
scene.add(warmFill);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
standard(0x0a1422, { roughness: 0.96 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.48;
floor.receiveShadow = true;
scene.add(floor);
const wall = new THREE.Mesh(
new THREE.PlaneGeometry(34, 15),
standard(0x0b1726, { roughness: 1 })
);
wall.position.set(0, 4.4, -4.1);
wall.receiveShadow = true;
scene.add(wall);
const grid = new THREE.GridHelper(30, 30, 0x28415b, 0x182b3e);
grid.position.y = -0.465;
grid.material.transparent = true;
grid.material.opacity = 0.23;
scene.add(grid);
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeLabel(text, options = {}) {
const {
color = "#eef7ff",
background = "rgba(7, 16, 28, 0.86)",
border = "rgba(157, 190, 219, 0.25)",
width = 2.8,
fontSize = 66
} = options;
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 220;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 8, 8, 1008, 204, 24);
ctx.fillStyle = background;
ctx.fill();
ctx.strokeStyle = border;
ctx.lineWidth = 4;
ctx.stroke();
let size = fontSize;
ctx.font = `800 ${size}px system-ui, sans-serif`;
while (ctx.measureText(text).width > 930 && size > 32) {
size -= 2;
ctx.font = `800 ${size}px system-ui, sans-serif`;
}
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = color;
ctx.fillText(text, 512, 112);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 220 / 1024, 1);
sprite.renderOrder = 30;
return sprite;
}
function coloredShape(points, colors, material) {
const shape = new THREE.Shape();
points.forEach((point, index) => {
if (index === 0) shape.moveTo(point[0], point[1]);
else shape.lineTo(point[0], point[1]);
});
shape.closePath();
let geometry = new THREE.ShapeGeometry(shape);
if (geometry.index) {
const nonIndexed = geometry.toNonIndexed();
geometry.dispose();
geometry = nonIndexed;
}
const count = geometry.attributes.position.count;
const colorValues = new Float32Array(count * 3);
const colorList = colors.map(c => new THREE.Color(c));
for (let vertex = 0; vertex < count; vertex += 3) {
const color = colorList[(vertex / 3) % colorList.length];
for (let j = 0; j < 3 && vertex + j < count; j++) {
const offset = (vertex + j) * 3;
colorValues[offset] = color.r;
colorValues[offset + 1] = color.g;
colorValues[offset + 2] = color.b;
}
}
geometry.setAttribute("color", new THREE.BufferAttribute(colorValues, 3));
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
material || new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.76,
metalness: 0.03,
flatShading: true,
side: THREE.DoubleSide
})
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function cylinderBetween(parent, from, to, radius, material, radialSegments = 6) {
const direction = new THREE.Vector3().subVectors(to, from);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
1,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(from).add(to).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.normalize());
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function addCone(parent, position, direction, radius, height, material) {
const mesh = new THREE.Mesh(
new THREE.ConeGeometry(radius, height, 6),
material
);
mesh.position.copy(position);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.clone().normalize());
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function solidAxis(parent, from, to, material) {
const group = new THREE.Group();
cylinderBetween(group, from, to, 0.017, material, 7);
const direction = new THREE.Vector3().subVectors(to, from).normalize();
addCone(group, to, direction, 0.052, 0.14, material);
addCone(group, from, direction.clone().negate(), 0.052, 0.14, material);
parent.add(group);
return group;
}
function dashedAxis(parent, from, to, material, segments = 11) {
const group = new THREE.Group();
const start = new THREE.Vector3(...from);
const end = new THREE.Vector3(...to);
const direction = end.clone().sub(start);
const total = direction.length();
const step = total / segments;
for (let i = 0; i < segments; i++) {
const a = start.clone().addScaledVector(direction, i * step);
const b = start.clone().addScaledVector(direction, (i + 0.58) * step);
cylinderBetween(group, a, b, 0.011, material, 5);
}
for (const endpoint of [start, end]) {
const diagonalA = endpoint.clone().add(new THREE.Vector3(-0.065, -0.065, 0));
const diagonalB = endpoint.clone().add(new THREE.Vector3(0.065, 0.065, 0));
const diagonalC = endpoint.clone().add(new THREE.Vector3(-0.065, 0.065, 0));
const diagonalD = endpoint.clone().add(new THREE.Vector3(0.065, -0.065, 0));
cylinderBetween(group, diagonalA, diagonalB, 0.012, material, 4);
cylinderBetween(group, diagonalC, diagonalD, 0.012, material, 4);
}
group.userData.candidateAxis = true;
candidateAxes.push(group);
parent.add(group);
return group;
}
function addMount(parent, x, index) {
const pedestal = new THREE.Mesh(
new THREE.BoxGeometry(4.0, 0.46, 1.8),
pedestalMaterial
);
pedestal.position.set(x, -0.25, -0.08);
pedestal.castShadow = true;
pedestal.receiveShadow = true;
scene.add(pedestal);
const top = new THREE.Mesh(
new THREE.BoxGeometry(4.15, 0.12, 1.94),
edgeMaterial
);
top.position.set(x, 0.01, -0.08);
top.castShadow = true;
top.receiveShadow = true;
scene.add(top);
const badge = makeLabel(index === 0 ? "BILATERAL / k = 1" : "CYCLE / k = 4", {
width: 2.1,
fontSize: 55,
color: index === 0 ? "#66f2c2" : "#55cfff",
border: index === 0
? "rgba(102, 242, 194, 0.45)"
: "rgba(85, 207, 255, 0.45)"
});
badge.position.set(x, -0.24, 0.85);
scene.add(badge);
}
function makePanel(x, index) {
const group = new THREE.Group();
group.position.set(x, 2.05, 0);
scene.add(group);
const board = new THREE.Mesh(
new THREE.BoxGeometry(4.15, 4.55, 0.16),
boardMaterial
);
board.position.z = -0.4;
board.castShadow = true;
board.receiveShadow = true;
group.add(board);
const framePieces = [
[0, 2.3, 0, 4.28, 0.09, 0.11],
[0, -2.3, 0, 4.28, 0.09, 0.11],
[-2.1, 0, 0, 0.09, 4.65, 0.11],
[2.1, 0, 0, 0.09, 4.65, 0.11]
];
framePieces.forEach(([px, py, pz, sx, sy, sz]) => {
const piece = new THREE.Mesh(
new THREE.BoxGeometry(sx, sy, sz),
edgeMaterial
);
piece.position.set(px, py, pz - 0.28);
piece.castShadow = true;
group.add(piece);
});
const boltGeometry = new THREE.CylinderGeometry(0.055, 0.055, 0.055, 8);
for (const bx of [-1.98, 1.98]) {
for (const by of [-2.18, 2.18]) {
const bolt = new THREE.Mesh(boltGeometry, cyanMaterial);
bolt.rotation.x = Math.PI / 2;
bolt.position.set(bx, by, -0.22);
group.add(bolt);
}
}
const title = makeLabel(
index === 0 ? "01 REFLECTION" : "02 ROTATION",
{
width: 3.05,
fontSize: 68,
color: index === 0 ? "#66f2c2" : "#55cfff",
border: index === 0
? "rgba(102, 242, 194, 0.42)"
: "rgba(85, 207, 255, 0.42)"
}
);
title.position.set(0, 1.83, 0.15);
group.add(title);
const subtitle = makeLabel(
index === 0
? "BUTTERFLY / ONE MIRROR AXIS"
: "PINWHEEL / ORDER 4 / NO MIRROR AXIS",
{
width: 3.25,
fontSize: 46,
color: "#b8cbdf",
background: "rgba(7, 16, 28, 0.66)"
}
);
subtitle.position.set(0, 1.43, 0.16);
group.add(subtitle);
addMount(scene, x, index);
return group;
}
const butterflyPanel = makePanel(-3.08, 0);
const pinwheelPanel = makePanel(3.08, 1);
// Butterfly: every shape and marking is mirrored about local x = 0.
const butterfly = new THREE.Group();
butterfly.position.z = 0.06;
butterflyPanel.add(butterfly);
const upperRight = [
[0.05, 0.34], [0.30, 0.73], [0.72, 1.17], [1.23, 0.89],
[1.10, 0.31], [0.62, 0.10], [0.08, 0.18]
];
const lowerRight = [
[0.06, 0.12], [0.58, 0.12], [1.03, -0.22], [0.85, -0.82],
[0.43, -1.12], [0.13, -0.64]
];
const wingPalette = [0xff8b61, 0xf5a15f, 0xffbf69, 0xd95d73];
const rightUpper = coloredShape(upperRight, wingPalette);
const leftUpper = coloredShape(upperRight, wingPalette);
leftUpper.scale.x = -1;
const rightLower = coloredShape(lowerRight, [0x6bc8b7, 0x4bb6a7, 0x7ad7c0, 0x3b918f]);
const leftLower = coloredShape(lowerRight, [0x6bc8b7, 0x4bb6a7, 0x7ad7c0, 0x3b918f]);
leftLower.scale.x = -1;
[leftUpper, rightUpper, leftLower, rightLower].forEach(mesh => {
mesh.position.z = 0.015;
butterfly.add(mesh);
});
const upperCell = [
[0.30, 0.72], [0.69, 1.09], [0.88, 0.89], [0.53, 0.63]
];
const lowerCell = [
[0.55, 0.05], [0.91, -0.24], [0.78, -0.68], [0.43, -0.43]
];
[upperCell, lowerCell].forEach((points, index) => {
const right = coloredShape(
points,
index === 0
? [0x6ce5c4, 0x39bba4, 0x8bf2d5]
: [0xffd166, 0xffb84d, 0xffe39a]
);
right.position.z = 0.026;
butterfly.add(right);
const left = coloredShape(
points,
index === 0
? [0x6ce5c4, 0x39bba4, 0x8bf2d5]
: [0xffd166, 0xffb84d, 0xffe39a]
);
left.scale.x = -1;
left.position.z = 0.026;
butterfly.add(left);
});
const spotMaterial = standard(0x18283c, { roughness: 0.88 });
for (const side of [-1, 1]) {
const upperSpot = new THREE.Mesh(
new THREE.CircleGeometry(0.105, 8),
spotMaterial
);
upperSpot.position.set(side * 0.93, 0.67, 0.034);
butterfly.add(upperSpot);
const lowerSpot = new THREE.Mesh(
new THREE.CircleGeometry(0.082, 8),
spotMaterial
);
lowerSpot.position.set(side * 0.65, -0.56, 0.034);
butterfly.add(lowerSpot);
const veinMaterial = standard(0x284456, {
roughness: 0.8,
transparent: true,
opacity: 0.78
});
const veins = [
[[0.12, 0.31], [0.64, 0.83]],
[[0.12, 0.28], [0.99, 0.64]],
[[0.13, 0.04], [0.79, -0.25]],
[[0.13, -0.06], [0.56, -0.76]]
];
veins.forEach(([a, b]) => {
const from = new THREE.Vector3(side * a[0], a[1], 0.045);
const to = new THREE.Vector3(side * b[0], b[1], 0.045);
cylinderBetween(butterfly, from, to, 0.012, veinMaterial, 5);
});
}
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.095, 0.15, 1.35, 7),
bodyMaterial
);
body.position.set(0, 0.03, 0.13);
body.castShadow = true;
butterfly.add(body);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.17, 0),
bodyMaterial
);
head.position.set(0, 0.75, 0.13);
head.castShadow = true;
butterfly.add(head);
for (const side of [-1, 1]) {
cylinderBetween(
butterfly,
new THREE.Vector3(side * 0.035, 0.79, 0.13),
new THREE.Vector3(side * 0.22, 1.04, 0.13),
0.018,
bodyMaterial,
5
);
cylinderBetween(
butterfly,
new THREE.Vector3(side * 0.24, 1.04, 0.13),
new THREE.Vector3(side * 0.34, 1.17, 0.13),
0.014,
bodyMaterial,
5
);
}
solidAxis(
butterflyPanel,
new THREE.Vector3(0, -1.42, 0.38),
new THREE.Vector3(0, 1.42, 0.38),
mintMaterial
);
dashedAxis(
butterflyPanel,
[-1.62, 0, 0.39],
[1.62, 0, 0.39],
coralMaterial
);
dashedAxis(
butterflyPanel,
[-1.28, -1.28, 0.4],
[1.28, 1.28, 0.4],
coralMaterial,
10
);
const mirrorLabel = makeLabel("MIRROR AXIS", {
width: 1.62,
fontSize: 57,
color: "#66f2c2",
border: "rgba(102, 242, 194, 0.42)"
});
mirrorLabel.position.set(0.78, 1.13, 0.66);
butterflyPanel.add(mirrorLabel);
const rejectedLabel = makeLabel("REJECTED", {
width: 1.2,
fontSize: 50,
color: "#ff8b96",
border: "rgba(255, 107, 120, 0.38)"
});
rejectedLabel.position.set(-1.16, -0.29, 0.66);
butterflyPanel.add(rejectedLabel);
// Pinwheel: four congruent, handed blades form a four-fold rotation.
const pinwheelArt = new THREE.Group();
pinwheelArt.position.z = 0.08;
pinwheelPanel.add(pinwheelArt);
const bladePoints = [
[0.03, 0.03], [0.28, 0.24], [1.20, 0.49], [0.49, 0.70]
];
const tabPoints = [
[0.67, 0.39], [0.98, 0.47], [0.77, 0.59]
];
const bladeColors = [0xff8a5c, 0xf56f61, 0xff9f68, 0xe95f66];
for (let i = 0; i < 4; i++) {
const bladeGroup = new THREE.Group();
bladeGroup.rotation.z = i * Math.PI / 2;
const blade = coloredShape(bladePoints, bladeColors);
blade.position.z = 0.005;
bladeGroup.add(blade);
const tab = coloredShape(
tabPoints,
[0x67edc0, 0x46cfa8, 0x8ff5d4]
);
tab.position.z = 0.025;
bladeGroup.add(tab);
pinwheelArt.add(bladeGroup);
}
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.235, 0.235, 0.19, 12),
standard(palette.gold, {
roughness: 0.48,
metalness: 0.18,
emissive: 0x5c3a00,
emissiveIntensity: 0.22
})
);
hub.rotation.x = Math.PI / 2;
hub.position.z = 0.16;
hub.castShadow = true;
pinwheelArt.add(hub);
const hubCap = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.095, 0),
standard(0xfff1b8, { roughness: 0.42 })
);
hubCap.position.z = 0.29;
pinwheelArt.add(hubCap);
dashedAxis(
pinwheelPanel,
[-1.55, 0, 0.39],
[1.55, 0, 0.39],
coralMaterial
);
dashedAxis(
pinwheelPanel,
[0, -1.55, 0.39],
[0, 1.55, 0.39],
coralMaterial
);
dashedAxis(
pinwheelPanel,
[-1.32, -1.32, 0.4],
[1.32, 1.32, 0.4],
coralMaterial,
10
);
// A cyan ring and out-of-plane arrow identify the rotational axis.
const rotationRing = new THREE.Mesh(
new THREE.TorusGeometry(0.34, 0.019, 5, 32),
cyanMaterial
);
rotationRing.position.z = 0.37;
pinwheelPanel.add(rotationRing);
cylinderBetween(
pinwheelPanel,
new THREE.Vector3(0, 0, 0.32),
new THREE.Vector3(0, 0, 0.62),
0.023,
cyanMaterial,
7
);
addCone(
pinwheelPanel,
new THREE.Vector3(0, 0, 0.69),
new THREE.Vector3(0, 0, 1),
0.07,
0.16,
cyanMaterial
);
// A curved arrow demonstrates one quarter turn.
const arcPoints = [];
const arcStart = THREE.MathUtils.degToRad(-54);
const arcEnd = THREE.MathUtils.degToRad(36);
for (let i = 0; i <= 32; i++) {
const angle = THREE.MathUtils.lerp(arcStart, arcEnd, i / 32);
arcPoints.push(new THREE.Vector3(
Math.cos(angle) * 1.5,
Math.sin(angle) * 1.5,
0.51
));
}
const arcCurve = new THREE.CatmullRomCurve3(arcPoints);
const arc = new THREE.Mesh(
new THREE.TubeGeometry(arcCurve, 48, 0.017, 5, false),
cyanMaterial
);
pinwheelPanel.add(arc);
const tangent = new THREE.Vector3(
-Math.sin(arcEnd),
Math.cos(arcEnd),
0
);
addCone(
pinwheelPanel,
new THREE.Vector3(
Math.cos(arcEnd) * 1.5,
Math.sin(arcEnd) * 1.5,
0.51
),
tangent,
0.075,
0.19,
cyanMaterial
);
for (let i = 0; i < 4; i++) {
const angle = i * Math.PI / 2;
const dot = new THREE.Mesh(
new THREE.OctahedronGeometry(0.055, 0),
cyanMaterial
);
dot.position.set(
Math.cos(angle) * 1.5,
Math.sin(angle) * 1.5,
0.52
);
pinwheelPanel.add(dot);
}
const rotationLabel = makeLabel("4 x 90 DEG TURN", {
width: 1.92,
fontSize: 49,
color: "#55cfff",
border: "rgba(85, 207, 255, 0.45)"
});
rotationLabel.position.set(0.72, 1.14, 0.68);
pinwheelPanel.add(rotationLabel);
const noMirrorLabel = makeLabel("NO MIRROR AXIS", {
width: 1.9,
fontSize: 49,
color: "#ff8b96",
border: "rgba(255, 107, 120, 0.4)"
});
noMirrorLabel.position.set(0, -1.56, 0.68);
pinwheelPanel.add(noMirrorLabel);
// Direct camera controls, implemented without external controls modules.
const current = {
target: new THREE.Vector3(0, 1.95, 0),
theta: 0,
phi: 1.42,
radius: 14.2
};
const goal = {
target: current.target.clone(),
theta: current.theta,
phi: current.phi,
radius: current.radius
};
const spherical = new THREE.Spherical();
let dragging = false;
let panning = false;
let previousX = 0;
let previousY = 0;
let activeView = "all";
let autoOrbit = false;
let spinCurrent = 0;
let spinGoal = 0;
function overviewRadius() {
return window.innerWidth / window.innerHeight < 0.9 ? 21.5 : 14.2;
}
function setView(view) {
activeView = view;
document.querySelectorAll("[data-view]").forEach(button => {
button.classList.toggle("active", button.dataset.view === view);
});
if (view === "all") {
goal.target.set(0, 1.95, 0);
goal.radius = overviewRadius();
goal.theta = 0;
goal.phi = 1.42;
} else if (view === "reflection") {
goal.target.set(-3.08, 2.05, 0);
goal.radius = window.innerWidth / window.innerHeight < 0.9 ? 10.2 : 7.55;
goal.theta = 0;
goal.phi = 1.43;
} else {
goal.target.set(3.08, 2.05, 0);
goal.radius = window.innerWidth / window.innerHeight < 0.9 ? 10.2 : 7.55;
goal.theta = 0;
goal.phi = 1.43;
}
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => setView(button.dataset.view));
});
document.querySelector("#axisToggle").addEventListener("change", event => {
candidateAxes.forEach(axis => {
axis.visible = event.target.checked;
});
});
document.querySelector("#orbitButton").addEventListener("click", event => {
autoOrbit = !autoOrbit;
event.currentTarget.classList.toggle("active", autoOrbit);
});
document.querySelector("#spinButton").addEventListener("click", event => {
spinGoal += Math.PI / 2;
const button = event.currentTarget;
button.classList.add("active");
window.setTimeout(() => button.classList.remove("active"), 900);
});
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = panning ? "move" : "grabbing";
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panning) {
const panScale = goal.radius * 0.0011;
goal.target.x -= dx * panScale;
goal.target.y += dy * panScale;
} else {
goal.theta -= dx * 0.006;
goal.phi = THREE.MathUtils.clamp(
goal.phi - dy * 0.005,
0.42,
1.48
);
}
});
function endDrag(event) {
dragging = false;
panning = false;
canvas.style.cursor = "grab";
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.style.cursor = "grab";
canvas.addEventListener("wheel", event => {
event.preventDefault();
goal.radius = THREE.MathUtils.clamp(
goal.radius * Math.exp(event.deltaY * 0.001),
5.2,
24
);
}, { passive: false });
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
if (activeView === "all") goal.radius = overviewRadius();
});
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (autoOrbit) goal.theta += dt * 0.11;
const damping = 1 - Math.exp(-6.5 * dt);
current.theta += (goal.theta - current.theta) * damping;
current.phi += (goal.phi - current.phi) * damping;
current.radius += (goal.radius - current.radius) * damping;
current.target.lerp(goal.target, damping);
spherical.set(current.radius, current.phi, current.theta);
camera.position.setFromSpherical(spherical).add(current.target);
camera.lookAt(current.target);
const spinDamping = 1 - Math.exp(-5.5 * dt);
spinCurrent += (spinGoal - spinCurrent) * spinDamping;
pinwheelArt.rotation.z = spinCurrent;
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
window.setTimeout(() => loading.remove(), 450);
}
}
current.radius = overviewRadius();
goal.radius = overviewRadius();
animate();
</script>
</body>
</html>
```