Prompt specification
Build or customize the Three.js 3D scene "Swing Seat and Fixed Suspension Points" 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: Swing Seat and Fixed Suspension Points
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/swing-seat-and-fixed-suspension-points-x3621
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring playground swings as pendulums. Model a seat suspended by equal-length ropes from two fixed pivots. Keep rope lengths constant and show the allowed arc without stretching the suspension. Low-poly.
Working Three.js Starter (swing-seat-and-fixed-suspension-points-x3621):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pendulum Playground</title>
<style>
:root {
color-scheme: light;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9def0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
top: 22px;
left: 22px;
width: min(360px, calc(100vw - 44px));
padding: 20px;
color: #163544;
background: rgba(248, 252, 249, 0.88);
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 18px;
box-shadow: 0 18px 50px rgba(33, 67, 75, 0.18);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
user-select: none;
}
.eyebrow {
margin-bottom: 6px;
color: #277887;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 4vw, 31px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.description {
margin: 12px 0 17px;
color: #496773;
font-size: 13px;
line-height: 1.55;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-bottom: 17px;
}
.metric {
min-width: 0;
padding: 10px 9px;
background: rgba(255, 255, 255, 0.72);
border: 1px solid rgba(31, 83, 92, 0.09);
border-radius: 11px;
}
.metric span {
display: block;
margin-bottom: 3px;
color: #69818a;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric strong {
display: block;
overflow: hidden;
color: #173b48;
font-size: 15px;
text-overflow: ellipsis;
white-space: nowrap;
}
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 9px;
padding-top: 15px;
border-top: 1px solid rgba(31, 83, 92, 0.12);
}
button,
.toggle {
min-height: 34px;
padding: 7px 11px;
color: #234a57;
background: rgba(255, 255, 255, 0.84);
border: 1px solid rgba(31, 83, 92, 0.16);
border-radius: 9px;
font: inherit;
font-size: 12px;
font-weight: 700;
}
button {
cursor: pointer;
}
button:hover {
background: #ffffff;
border-color: rgba(31, 83, 92, 0.32);
}
.toggle {
display: flex;
align-items: center;
gap: 7px;
cursor: pointer;
}
.toggle input {
width: 15px;
height: 15px;
accent-color: #277887;
}
.speed {
display: flex;
align-items: center;
gap: 7px;
min-height: 34px;
font-size: 12px;
font-weight: 700;
}
.speed input {
width: 76px;
accent-color: #277887;
}
.hint {
position: fixed;
z-index: 10;
right: 18px;
bottom: 16px;
padding: 8px 12px;
color: rgba(24, 56, 68, 0.72);
background: rgba(255, 255, 255, 0.55);
border-radius: 999px;
font-size: 11px;
font-weight: 650;
pointer-events: none;
backdrop-filter: blur(8px);
}
@media (max-width: 600px) {
.panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 16px;
}
.description {
margin: 9px 0 12px;
}
.metrics {
margin-bottom: 12px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<section class="panel" aria-label="Scene information and controls">
<div class="eyebrow">Live physics study</div>
<h1>Pendulum Playground</h1>
<p class="description">
Each rigid seat hangs from two fixed pivots with equal-length ropes.
The dashed curve shows the seat center’s allowed path.
</p>
<div class="metrics">
<div class="metric">
<span>Rope length</span>
<strong>2.550 m</strong>
</div>
<div class="metric">
<span>Live angle</span>
<strong id="angleValue">0.0°</strong>
</div>
<div class="metric">
<span>Rope check</span>
<strong id="ropeValue">2.550 m</strong>
</div>
</div>
<div class="controls">
<label class="toggle">
<input id="arcToggle" type="checkbox" checked>
Show arcs
</label>
<button id="pauseButton" type="button">Pause</button>
<label class="speed">
Speed
<input
id="speedSlider"
type="range"
min="0.25"
max="1.75"
step="0.05"
value="1"
>
<span id="speedValue">1.0×</span>
</label>
<button id="resetButton" type="button">Reset view</button>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom · Space to pause</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9def0);
scene.fog = new THREE.Fog(0xb9def0, 19, 42);
const camera = new THREE.PerspectiveCamera(
44,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly playground with pendulum swings"
);
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
0xeaf8ff,
0x70875b,
2.0
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1cf, 2.7);
sun.position.set(-8, 14, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9ddff, 0.7);
fill.position.set(8, 6, -10);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
function standard(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...extra
});
}
const materials = {
ground: standard(0x79aa69),
sand: standard(0xe4c58d),
frame: standard(0x236e78, { metalness: 0.18 }),
topBeam: standard(0xf2b640, { metalness: 0.12 }),
rope: standard(0xf3dfb2),
dark: standard(0x29434b),
trunk: standard(0x805536),
leaves: standard(0x3f8b59),
leavesLight: standard(0x5ba76b),
cloud: standard(0xf5fbfc)
};
const up = new THREE.Vector3(0, 1, 0);
const tempDirection = new THREE.Vector3();
const tempMidpoint = new THREE.Vector3();
function addBox(width, height, depth, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBeam(start, end, width, depth, material, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, 1, depth),
material
);
tempDirection.subVectors(end, start);
const length = tempDirection.length();
tempMidpoint.addVectors(start, end).multiplyScalar(0.5);
mesh.position.copy(tempMidpoint);
mesh.scale.y = length;
mesh.quaternion.setFromUnitVectors(
up,
tempDirection.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function positionCylinderBetween(mesh, start, end) {
tempDirection.subVectors(end, start);
const length = tempDirection.length();
tempMidpoint.addVectors(start, end).multiplyScalar(0.5);
mesh.position.copy(tempMidpoint);
mesh.scale.set(1, length, 1);
mesh.quaternion.setFromUnitVectors(
up,
tempDirection.normalize()
);
}
// -------------------------------------------------------------------------
// Playground environment
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.12;
ground.receiveShadow = true;
scene.add(ground);
const sandpit = new THREE.Mesh(
new THREE.CylinderGeometry(7.7, 8.0, 0.2, 24),
materials.sand
);
sandpit.position.y = -0.01;
sandpit.receiveShadow = true;
scene.add(sandpit);
// Main overhead beam.
addBox(0.25, 0.25, 9.8, materials.topBeam, 0, 4.45, 0);
// Two A-frame supports.
for (const z of [-4.55, 4.55]) {
addBeam(
new THREE.Vector3(0, 4.43, z),
new THREE.Vector3(-1.78, 0.16, z),
0.18,
0.18,
materials.frame
);
addBeam(
new THREE.Vector3(0, 4.43, z),
new THREE.Vector3(1.78, 0.16, z),
0.18,
0.18,
materials.frame
);
addBeam(
new THREE.Vector3(-1.78, 0.16, z),
new THREE.Vector3(1.78, 0.16, z),
0.17,
0.17,
materials.frame
);
}
// Longitudinal rails.
for (const x of [-0.9, 0.9]) {
addBeam(
new THREE.Vector3(x, 2.38, -4.45),
new THREE.Vector3(x, 2.38, 4.45),
0.13,
0.13,
materials.frame
);
}
// Cross braces between the supports.
for (const z of [-2.35, 2.35]) {
addBeam(
new THREE.Vector3(-0.9, 2.38, z),
new THREE.Vector3(0.9, 2.38, z),
0.12,
0.12,
materials.frame
);
}
// -------------------------------------------------------------------------
// Swings
//
// Every swing has TWO fixed pivots and TWO equal ropes.
//
// For a swing angle θ:
// dx = L sin(θ)
// dy = -L cos(θ)
//
// Therefore hypot(dx, dy) is always exactly L. The seat is translated
// without rotation, so both ropes remain the same fixed length.
// -------------------------------------------------------------------------
const ROPE_LENGTH = 2.55;
const PIVOT_Y = 4.18;
const ATTACHMENT_OFFSET = 0.12;
const HALF_PIVOT_SPACING = 0.72;
const GRAVITY = 9.81;
const swingDefinitions = [
{ z: -2.7, color: 0xec6c61, amplitude: 38, phase: 0.0 },
{ z: 0.0, color: 0x428fd0, amplitude: 48, phase: 1.8 },
{ z: 2.7, color: 0xf0a33c, amplitude: 34, phase: 3.6 }
];
const swings = [];
const arcs = [];
function createArc(color, z, amplitude, isMiddle) {
const points = [];
const segments = 100;
// The seat center traces a circle of radius L around an effective
// pivot located ATTACHMENT_OFFSET below the physical pivot.
const arcCenterY = PIVOT_Y - ATTACHMENT_OFFSET;
for (let i = 0; i <= segments; i++) {
const angle = THREE.MathUtils.lerp(
-amplitude,
amplitude,
i / segments
);
points.push(
new THREE.Vector3(
ROPE_LENGTH * Math.sin(angle),
arcCenterY - ROPE_LENGTH * Math.cos(angle),
z
)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color,
dashSize: isMiddle ? 0.17 : 0.13,
gapSize: isMiddle ? 0.09 : 0.08,
transparent: true,
opacity: isMiddle ? 0.88 : 0.48,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
line.renderOrder = 2;
scene.add(line);
arcs.push(line);
return line;
}
swingDefinitions.forEach((definition, index) => {
const seatMaterial = standard(definition.color);
const seatGroup = new THREE.Group();
scene.add(seatGroup);
// Three wooden-looking slats.
for (const zOffset of [-0.48, 0, 0.48]) {
addBox(
0.62,
0.10,
0.30,
seatMaterial,
0,
0,
zOffset,
seatGroup
);
}
// Underside rails.
addBox(0.07, 0.12, 1.56, materials.dark, -0.22, -0.07, 0, seatGroup);
addBox(0.07, 0.12, 1.56, materials.dark, 0.22, -0.07, 0, seatGroup);
// Connector beneath the two rope attachment points.
addBox(0.10, 0.08, 1.56, materials.dark, 0, 0.08, 0, seatGroup);
const ropeMeshes = [];
for (const side of [-1, 1]) {
const pivotZ = definition.z + side * HALF_PIVOT_SPACING;
// Fixed pivot cap.
const pivotCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.105, 0.105, 0.18, 8),
materials.dark
);
pivotCap.position.set(0, 4.25, pivotZ);
pivotCap.castShadow = true;
scene.add(pivotCap);
// Visible lower attachment fitting.
const fitting = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 8, 6),
materials.dark
);
fitting.position.set(0, ATTACHMENT_OFFSET, side * HALF_PIVOT_SPACING);
fitting.castShadow = true;
seatGroup.add(fitting);
// Each rope is a low-poly cylinder repositioned between its endpoints.
const rope = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 1, 6),
materials.rope
);
rope.castShadow = true;
scene.add(rope);
ropeMeshes.push(rope);
}
createArc(
definition.color,
definition.z,
THREE.MathUtils.degToRad(definition.amplitude),
index === 1
);
swings.push({
...definition,
seatGroup,
ropeMeshes
});
});
// -------------------------------------------------------------------------
// Low-poly scenery
// -------------------------------------------------------------------------
function createTree(x, z, scale, alternate = false) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.21, 1.45, 6),
materials.trunk
);
trunk.position.y = 0.72;
trunk.castShadow = true;
tree.add(trunk);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(0.95, 2.35, 7),
alternate ? materials.leavesLight : materials.leaves
);
crown.position.y = 2.15;
crown.rotation.y = x * 0.37 + z * 0.19;
crown.castShadow = true;
tree.add(crown);
scene.add(tree);
}
[
[-9.1, -5.8, 1.15],
[-8.0, 4.9, 0.95],
[ 8.7, -5.4, 1.05],
[ 9.0, 3.9, 1.18],
[-10.4, 0.4, 0.85],
[ 10.3, -0.3, 0.90]
].forEach((tree, index) => {
createTree(tree[0], tree[1], tree[2], index % 2 === 0);
});
function createCloud(x, y, z, scale) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
const pieces = [
[-0.8, 0, 0, 0.65],
[-0.25, 0.18, 0, 0.85],
[ 0.42, 0.06, 0, 0.72],
[ 0.95, -0.03, 0, 0.50]
];
for (const [px, py, pz, radius] of pieces) {
const puff = new THREE.Mesh(
new THREE.DodecahedronGeometry(radius, 0),
materials.cloud
);
puff.position.set(px, py, pz);
cloud.add(puff);
}
scene.add(cloud);
}
createCloud(-6.5, 8.0, -11, 1.2);
createCloud(7.0, 8.7, -15, 0.9);
// -------------------------------------------------------------------------
// Custom orbit controls, implemented without addons
// -------------------------------------------------------------------------
const orbit = {
theta: 0.57,
phi: 1.08,
radius: 14.2,
target: new THREE.Vector3(0, 2.2, 0)
};
const defaultOrbit = {
theta: 0.57,
phi: 1.08,
radius: 14.2,
target: new THREE.Vector3(0, 2.2, 0)
};
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
renderer.domElement.addEventListener("pointerdown", event => {
if (event.pointerType === "mouse" && event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.theta -= dx * 0.0055;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.0045,
0.46,
1.45
);
});
function endDrag(event) {
dragging = false;
if (
event.pointerType !== "mouse" &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
7.5,
24
);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
const angleValue = document.getElementById("angleValue");
const ropeValue = document.getElementById("ropeValue");
const pauseButton = document.getElementById("pauseButton");
const arcToggle = document.getElementById("arcToggle");
const speedSlider = document.getElementById("speedSlider");
const speedValue = document.getElementById("speedValue");
const resetButton = document.getElementById("resetButton");
let paused = false;
let simulationSpeed = 1;
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Play" : "Pause";
});
arcToggle.addEventListener("change", () => {
arcs.forEach(arc => {
arc.visible = arcToggle.checked;
});
});
speedSlider.addEventListener("input", () => {
simulationSpeed = Number(speedSlider.value);
speedValue.textContent = `${simulationSpeed.toFixed(2).replace(/0$/, "")}×`;
});
resetButton.addEventListener("click", () => {
orbit.theta = defaultOrbit.theta;
orbit.phi = defaultOrbit.phi;
orbit.radius = defaultOrbit.radius;
orbit.target.copy(defaultOrbit.target);
});
addEventListener("keydown", event => {
const activeTag = document.activeElement?.tagName;
if (activeTag === "INPUT" || activeTag === "BUTTON") return;
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.code === "ArrowLeft") orbit.theta += 0.08;
if (event.code === "ArrowRight") orbit.theta -= 0.08;
if (event.code === "ArrowUp") orbit.phi -= 0.06;
if (event.code === "ArrowDown") orbit.phi += 0.06;
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const pendulumFrequency = Math.sqrt(GRAVITY / ROPE_LENGTH);
let simulationTime = 0;
function updateSwings() {
for (const swing of swings) {
const amplitude = THREE.MathUtils.degToRad(swing.amplitude);
const angle =
amplitude * Math.sin(pendulumFrequency * simulationTime + swing.phase);
// Fixed-radius pendulum displacement.
const dx = ROPE_LENGTH * Math.sin(angle);
const dy = -ROPE_LENGTH * Math.cos(angle);
// The rigid seat remains horizontal while translating along the arc.
swing.seatGroup.position.set(
dx,
PIVOT_Y + dy - ATTACHMENT_OFFSET,
swing.z
);
swing.ropeMeshes.forEach((rope, index) => {
const side = index === 0 ? -1 : 1;
const pivotZ = swing.z + side * HALF_PIVOT_SPACING;
const top = new THREE.Vector3(
0,
PIVOT_Y,
pivotZ
);
const bottom = new THREE.Vector3(
dx,
PIVOT_Y + dy,
pivotZ
);
positionCylinderBetween(rope, top, bottom);
});
}
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
simulationTime += delta * simulationSpeed;
}
updateSwings();
updateCamera();
const middleSwing = swings[1];
const middleAngle =
THREE.MathUtils.degToRad(middleSwing.amplitude) *
Math.sin(pendulumFrequency * simulationTime + middleSwing.phase);
angleValue.textContent =
`${THREE.MathUtils.radToDeg(middleAngle) >= 0 ? "+" : ""}` +
`${THREE.MathUtils.radToDeg(middleAngle).toFixed(1)}°`;
// The analytical construction guarantees this value, but display the
// live geometric result to make the constant-length constraint explicit.
const measuredRopeLength = Math.hypot(
ROPE_LENGTH * Math.sin(middleAngle),
ROPE_LENGTH * Math.cos(middleAngle)
);
ropeValue.textContent = `${measuredRopeLength.toFixed(3)} m`;
renderer.render(scene, camera);
}
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
updateSwings();
updateCamera();
animate();
</script>
</body>
</html>
```