Prompt specification
Build or customize the Three.js 3D scene "Fruit-sharing picnic board" 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: Fruit-sharing picnic board
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/fruit-sharing-picnic-board-x0095
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring segmented citrus fruit. Build a picnic arrangement with mandarins, plates, cups, and baskets; distribute equal segment groups among visitors and display the remaining count beside the shared fruit. Stylized solid forms.
Working Three.js Starter (fruit-sharing-picnic-board-x0095):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#f7f1df" />
<title>Citrus Picnic</title>
<style>
:root {
--ink: #26372c;
--muted: #6f796f;
--cream: #fffaf0;
--paper: rgba(255, 250, 240, 0.9);
--orange: #f47a32;
--orange-dark: #d95b22;
--green: #52755a;
--line: rgba(38, 55, 44, 0.12);
--shadow: 0 18px 50px rgba(47, 63, 46, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9d9;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene-canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene-canvas:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.brand {
position: absolute;
top: 25px;
left: 28px;
display: flex;
align-items: center;
gap: 10px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.brand-mark {
display: grid;
width: 31px;
height: 31px;
place-items: center;
border-radius: 50%;
background: var(--orange);
color: white;
box-shadow: 0 8px 22px rgba(217, 91, 34, 0.25);
}
.brand-mark svg {
width: 18px;
height: 18px;
}
.intro {
position: absolute;
top: 76px;
left: 28px;
width: min(360px, calc(100vw - 56px));
}
.eyebrow {
margin: 0 0 9px;
color: var(--orange-dark);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 330px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(40px, 4.4vw, 66px);
font-weight: 500;
line-height: 0.93;
letter-spacing: -0.055em;
}
.intro-copy {
max-width: 315px;
margin: 17px 0 0;
color: #59675d;
font-size: 14px;
line-height: 1.55;
}
.control-panel {
position: absolute;
left: 28px;
bottom: 28px;
width: 330px;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 22px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
}
.control-row + .control-row {
margin-top: 17px;
padding-top: 17px;
border-top: 1px solid var(--line);
}
.control-label {
display: block;
margin-bottom: 5px;
font-size: 12px;
font-weight: 800;
}
.control-value {
color: var(--muted);
font-size: 12px;
}
.counter {
display: flex;
align-items: center;
gap: 5px;
padding: 4px;
border-radius: 14px;
background: #f1eadb;
}
.counter button {
display: grid;
width: 31px;
height: 31px;
padding: 0;
place-items: center;
border: 0;
border-radius: 10px;
background: transparent;
cursor: pointer;
font-size: 19px;
transition: background 160ms ease, transform 160ms ease;
}
.counter button:hover {
background: white;
transform: translateY(-1px);
}
.counter button:disabled {
cursor: default;
opacity: 0.32;
transform: none;
}
#visitorCount {
min-width: 26px;
text-align: center;
font-size: 14px;
font-weight: 850;
}
input[type="range"] {
width: 138px;
height: 5px;
margin: 0;
border-radius: 999px;
outline: none;
appearance: none;
background: linear-gradient(
to right,
var(--orange) 0%,
var(--orange) var(--range-fill, 63%),
#e7dfcf var(--range-fill, 63%),
#e7dfcf 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 18px;
height: 18px;
border: 3px solid white;
border-radius: 50%;
appearance: none;
background: var(--orange);
box-shadow: 0 3px 10px rgba(217, 91, 34, 0.3);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid white;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 3px 10px rgba(217, 91, 34, 0.3);
}
.share-panel {
position: absolute;
top: 25px;
right: 25px;
width: 276px;
padding: 17px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 22px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.share-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 14px;
padding-bottom: 13px;
border-bottom: 1px solid var(--line);
}
.share-title {
margin: 0;
font-size: 13px;
font-weight: 850;
}
.share-subtitle {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
}
.remaining-badge {
flex: 0 0 auto;
padding: 6px 9px;
border-radius: 999px;
background: #fff0d8;
color: #b65120;
font-size: 11px;
font-weight: 850;
}
#visitorList {
display: grid;
gap: 5px;
margin-top: 11px;
}
.visitor-item {
display: flex;
align-items: center;
gap: 9px;
min-height: 34px;
padding: 6px 8px;
border-radius: 12px;
transition: background 160ms ease, transform 160ms ease;
}
.visitor-item:hover {
background: rgba(255, 255, 255, 0.72);
transform: translateX(-2px);
}
.visitor-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--dot, var(--orange));
box-shadow: 0 0 0 4px color-mix(in srgb, var(--dot, var(--orange)) 14%, transparent);
}
.visitor-name {
flex: 1;
font-size: 12px;
font-weight: 700;
}
.visitor-share {
color: var(--muted);
font-size: 11px;
}
.visitor-share strong {
color: var(--ink);
}
.camera-tools {
position: absolute;
right: 25px;
bottom: 27px;
display: flex;
gap: 7px;
padding: 6px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 16px;
background: var(--paper);
box-shadow: 0 10px 28px rgba(47, 63, 46, 0.12);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.camera-tools button {
display: grid;
width: 34px;
height: 34px;
padding: 0;
place-items: center;
border: 0;
border-radius: 11px;
background: transparent;
cursor: pointer;
font-size: 17px;
transition: background 150ms ease, transform 150ms ease;
}
.camera-tools button:hover {
background: white;
transform: translateY(-1px);
}
.camera-tools button svg {
width: 17px;
height: 17px;
}
.hint {
position: absolute;
bottom: 31px;
left: 50%;
display: flex;
align-items: center;
gap: 8px;
padding: 9px 13px;
border-radius: 999px;
background: rgba(255, 250, 240, 0.72);
color: #617064;
font-size: 11px;
box-shadow: 0 8px 24px rgba(47, 63, 46, 0.08);
backdrop-filter: blur(10px);
transform: translateX(-50%);
}
.hint svg {
width: 14px;
height: 14px;
}
#fruit-tag {
position: fixed;
z-index: 4;
display: flex;
align-items: center;
gap: 7px;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 12px;
background: rgba(255, 250, 240, 0.94);
box-shadow: 0 10px 26px rgba(47, 63, 46, 0.16);
color: var(--ink);
pointer-events: none;
transform: translate(-50%, -115%);
transition: opacity 120ms ease;
white-space: nowrap;
}
#fruit-tag::after {
position: absolute;
bottom: -5px;
left: 50%;
width: 9px;
height: 9px;
border-right: 1px solid rgba(255, 255, 255, 0.85);
border-bottom: 1px solid rgba(255, 255, 255, 0.85);
background: rgba(255, 250, 240, 0.94);
content: "";
transform: translateX(-50%) rotate(45deg);
}
.tag-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--orange);
}
#fruit-tag strong {
font-size: 11px;
}
#fruit-tag small {
color: var(--muted);
font-size: 10px;
}
@media (max-width: 760px) {
.brand {
top: 17px;
left: 17px;
}
.intro {
top: 59px;
left: 17px;
}
h1 {
font-size: 39px;
}
.intro-copy {
display: none;
}
.control-panel {
right: 15px;
bottom: 15px;
left: 15px;
width: auto;
padding: 14px;
}
.control-row + .control-row {
margin-top: 12px;
padding-top: 12px;
}
.share-panel {
top: 16px;
right: 15px;
width: 205px;
padding: 12px;
}
.share-subtitle {
display: none;
}
#visitorList {
max-height: 155px;
overflow: auto;
}
.hint {
display: none;
}
.camera-tools {
right: 15px;
bottom: 176px;
}
}
@media (max-width: 470px) {
.share-panel {
top: 62px;
width: 176px;
}
.share-header {
display: block;
}
.remaining-badge {
display: inline-block;
margin-top: 7px;
}
.visitor-name {
font-size: 11px;
}
}
</style>
</head>
<body>
<canvas id="scene-canvas" aria-label="Interactive 3D picnic scene"></canvas>
<div class="ui">
<div class="brand">
<span class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<path d="M12 3v4M8.5 5.5c1.1.2 2.2.1 3.5-.5 1.3.6 2.4.7 3.5.5" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/>
<circle cx="12" cy="14" r="7" stroke="currentColor" stroke-width="1.7"/>
<path d="M12 8v12M7.4 10.2c2.9 1.1 6.3 1.1 9.2 0M7.8 15c2.6-.8 5.8-.8 8.4 0" stroke="currentColor" stroke-width="1.25" stroke-linecap="round"/>
</svg>
</span>
Sunday Citrus Club
</div>
<section class="intro">
<p class="eyebrow">A little picnic, a fair share</p>
<h1>Share the sunshine.</h1>
<p class="intro-copy">
Split the citrus fairly, fill each plate, and leave the extras beside the shared fruit.
Everyone gets an equal helping.
</p>
</section>
<section class="control-panel" aria-label="Picnic sharing controls">
<div class="control-row">
<div>
<label class="control-label" for="visitorCount">Visitors</label>
<span class="control-value">Choose your picnic group</span>
</div>
<div class="counter">
<button id="visitorsMinus" type="button" aria-label="Remove one visitor">−</button>
<span id="visitorCount">4</span>
<button id="visitorsPlus" type="button" aria-label="Add one visitor">+</button>
</div>
</div>
<div class="control-row">
<div>
<label class="control-label" for="segmentRange">Citrus segments</label>
<span class="control-value"><strong id="segmentTotal">30</strong> to share</span>
</div>
<input id="segmentRange" type="range" min="12" max="36" step="2" value="30" />
</div>
</section>
<aside class="share-panel" aria-label="Equal sharing summary">
<div class="share-header">
<div>
<h2 class="share-title">Equal portions</h2>
<p class="share-subtitle">Each visitor receives the same amount.</p>
</div>
<span class="remaining-badge"><span id="remainingCount">2</span> left</span>
</div>
<div id="visitorList"></div>
</aside>
<div class="camera-tools" aria-label="Camera controls">
<button id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button id="resetCamera" type="button" aria-label="Reset camera view">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M4 8V4h4M4.7 4.7A9 9 0 1 1 3 14" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
</div>
<div class="hint">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M8 10V7a2 2 0 0 1 4 0v3-1a2 2 0 0 1 4 0v2-1a2 2 0 0 1 4 0v5c0 4-3 7-7 7h-1c-3 0-5-2-6-4l-2-4a2 2 0 0 1 3-2l1 1v-3Z" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
Drag to look around · Scroll to zoom
</div>
</div>
<div id="fruit-tag" aria-live="polite">
<span class="tag-dot"></span>
<strong id="fruitTagCount">2 segments left</strong>
<small>shared citrus</small>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene-canvas");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9d9);
scene.fog = new THREE.Fog(0xdce9d9, 15, 31);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.45, 0);
let desiredYaw = 0.68;
let desiredPitch = 1.02;
let desiredRadius = 11.7;
let currentYaw = desiredYaw;
let currentPitch = desiredPitch;
let currentRadius = desiredRadius;
const material = {
ground: new THREE.MeshStandardMaterial({ color: 0xc9ddbd, roughness: 1 }),
cloth: new THREE.MeshStandardMaterial({ color: 0xe8794b, roughness: 0.92 }),
stripe: new THREE.MeshStandardMaterial({ color: 0xffe6bd, roughness: 0.94 }),
cream: new THREE.MeshStandardMaterial({ color: 0xfff8e8, roughness: 0.74 }),
plate: new THREE.MeshStandardMaterial({ color: 0xfffaf0, roughness: 0.48 }),
orange: new THREE.MeshStandardMaterial({ color: 0xf27a2d, roughness: 0.62 }),
orangeSide: new THREE.MeshStandardMaterial({ color: 0xd95b22, roughness: 0.72 }),
orangeLight: new THREE.MeshStandardMaterial({ color: 0xffa044, roughness: 0.6 }),
pith: new THREE.MeshStandardMaterial({ color: 0xffedc7, roughness: 0.85 }),
wicker: new THREE.MeshStandardMaterial({ color: 0xc8954e, roughness: 0.95 }),
wickerLight: new THREE.MeshStandardMaterial({ color: 0xddb66f, roughness: 0.94 }),
leaf: new THREE.MeshStandardMaterial({ color: 0x527d48, roughness: 0.9 }),
stem: new THREE.MeshStandardMaterial({ color: 0x6f6938, roughness: 0.95 }),
tea: new THREE.MeshStandardMaterial({ color: 0x875c36, roughness: 0.4 }),
treeTrunk: new THREE.MeshStandardMaterial({ color: 0x9a7650, roughness: 1 }),
treeLeaf: new THREE.MeshStandardMaterial({ color: 0x789b68, roughness: 1 }),
treeLeafLight: new THREE.MeshStandardMaterial({ color: 0x91ad78, roughness: 1 })
};
const hemisphere = new THREE.HemisphereLight(0xfff9e8, 0x7a8f6a, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.15);
sun.position.set(-5, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xdcecff, 0.75);
fill.position.set(7, 5, -5);
scene.add(fill);
function shadow(mesh, cast = true, receive = true) {
mesh.castShadow = cast;
mesh.receiveShadow = receive;
return mesh;
}
function mesh(geometry, mat, parent = scene) {
const object = shadow(new THREE.Mesh(geometry, mat));
parent.add(object);
return object;
}
// Ground and picnic blanket.
const ground = mesh(new THREE.PlaneGeometry(70, 70), material.ground, scene);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.16;
ground.castShadow = false;
const blanket = mesh(new THREE.BoxGeometry(8.2, 0.12, 5.8), material.cloth);
blanket.position.y = -0.075;
const stripeGeometry = new THREE.BoxGeometry(0.3, 0.022, 5.82);
[-3.45, -2.45, -1.45, 1.45, 2.45, 3.45].forEach((x) => {
const stripe = mesh(stripeGeometry, material.stripe);
stripe.position.set(x, -0.002, 0);
stripe.castShadow = false;
});
const fringeGeometry = new THREE.BoxGeometry(0.055, 0.05, 0.26);
for (let i = 0; i < 28; i++) {
const fringe = mesh(fringeGeometry, material.stripe);
fringe.position.set(-3.95 + i * 0.293, -0.045, 3.02);
fringe.castShadow = false;
}
// Low-poly scenery.
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, -0.13, z);
tree.scale.setScalar(scale);
scene.add(tree);
const trunk = mesh(new THREE.CylinderGeometry(0.18, 0.25, 1.8, 7), material.treeTrunk, tree);
trunk.position.y = 0.9;
const lower = mesh(new THREE.IcosahedronGeometry(1.1, 1), material.treeLeaf, tree);
lower.position.set(0, 2.05, 0);
lower.scale.set(1, 1.05, 0.92);
const upper = mesh(new THREE.IcosahedronGeometry(0.85, 1), material.treeLeafLight, tree);
upper.position.set(0.22, 2.85, -0.08);
}
addTree(-6.5, -5.2, 1.05);
addTree(5.7, -6.2, 1.22);
addTree(-7.7, 1.7, 0.86);
addTree(7.3, 0.2, 0.92);
function addFlower(x, z, color) {
const group = new THREE.Group();
group.position.set(x, -0.13, z);
scene.add(group);
const stem = mesh(new THREE.CylinderGeometry(0.018, 0.022, 0.24, 5), material.leaf, group);
stem.position.y = 0.12;
const petalMaterial = new THREE.MeshStandardMaterial({ color, roughness: 0.8 });
for (let i = 0; i < 5; i++) {
const petal = mesh(new THREE.SphereGeometry(0.07, 8, 5), petalMaterial, group);
const a = (i / 5) * Math.PI * 2;
petal.scale.set(1.2, 0.45, 0.75);
petal.position.set(Math.cos(a) * 0.08, 0.25, Math.sin(a) * 0.08);
petal.rotation.y = -a;
}
const center = mesh(new THREE.SphereGeometry(0.055, 8, 5), material.orangeLight, group);
center.position.y = 0.27;
center.scale.y = 0.5;
}
[
[-4.5, 3.2, 0xf3b448],
[-5.2, 2.5, 0xfff2c5],
[4.8, 3.3, 0xf3b448],
[5.4, 2.7, 0xfff2c5],
[-3.8, -3.5, 0xe98a4f],
[4.1, -3.7, 0xfff2c5]
].forEach(([x, z, color]) => addFlower(x, z, color));
function addMandarin(parent, x, y, z, radius = 0.25, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotation;
parent.add(group);
const fruit = mesh(
new THREE.SphereGeometry(radius, 20, 12),
material.orange,
group
);
fruit.scale.set(1, 0.9, 1);
const stem = mesh(
new THREE.CylinderGeometry(0.018, 0.025, 0.08, 7),
material.stem,
group
);
stem.position.y = radius * 0.88;
const leaf = mesh(new THREE.SphereGeometry(radius * 0.42, 10, 6), material.leaf, group);
leaf.scale.set(1, 0.12, 0.45);
leaf.position.set(radius * 0.38, radius * 0.9, 0);
leaf.rotation.z = -0.25;
return group;
}
function addPlate(parent, radius = 0.55, rimColor = material.plate) {
const group = new THREE.Group();
parent.add(group);
const base = mesh(
new THREE.CylinderGeometry(radius, radius * 0.92, 0.07, 40),
material.plate,
group
);
base.position.y = 0.035;
const rim = mesh(
new THREE.TorusGeometry(radius * 0.91, 0.025, 10, 44),
rimColor,
group
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.072;
const inner = mesh(
new THREE.CylinderGeometry(radius * 0.72, radius * 0.72, 0.012, 36),
new THREE.MeshStandardMaterial({ color: 0xf5ead4, roughness: 0.76 }),
group
);
inner.position.y = 0.076;
inner.castShadow = false;
return group;
}
function addCup(parent, x, z, angle = 0, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.015, z);
group.rotation.y = angle;
group.scale.setScalar(scale);
parent.add(group);
const body = mesh(
new THREE.CylinderGeometry(0.18, 0.145, 0.33, 24, 1, true),
new THREE.MeshStandardMaterial({
color: 0x6f9b83,
roughness: 0.52,
side: THREE.DoubleSide
}),
group
);
body.position.y = 0.165;
const bottom = mesh(new THREE.CylinderGeometry(0.145, 0.145, 0.025, 24), material.cream, group);
bottom.position.y = 0.014;
const liquid = mesh(new THREE.CircleGeometry(0.155, 24), material.tea, group);
liquid.rotation.x = -Math.PI / 2;
liquid.position.y = 0.292;
const rim = mesh(new THREE.TorusGeometry(0.178, 0.018, 8, 28), material.cream, group);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.33;
const handle = mesh(
new THREE.TorusGeometry(0.115, 0.027, 8, 24, Math.PI * 1.55),
material.cream,
group
);
handle.position.set(0.18, 0.17, 0);
handle.rotation.z = -0.45;
return group;
}
function addBasket(parent, x, z, scale = 1, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.01, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
parent.add(group);
const body = mesh(
new THREE.CylinderGeometry(0.57, 0.47, 0.48, 14),
material.wicker,
group
);
body.position.y = 0.24;
[0.08, 0.23, 0.39, 0.48].forEach((y, index) => {
const radius = 0.47 + index * 0.03;
const ring = mesh(
new THREE.TorusGeometry(radius, 0.027, 7, 28),
index % 2 ? material.wickerLight : material.wicker,
group
);
ring.rotation.x = Math.PI / 2;
ring.position.y = y;
});
const slatGeometry = new THREE.BoxGeometry(0.035, 0.42, 0.065);
for (let i = 0; i < 14; i++) {
const a = (i / 14) * Math.PI * 2;
const slat = mesh(slatGeometry, material.wickerLight, group);
slat.position.set(Math.sin(a) * 0.525, 0.24, Math.cos(a) * 0.525);
slat.rotation.y = a;
}
const handle = mesh(
new THREE.TorusGeometry(0.53, 0.043, 9, 36, Math.PI),
material.wickerLight,
group
);
handle.position.y = 0.46;
const fruitPositions = [
[-0.2, 0.54, 0.13, 0.21],
[0.2, 0.55, 0.08, 0.22],
[0, 0.57, -0.25, 0.2]
];
fruitPositions.forEach(([fx, fy, fz, radius], index) => {
addMandarin(group, fx, fy, fz, radius, index * 1.7);
});
return group;
}
// Shared fruit plate in the center.
const sharedRoot = new THREE.Group();
sharedRoot.position.set(0, 0.01, 0);
scene.add(sharedRoot);
const sharedPlate = addPlate(sharedRoot, 0.68);
sharedPlate.position.y = 0.02;
const sharedSegments = new THREE.Group();
sharedSegments.position.y = 0.095;
sharedRoot.add(sharedSegments);
const pithRing = mesh(
new THREE.TorusGeometry(0.31, 0.018, 8, 36),
material.pith,
sharedSegments
);
pithRing.rotation.x = Math.PI / 2;
pithRing.position.y = 0.012;
const distributionRoot = new THREE.Group();
scene.add(distributionRoot);
function addCitrusWedge(parent, count, radius = 0.29) {
if (count <= 0) return;
const theta = Math.min((Math.PI * 2) / count, Math.PI * 1.2) * 0.72;
const geometry = new THREE.CylinderGeometry(
radius,
radius * 0.92,
0.09,
14,
1,
false,
-theta / 2,
theta
);
for (let i = 0; i < count; i++) {
const a = (i / count) * Math.PI * 2 + 0.16;
const wedge = mesh(
geometry,
[material.orangeSide, material.orangeLight, material.orangeSide],
parent
);
wedge.position.y = 0.04;
wedge.rotation.y = a;
wedge.scale.y = 0.95 + (i % 2) * 0.06;
}
}
function addPlateSegments(parent, count) {
if (count <= 0) return;
const columns = count <= 6 ? count : Math.ceil(Math.sqrt(count * 1.45));
const rows = Math.ceil(count / columns);
const radius = count > 9 ? 0.082 : 0.105;
const spacing = count > 9 ? 0.165 : 0.19;
const wedgeGeometry = new THREE.CylinderGeometry(
radius,
radius * 0.91,
0.075,
12,
1,
false,
-1.15,
2.3
);
for (let i = 0; i < count; i++) {
const row = Math.floor(i / columns);
const col = i % columns;
const rowCount = Math.min(columns, count - row * columns);
const x = (col - (rowCount - 1) / 2) * spacing;
const z = (row - (rows - 1) / 2) * spacing * 0.88;
const wedge = mesh(
wedgeGeometry,
[material.orangeSide, material.orangeLight, material.orangeSide],
parent
);
wedge.position.set(x, 0.052, z);
wedge.rotation.y = (i * 1.37) % (Math.PI * 2);
}
}
function addVisitor(parent, x, z, color, index) {
const group = new THREE.Group();
group.position.set(x, 0.01, z);
group.lookAt(0, 0.01, 0);
parent.add(group);
const shirt = new THREE.MeshStandardMaterial({ color, roughness: 0.86 });
const trousers = new THREE.MeshStandardMaterial({
color: index % 2 ? 0x52657a : 0x5a6255,
roughness: 0.95
});
const skin = new THREE.MeshStandardMaterial({
color: [0xe9b58c, 0xb97853, 0xd79b74, 0x8f5e42, 0xe3aa7f, 0xc88a63][index],
roughness: 0.9
});
const hair = new THREE.MeshStandardMaterial({
color: [0x3d2e25, 0x7a4d2f, 0x302b2a, 0x93613d, 0x5a382a, 0x2f2927][index],
roughness: 1
});
const torso = mesh(new THREE.CapsuleGeometry(0.22, 0.32, 5, 10), shirt, group);
torso.position.set(0, 0.77, 0);
torso.scale.z = 0.82;
const head = mesh(new THREE.SphereGeometry(0.185, 16, 12), skin, group);
head.position.set(0, 1.27, 0.015);
const hairCap = mesh(new THREE.SphereGeometry(0.19, 14, 10), hair, group);
hairCap.position.set(0, 1.36, -0.025);
hairCap.scale.set(1, 0.58, 0.94);
const nose = mesh(new THREE.SphereGeometry(0.035, 8, 6), skin, group);
nose.position.set(0, 1.26, 0.19);
nose.scale.set(0.8, 0.8, 1.2);
[-1, 1].forEach((side) => {
const leg = mesh(new THREE.CapsuleGeometry(0.095, 0.38, 4, 8), trousers, group);
leg.position.set(side * 0.13, 0.31, 0.09);
leg.rotation.x = 1.1;
const shoe = mesh(new THREE.SphereGeometry(0.105, 10, 7), material.cream, group);
shoe.scale.set(0.75, 0.55, 1.45);
shoe.position.set(side * 0.14, 0.105, 0.29);
const arm = mesh(new THREE.CapsuleGeometry(0.065, 0.34, 4, 8), shirt, group);
arm.position.set(side * 0.29, 0.72, 0.08);
arm.rotation.z = side * -0.42;
arm.rotation.x = 0.42;
const hand = mesh(new THREE.SphereGeometry(0.072, 9, 7), skin, group);
hand.position.set(side * 0.37, 0.53, 0.22);
});
return group;
}
// Fixed picnic props.
addBasket(scene, -2.65, -1.55, 0.92, 0.22);
addBasket(scene, 2.65, -1.72, 0.74, -0.28);
addCup(scene, -1.45, 1.82, 0.3, 0.92);
addCup(scene, 1.47, 1.75, -0.3, 0.92);
addCup(scene, 0.05, -2.1, 0, 0.82);
addMandarin(scene, -1.12, 0.12, 1.95, 0.2, 0.5);
addMandarin(scene, -0.78, 0.12, 2.03, 0.19, 1.2);
addMandarin(scene, 1.1, 0.12, 2.03, 0.2, 2.1);
const visitorNames = ["Mara", "Theo", "Inez", "Arlo", "June", "Finn"];
const visitorColors = [0xe06d52, 0x5f8e78, 0xe3ac46, 0x7a7faa, 0xc7788b, 0x5f91a2];
const visitorList = document.querySelector("#visitorList");
const visitorCountLabel = document.querySelector("#visitorCount");
const segmentRange = document.querySelector("#segmentRange");
const segmentTotalLabel = document.querySelector("#segmentTotal");
const remainingCountLabel = document.querySelector("#remainingCount");
const fruitTagCount = document.querySelector("#fruitTagCount");
const fruitTag = document.querySelector("#fruit-tag");
const visitorsMinus = document.querySelector("#visitorsMinus");
const visitorsPlus = document.querySelector("#visitorsPlus");
let visitorCount = 4;
let totalSegments = 30;
function disposeGroup(group) {
group.traverse((object) => {
if (object.geometry) object.geometry.dispose();
});
group.clear();
}
function updateDistribution() {
const perVisitor = Math.floor(totalSegments / visitorCount);
const remaining = totalSegments - perVisitor * visitorCount;
segmentTotalLabel.textContent = totalSegments;
visitorCountLabel.textContent = visitorCount;
remainingCountLabel.textContent = remaining;
fruitTagCount.textContent = remaining === 1 ? "1 segment left" : `${remaining} segments left`;
segmentRange.style.setProperty(
"--range-fill",
`${((totalSegments - Number(segmentRange.min)) /
(Number(segmentRange.max) - Number(segmentRange.min))) * 100}%`
);
visitorsMinus.disabled = visitorCount <= 2;
visitorsPlus.disabled = visitorCount >= 6;
visitorList.innerHTML = visitorNames
.slice(0, visitorCount)
.map(
(name, index) => `
<div class="visitor-item">
<span class="visitor-dot" style="--dot:#${visitorColors[index].toString(16).padStart(6, "0")}"></span>
<span class="visitor-name">${name}</span>
<span class="visitor-share"><strong>${perVisitor}</strong> segments</span>
</div>
`
)
.join("");
disposeGroup(sharedSegments);
addCitrusWedge(sharedSegments, remaining, 0.29);
if (remaining === 0) {
const whole = addMandarin(sharedSegments, 0, 0.04, 0, 0.28, 0.3);
whole.scale.setScalar(0.88);
}
disposeGroup(distributionRoot);
const startAngle = 0.35;
for (let i = 0; i < visitorCount; i++) {
const angle = startAngle + (i / visitorCount) * Math.PI * 2;
const plateX = Math.sin(angle) * 1.86;
const plateZ = Math.cos(angle) * 1.86;
const visitorX = Math.sin(angle) * 3.25;
const visitorZ = Math.cos(angle) * 3.25;
const plate = addPlate(distributionRoot, 0.55);
plate.position.set(plateX, 0.018, plateZ);
plate.rotation.y = angle;
const segments = new THREE.Group();
segments.position.set(plateX, 0.1, plateZ);
segments.rotation.y = angle;
distributionRoot.add(segments);
addPlateSegments(segments, perVisitor);
addVisitor(distributionRoot, visitorX, visitorZ, visitorColors[i], i);
const tangentX = Math.cos(angle) * 0.55;
const tangentZ = -Math.sin(angle) * 0.55;
addCup(
distributionRoot,
plateX + tangentX,
plateZ + tangentZ,
angle + Math.PI / 2,
0.72
);
}
}
visitorsMinus.addEventListener("click", () => {
visitorCount = Math.max(2, visitorCount - 1);
updateDistribution();
});
visitorsPlus.addEventListener("click", () => {
visitorCount = Math.min(6, visitorCount + 1);
updateDistribution();
});
segmentRange.addEventListener("input", (event) => {
totalSegments = Number(event.target.value);
updateDistribution();
});
updateDistribution();
// Direct, dependency-free camera controls.
function updateCamera() {
currentYaw += (desiredYaw - currentYaw) * 0.09;
currentPitch += (desiredPitch - currentPitch) * 0.09;
currentRadius += (desiredRadius - currentRadius) * 0.09;
const sinPitch = Math.sin(currentPitch);
camera.position.set(
cameraTarget.x + currentRadius * sinPitch * Math.sin(currentYaw),
cameraTarget.y + currentRadius * Math.cos(currentPitch),
cameraTarget.z + currentRadius * sinPitch * Math.cos(currentYaw)
);
camera.lookAt(cameraTarget);
}
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
let activePointer = null;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
activePointer = event.pointerId;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointer) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
desiredYaw -= dx * 0.006;
desiredPitch = THREE.MathUtils.clamp(desiredPitch + dy * 0.004, 0.48, 1.34);
});
function endDrag(event) {
if (event.pointerId !== activePointer) return;
dragging = false;
activePointer = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius + event.deltaY * 0.007,
7.2,
15.5
);
},
{ passive: false }
);
document.querySelector("#zoomIn").addEventListener("click", () => {
desiredRadius = Math.max(7.2, desiredRadius - 0.8);
});
document.querySelector("#zoomOut").addEventListener("click", () => {
desiredRadius = Math.min(15.5, desiredRadius + 0.8);
});
document.querySelector("#resetCamera").addEventListener("click", () => {
desiredYaw = 0.68;
desiredPitch = 1.02;
desiredRadius = 11.7;
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
const projectedTag = new THREE.Vector3();
const sharedLabelAnchor = new THREE.Vector3(0.63, 0.78, 0.12);
function animate() {
requestAnimationFrame(animate);
updateCamera();
scene.updateMatrixWorld();
camera.updateMatrixWorld();
projectedTag.copy(sharedLabelAnchor).project(camera);
const visible = projectedTag.z > -1 && projectedTag.z < 1;
fruitTag.style.opacity = visible ? "1" : "0";
fruitTag.style.left = `${(projectedTag.x * 0.5 + 0.5) * window.innerWidth}px`;
fruitTag.style.top = `${(-projectedTag.y * 0.5 + 0.5) * window.innerHeight}px`;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```