Prompt specification
Build or customize the Three.js 3D scene "Narrow and wide bin comparison" 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: Narrow and wide bin comparison
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/narrow-and-wide-bin-comparison-x1798
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts histograms and bin boundaries. Show the same observations under two bin widths with a common axis; explain changed appearance without altering underlying data or implying new observations. Stylized solid forms.
Working Three.js Starter (narrow-and-wide-bin-comparison-x1798):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Same observations, two bin widths</title>
<style>
:root{
--ink:#23262b; --paper:#f6f1e7; --card:rgba(255,253,247,.93);
--coarse:#e2703a; --fine:#2f8f88; --rug:#e3a92f; --curve:#6b4a8f;
--muted:rgba(35,38,43,.62);
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden;background:var(--paper);color:var(--ink);
font-family:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;}
#c{position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none;cursor:grab}
#c:active{cursor:grabbing}
.ui{position:fixed;inset:0;pointer-events:none;z-index:5}
.card{pointer-events:auto;background:var(--card);border:1px solid rgba(35,38,43,.14);
border-radius:14px;box-shadow:0 12px 34px rgba(70,58,40,.13);backdrop-filter:blur(7px)}
#title{position:absolute;left:18px;top:16px;padding:14px 18px;max-width:390px}
#title h1{margin:0 0 5px;font-size:19px;letter-spacing:.2px}
#title p{margin:0;font-size:12.5px;color:var(--muted);line-height:1.45}
#panel{position:absolute;right:18px;top:16px;width:372px;max-width:calc(100vw - 36px);
padding:16px 18px 14px;max-height:calc(100vh - 32px);overflow:auto}
#panel h2{margin:0 0 8px;font-size:15.5px}
#panel p{margin:0 0 9px;font-size:12.8px;line-height:1.5;color:rgba(35,38,43,.86)}
#panel ul{margin:0 0 9px;padding-left:16px;font-size:12.8px;line-height:1.5;color:rgba(35,38,43,.86)}
#panel b{font-weight:650}
.legend{display:flex;flex-wrap:wrap;gap:6px 12px;margin:10px 0 8px}
.lg{display:flex;align-items:center;gap:6px;font-size:11.5px;color:rgba(35,38,43,.78)}
.sw{width:11px;height:11px;border-radius:3px;display:inline-block}
.stats{border-top:1px solid rgba(35,38,43,.12);padding-top:9px;margin-top:2px}
.srow{display:flex;align-items:flex-start;gap:7px;font-size:12.3px;line-height:1.45;margin:0 0 4px}
.srow.total{margin-top:6px;padding-top:6px;border-top:1px dashed rgba(35,38,43,.18)}
.foot{font-size:11.8px!important;color:var(--muted)!important;font-style:italic}
#controls{position:absolute;left:18px;bottom:16px;padding:13px 15px;width:372px;max-width:calc(100vw - 36px)}
.ctl{margin-bottom:9px}
.ctl-head{display:flex;align-items:center;gap:7px;font-size:12.6px;font-weight:600;margin-bottom:3px}
.ctl-head b{margin-left:auto;font-variant-numeric:tabular-nums}
.dot{width:10px;height:10px;border-radius:3px}
.sub{font-size:11.4px;color:var(--muted);margin-top:2px;font-variant-numeric:tabular-nums}
input[type=range]{width:100%;margin:2px 0 0;accent-color:#3c4149;cursor:pointer}
.presets{display:flex;flex-wrap:wrap;gap:6px;margin-top:9px;padding-top:9px;border-top:1px solid rgba(35,38,43,.12)}
button{font:inherit;font-size:11.6px;padding:5px 9px;border-radius:8px;border:1px solid rgba(35,38,43,.2);
background:rgba(255,255,255,.7);color:var(--ink);cursor:pointer}
button:hover{background:#fff;border-color:rgba(35,38,43,.4)}
#hint{position:absolute;left:50%;bottom:18px;transform:translateX(-50%);font-size:11.5px;color:var(--muted);
background:rgba(255,253,247,.7);padding:5px 12px;border-radius:20px;border:1px solid rgba(35,38,43,.1)}
@media (max-width:980px){
#title{max-width:calc(100vw - 36px)}
#panel{right:12px;left:12px;top:auto;bottom:12px;width:auto;max-height:44vh}
#controls{left:12px;right:12px;bottom:auto;top:96px;width:auto}
#hint{display:none}
}
</style>
</head>
<body>
<canvas id="c"></canvas>
<div class="ui">
<div id="title" class="card">
<h1>Same observations, two bin widths</h1>
<p>Both histograms plot the <b>identical 40 observations</b> on a common axis. Only the width of the bins changed.</p>
</div>
<div id="panel" class="card">
<h2>Why the shape changed — without changing the data</h2>
<p>Both panels show the <b>same 40 values</b>: the small gold ticks under each panel are those same individual points, and the bars in each panel still add up to <b>40</b>. No observation was added, moved, removed or duplicated — only the way the same points are <b>pooled into bins</b> changed.</p>
<ul>
<li><b>Coarse bins (left):</b> each bar averages several values, so the profile is smooth, wide and low, and small bumps are hidden.</li>
<li><b>Fine bins (right):</b> each bar pools fewer values, so the profile is more detailed and jagged, with shorter bars and the same total.</li>
</ul>
<p><b>Common axis:</b> identical value range 0–100 and an identical count scale (same gridlines in both panels), so heights are directly comparable. The purple curve — the smoothed shape of the same 40 points — is unchanged in both.</p>
<div class="legend">
<span class="lg"><i class="sw" style="background:var(--coarse)"></i>coarse bars</span>
<span class="lg"><i class="sw" style="background:var(--fine)"></i>fine bars</span>
<span class="lg"><i class="sw" style="background:var(--rug)"></i>the 40 observations</span>
<span class="lg"><i class="sw" style="background:var(--curve)"></i>same smoothed shape</span>
<span class="lg"><i class="sw" style="background:#b3372f"></i>mean (identical)</span>
</div>
<div class="stats" id="stats"></div>
<p class="foot">Bin width trades off smoothing against detail. It never changes the data.</p>
</div>
<div id="controls" class="card">
<div class="ctl">
<div class="ctl-head"><i class="dot" style="background:var(--coarse)"></i>Left panel · coarse bins <b id="valA">5</b></div>
<input id="binsA" type="range" min="2" max="24" step="1" value="5" />
<div class="sub" id="infoA"></div>
</div>
<div class="ctl">
<div class="ctl-head"><i class="dot" style="background:var(--fine)"></i>Right panel · fine bins <b id="valB">15</b></div>
<input id="binsB" type="range" min="2" max="24" step="1" value="15" />
<div class="sub" id="infoB"></div>
</div>
<div class="presets">
<button data-a="5" data-b="10">5 vs 10</button>
<button data-a="5" data-b="20">5 vs 20</button>
<button data-a="10" data-b="20">10 vs 20</button>
<button data-a="12" data-b="12">same width</button>
<button id="reset">reset view</button>
</div>
</div>
<div id="hint">drag to orbit · scroll to zoom</div>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ------------------------------------------------------------------ data */
const DATA = [6,9,12,14,16,18,20,21,23,25,26,28,29,31,32,34,35,36,38,39,
40,41,43,44,45,47,48,50,52,53,55,57,59,62,65,68,72,76,81,88];
const N = DATA.length, XMIN = 0, XMAX = 100;
const MEAN = DATA.reduce((a,b)=>a+b,0)/N;
/* -------------------------------------------------------------- constants */
const AXIS_H = 30, HALF = 40, SCALE = (HALF*2)/(XMAX-XMIN);
const BAR_DEPTH = 16;
const Z_WALL=-11.2, Z_FENCE=-9.6, Z_GRID=-10.5, Z_RAIL=10.2, Z_RUG=12.4, Z_MARK=13.4;
const C = {
ground:'#e9e1cf', plinth:'#ded4bf', wall:'#f3ecdd', grid:'#c9bda6',
rail:'#3c4149', rug:'#e3a92f', curve:'#6b4a8f', mean:'#b3372f',
coarse:'#e2703a', coarseDark:'#c25a2a', coarseAccent:'#9c4418',
fine:'#2f8f88', fineDark:'#256e69', fineAccent:'#134f4b'
};
const PANELS = [
{ id:'coarse', cx:-50, bins:5, mat:null, matDark:null, matAcc:null, group:null },
{ id:'fine', cx: 50, bins:15, mat:null, matDark:null, matAcc:null, group:null }
];
/* --------------------------------------------------------------- renderer */
const canvas = document.getElementById('c');
const renderer = new THREE.WebGLRenderer({ canvas, antialias:true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
const scene = new THREE.Scene();
scene.background = new THREE.Color('#f6f1e7');
scene.fog = new THREE.Fog('#f6f1e7', 340, 760);
const camera = new THREE.PerspectiveCamera(42, innerWidth/innerHeight, 1, 1200);
/* ---------------------------------------------------------------- lights */
scene.add(new THREE.HemisphereLight(0xffffff, 0xc3b39a, 0.85));
const key = new THREE.DirectionalLight(0xfff3df, 1.55);
key.position.set(-80, 120, 90);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.bias = -0.0009;
const sc = key.shadow.camera;
sc.left=-150; sc.right=150; sc.top=150; sc.bottom=-150; sc.near=20; sc.far=420;
scene.add(key);
const fill = new THREE.DirectionalLight(0xdde7ff, 0.34);
fill.position.set(110, 60, -80);
scene.add(fill);
/* -------------------------------------------------------------- materials */
function lam(color){ const m = new THREE.MeshLambertMaterial({color}); m.userData.shared = true; return m; }
const M = {
ground: lam(C.ground), plinth: lam(C.plinth), wall: lam(C.wall),
grid: lam(C.grid), rail: lam(C.rail), rug: lam(C.rug),
curve: lam(C.curve), mean: lam(C.mean)
};
PANELS[0].mat = lam(C.coarse); PANELS[0].matDark = lam(C.coarseDark); PANELS[0].matAcc = lam(C.coarseAccent);
PANELS[1].mat = lam(C.fine); PANELS[1].matDark = lam(C.fineDark); PANELS[1].matAcc = lam(C.fineAccent);
/* ------------------------------------------------------------ text labels */
function chip(text, o = {}){
const {bg='rgba(35,38,43,.88)', fg='#fdf8ee', worldH=2.2, pad=26, weight=650, fontPx=56} = o;
const font = `${weight} ${fontPx}px ui-sans-serif, system-ui, "Segoe UI", Roboto, Arial, sans-serif`;
const m = document.createElement('canvas').getContext('2d');
m.font = font;
const w = Math.ceil(m.measureText(text).width) + pad*2, h = fontPx + pad;
const cv = document.createElement('canvas'); cv.width = w; cv.height = h;
const ctx = cv.getContext('2d');
if (bg){
ctx.fillStyle = bg;
const r = h/2;
ctx.beginPath();
ctx.moveTo(r,0); ctx.lineTo(w-r,0); ctx.quadraticCurveTo(w,0,w,r); ctx.lineTo(w,h-r);
ctx.quadraticCurveTo(w,h,w-r,h); ctx.lineTo(r,h); ctx.quadraticCurveTo(0,h,0,h-r);
ctx.lineTo(0,r); ctx.quadraticCurveTo(0,0,r,0); ctx.closePath(); ctx.fill();
}
ctx.font = font; ctx.fillStyle = fg; ctx.textAlign='center'; ctx.textBaseline='middle';
ctx.fillText(text, w/2, h/2 + 2);
const tex = new THREE.CanvasTexture(cv);
tex.colorSpace = THREE.SRGBColorSpace; tex.minFilter = THREE.LinearFilter;
const sp = new THREE.Sprite(new THREE.SpriteMaterial({map:tex, transparent:true, depthTest:false, depthWrite:false}));
sp.scale.set(worldH * (w/h), worldH, 1);
sp.renderOrder = 20;
return sp;
}
function disposeMat(m){
if (m.userData && m.userData.shared) return;
if (m.map) m.map.dispose();
m.dispose();
}
function clearGroup(g){
[...g.children].forEach(child=>{
g.remove(child);
child.traverse(o=>{
if (o.geometry) o.geometry.dispose();
if (o.material) (Array.isArray(o.material)?o.material:[o.material]).forEach(disposeMat);
});
});
}
function box(g, w,h,d, x,y,z, mat, cast=true, recv=true){
const m = new THREE.Mesh(new THREE.BoxGeometry(w,h,d), mat);
m.position.set(x,y,z); m.castShadow = cast; m.receiveShadow = recv; g.add(m);
return m;
}
/* ------------------------------------------------------------- scene body */
const ground = new THREE.Mesh(new THREE.PlaneGeometry(900,900), M.ground);
ground.rotation.x = -Math.PI/2; ground.position.y = -1.25; ground.receiveShadow = true;
scene.add(ground);
PANELS.forEach(p=>{ p.group = new THREE.Group(); scene.add(p.group); });
/* one long rail at the top of the walls: a single, shared count scale */
const sharedBeam = box(scene, 180, 0.32, 0.34, 0, AXIS_H, -10.15, M.rail, false);
/* headline chip floating above both panels */
const headline = chip('the same 40 observations — only the bin width changes', {bg:'rgba(35,38,43,.9)', worldH:3.4});
headline.position.set(0, AXIS_H + 14.5, -6);
scene.add(headline);
/* ------------------------------------------------------------- histogram */
function computeBins(n){
const w = (XMAX - XMIN)/n;
const bins = [];
for (let i=0;i<n;i++) bins.push({e0:XMIN+i*w, e1:XMIN+(i+1)*w, count:0});
for (const v of DATA){
let idx = Math.floor((v - XMIN)/w);
if (idx >= n) idx = n-1; if (idx < 0) idx = 0;
bins[idx].count++;
}
return bins;
}
/* kernel density of the SAME data — identical curve in both panels */
function kde(x, h){
let s = 0;
for (const v of DATA){ const u = (x-v)/h; s += Math.exp(-0.5*u*u); }
return s/(N*h*Math.sqrt(2*Math.PI));
}
const KSAMP = [], KVAL = [];
for (let i=0;i<=140;i++){ const x = XMIN + (XMAX-XMIN)*i/140; KSAMP.push(x); KVAL.push(kde(x,7)); }
const KMAX = Math.max(...KVAL);
const KSCALE = (AXIS_H*0.84)/KMAX;
function buildPanel(p, yScale, gridMax, gridStep){
const g = p.group; clearGroup(g);
const cx = p.cx, toX = v => cx + (v - 50)*SCALE;
const bins = p.binsData, bw = (XMAX-XMIN)/p.bins;
/* plinth + back wall */
box(g, HALF*2 + 6, 1.2, 28, cx, -0.6, 0, M.plinth);
box(g, HALF*2, AXIS_H, 1.2, cx, AXIS_H/2, Z_WALL, M.wall, false);
/* shared count gridlines + count labels (identical in both panels) */
for (let c=0; c<=gridMax; c+=gridStep){
const y = c*yScale;
box(g, HALF*2, 0.16, 0.22, cx, y, Z_GRID, M.grid, false, false);
const lab = chip(String(c), {bg:'rgba(246,241,231,.92)', fg:'#4a4a52', worldH:1.7, pad:16, weight:600});
lab.position.set(cx - HALF - 3.4, y, Z_GRID);
g.add(lab);
}
/* bars (solid, alternating tones) */
bins.forEach((b,i)=>{
const w = bw*SCALE*0.88;
const x = toX((b.e0+b.e1)/2);
const h = b.count*yScale;
box(g, w, h, BAR_DEPTH, x, h/2, 0, i%2 ? p.matDark : p.mat);
if (p.bins <= 12){
const lab = chip(String(b.count), {bg:null, fg:'#2b2f36', worldH:1.9, pad:10, weight:700});
lab.position.set(x, h + 1.8, 9.2);
g.add(lab);
}
});
/* bin boundaries: fence posts on the wall plane + top/bottom rails */
for (let i=0;i<=p.bins;i++){
const e = XMIN + i*bw;
box(g, 0.34, AXIS_H, 0.34, toX(e), AXIS_H/2, Z_FENCE, p.matAcc, false, false);
}
box(g, HALF*2, 0.34, 0.34, cx, AXIS_H, Z_FENCE, p.matAcc, false, false);
box(g, HALF*2, 0.34, 0.34, cx, 0.17, Z_FENCE, p.matAcc, false, false);
/* front value axis: rail, ticks, labels (0-100 in both panels) */
box(g, HALF*2, 0.55, 1.1, cx, 0.28, Z_RAIL, M.rail);
for (let v=XMIN; v<=XMAX; v+=20){
box(g, 0.34, 1.1, 1.7, toX(v), 0.55, Z_RAIL + 0.6, M.rail, false, false);
const lab = chip(String(v), {bg:'rgba(246,241,231,.92)', fg:'#4a4a52', worldH:1.8, pad:16, weight:600});
lab.position.set(toX(v), -1.9, Z_RAIL + 0.9);
g.add(lab);
}
/* bin-width markers on the front edge */
for (let i=1;i<p.bins;i++){
const cone = new THREE.Mesh(new THREE.ConeGeometry(0.85, 1.7, 4), p.matAcc);
cone.rotation.x = Math.PI;
cone.position.set(toX(XMIN + i*bw), 1.15, Z_RAIL + 0.6);
cone.castShadow = true;
g.add(cone);
}
/* the individual observations — the SAME 40 ticks in both panels */
DATA.forEach(v=>{
box(g, 0.6, 0.6, 1.7, toX(v), 0.3, Z_RUG, M.rug, false, false);
});
/* "one bin = w wide" bracket under the first bin */
const b0 = bins[0];
const bx0 = toX(b0.e0), bx1 = toX(b0.e1);
box(g, bx1-bx0, 0.32, 0.5, (bx0+bx1)/2, 0.16, Z_MARK, p.matAcc, false, false);
box(g, 0.3, 1.5, 0.5, bx0, 0.6, Z_MARK, p.matAcc, false, false);
box(g, 0.3, 1.5, 0.5, bx1, 0.6, Z_MARK, p.matAcc, false, false);
const bwLab = chip(`one bin = ${bw.toFixed(1)} wide`, {bg:'rgba(35,38,43,.85)', worldH:1.7});
bwLab.position.set((bx0+bx1)/2, 2.6, Z_MARK);
g.add(bwLab);
/* mean marker — same value in both panels */
const cone = new THREE.Mesh(new THREE.ConeGeometry(1.0, 1.9, 4), M.mean);
cone.position.set(toX(MEAN), 1.35, Z_RAIL + 0.6);
cone.castShadow = true;
g.add(cone);
const meanLab = chip(`mean ${MEAN.toFixed(1)}`, {bg:'rgba(179,55,47,.92)', worldH:1.6});
meanLab.position.set(toX(MEAN), -1.9, Z_RAIL + 1.2);
g.add(meanLab);
/* the same smoothed shape, drawn in both panels */
const pts = KSAMP.map((x,i)=> new THREE.Vector3(toX(x), KVAL[i]*KSCALE, 8.5));
const curve = new THREE.Mesh(
new THREE.TubeGeometry(new THREE.CatmullRomCurve3(pts), 160, 0.34, 8, false), M.curve);
curve.castShadow = true;
g.add(curve);
const cLab = chip('same shape', {bg:'rgba(107,74,143,.92)', worldH:1.6});
cLab.position.set(toX(93), KVAL[140]*KSCALE + 1.9, 8.5);
g.add(cLab);
/* titles */
const t = chip(`${p.id === 'coarse' ? 'COARSE' : 'FINE'} BINS · ${p.bins}`, {bg:p.id==='coarse'?C.coarse:C.fine, worldH:3.1});
t.position.set(cx, AXIS_H + 9.2, -5);
g.add(t);
const s = chip(`bin width ${bw.toFixed(1)} · same 40 observations`, {bg:'rgba(255,253,247,.94)', fg:'#3c4149', worldH:2.0});
s.position.set(cx, AXIS_H + 6.1, -5);
g.add(s);
}
/* --------------------------------------------------------------- updating */
function update(){
PANELS.forEach(p => { p.binsData = computeBins(p.bins); p.tallest = Math.max(...p.binsData.map(b=>b.count)); });
const maxC = Math.max(...PANELS.map(p=>p.tallest));
const gridMax = Math.max(2, Math.ceil(maxC/2)*2);
const gridStep = gridMax <= 10 ? 1 : 2;
const yScale = AXIS_H/gridMax;
PANELS.forEach(p => buildPanel(p, yScale, gridMax, gridStep));
updateStats();
}
function updateStats(){
const [a,b] = PANELS;
document.getElementById('valA').textContent = a.bins;
document.getElementById('valB').textContent = b.bins;
document.getElementById('infoA').textContent =
`bin width ${(100/a.bins).toFixed(1)} · tallest bar ${a.tallest} · avg ${(N/a.bins).toFixed(1)} points/bin`;
document.getElementById('infoB').textContent =
`bin width ${(100/b.bins).toFixed(1)} · tallest bar ${b.tallest} · avg ${(N/b.bins).toFixed(1)} points/bin`;
document.getElementById('stats').innerHTML = `
<div class="srow"><i class="sw" style="background:var(--coarse)"></i>
<span><b>Coarse</b> — ${a.bins} bins, width ${(100/a.bins).toFixed(1)}, tallest bar ${a.tallest}.</span></div>
<div class="srow"><i class="sw" style="background:var(--fine)"></i>
<span><b>Fine</b> — ${b.bins} bins, width ${(100/b.bins).toFixed(1)}, tallest bar ${b.tallest}.</span></div>
<div class="srow total"><span>Each panel's bars add up to <b>${N}</b> — the same number of observations.
Finer bins split the same points more ways; they never add new ones.</span></div>`;
}
const sA = document.getElementById('binsA'), sB = document.getElementById('binsB');
sA.addEventListener('input', ()=>{ PANELS[0].bins = +sA.value; update(); });
sB.addEventListener('input', ()=>{ PANELS[1].bins = +sB.value; update(); });
document.querySelectorAll('.presets button[data-a]').forEach(btn=>{
btn.addEventListener('click', ()=>{
sA.value = btn.dataset.a; sB.value = btn.dataset.b;
PANELS[0].bins = +btn.dataset.a; PANELS[1].bins = +btn.dataset.b;
update();
});
});
/* --------------------------------------------------- camera (own controls) */
const view = { theta:0.40, phi:1.04, radius:238, target:new THREE.Vector3(0,16,0) };
const HOME = { theta:0.40, phi:1.04, radius:238 };
let dragging=false, px=0, py=0;
canvas.addEventListener('pointerdown', e=>{ dragging=true; px=e.clientX; py=e.clientY; canvas.setPointerCapture(e.pointerId); });
canvas.addEventListener('pointerup', e=>{ dragging=false; });
canvas.addEventListener('pointercancel', ()=>{ dragging=false; });
canvas.addEventListener('pointermove', e=>{
if (!dragging) return;
const dx = e.clientX - px, dy = e.clientY - py; px = e.clientX; py = e.clientY;
view.theta -= dx*0.006;
view.phi = THREE.MathUtils.clamp(view.phi - dy*0.005, 0.22, 1.46);
});
canvas.addEventListener('wheel', e=>{
e.preventDefault();
view.radius = THREE.MathUtils.clamp(view.radius * (1 + Math.sign(e.deltaY)*0.09), 120, 430);
}, {passive:false});
document.getElementById('reset').addEventListener('click', ()=>{
view.theta = HOME.theta; view.phi = HOME.phi; view.radius = HOME.radius;
});
/* --------------------------------------------------------------- resizing */
function resize(){
const w = innerWidth, h = innerHeight;
camera.aspect = w/h; camera.updateProjectionMatrix();
renderer.setSize(w,h);
}
addEventListener('resize', resize);
/* ------------------------------------------------------------------ loop */
const cur = { theta:view.theta, phi:view.phi, radius:view.radius };
renderer.setAnimationLoop(()=>{
cur.theta += (view.theta - cur.theta)*0.12;
cur.phi += (view.phi - cur.phi )*0.12;
cur.radius+= (view.radius- cur.radius)*0.12;
const s = Math.sin(cur.phi);
camera.position.set(
view.target.x + cur.radius*s*Math.sin(cur.theta),
view.target.y + cur.radius*Math.cos(cur.phi),
view.target.z + cur.radius*s*Math.cos(cur.theta));
camera.lookAt(view.target);
renderer.render(scene, camera);
});
resize();
update();
</script>
</body>
</html>
```