Prompt specification
Build or customize the Three.js 3D scene "Separate tectonic and water-level changes in a model" 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: Separate tectonic and water-level changes in a model
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/separate-tectonic-and-water-level-changes-in-a-model-x3064
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring the East African Rift's faults, lakes, and relief. Let users control slow fault displacement and short-term lake level independently. Show their different geometric effects and avoid compressing their real timescales into one misleading process. Low-poly.
Working Three.js Starter (separate-tectonic-and-water-level-changes-in-a-model-x3064):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>East African Rift — fault displacement vs lake level</title>
<style>
:root{
--bg:#080b0f; --panel:rgba(12,17,23,.88); --edge:rgba(255,255,255,.10);
--txt:#dde6ef; --dim:#8ea0b2; --teal:#49d6c8; --blue:#5aa9ff; --amber:#ffb454; --red:#ff7a6b;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden;background:var(--bg);color:var(--txt);
font:12.5px/1.5 "Inter",system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;
-webkit-font-smoothing:antialiased}
#app{position:fixed;inset:0}
#app canvas{display:block}
.panel{position:fixed;background:var(--panel);border:1px solid var(--edge);
border-radius:10px;backdrop-filter:blur(9px);box-shadow:0 10px 40px rgba(0,0,0,.55)}
/* ---- left control column ---- */
#ctl{left:12px;top:12px;bottom:12px;width:326px;overflow-y:auto;padding:13px 14px 16px}
#ctl::-webkit-scrollbar{width:7px}
#ctl::-webkit-scrollbar-thumb{background:rgba(255,255,255,.16);border-radius:4px}
h1{font-size:14px;margin:0 0 2px;letter-spacing:.2px}
.sub{color:var(--dim);font-size:11px;margin-bottom:11px}
.grp{border-top:1px solid var(--edge);padding:10px 0 4px}
.grp:first-of-type{border-top:none;padding-top:4px}
.gtitle{display:flex;align-items:baseline;gap:7px;font-weight:650;font-size:12.5px;margin-bottom:2px}
.gtitle .num{display:inline-grid;place-items:center;width:16px;height:16px;border-radius:50%;
font-size:10px;background:var(--teal);color:#06221f;font-weight:800}
.grp.lake .gtitle .num{background:var(--blue);color:#04162b}
.scale{font-weight:500;font-size:10.5px;color:var(--dim);letter-spacing:.3px}
.clocks{font-size:10.5px;color:var(--dim);margin:2px 0 8px}
.clocks b{color:var(--txt);font-weight:600}
label.ctl-l{display:flex;justify-content:space-between;margin:9px 0 3px;font-size:11.5px;color:var(--dim)}
label.ctl-l b{color:var(--txt);font-weight:600;font-variant-numeric:tabular-nums}
input[type=range]{width:100%;height:16px;-webkit-appearance:none;background:transparent;cursor:pointer}
input[type=range]::-webkit-slider-runnable-track{height:3px;background:rgba(255,255,255,.16);border-radius:3px}
input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;width:13px;height:13px;border-radius:50%;
background:var(--txt);margin-top:-5px;border:none;box-shadow:0 0 0 3px rgba(0,0,0,.45)}
.grp.lake input[type=range]::-webkit-slider-thumb{background:var(--blue)}
.grp.tect input[type=range]::-webkit-slider-thumb{background:var(--teal)}
.row{display:flex;align-items:center;gap:7px;margin:8px 0 2px;font-size:11.5px;color:var(--dim)}
.row input[type=checkbox]{accent-color:var(--teal);width:14px;height:14px}
.grp.lake .row input[type=checkbox]{accent-color:var(--blue)}
.row .val{margin-left:auto;color:var(--txt);font-variant-numeric:tabular-nums}
.readout{font-size:11.5px;color:var(--dim);margin-top:7px;border-left:2px solid var(--teal);
padding-left:8px;line-height:1.7}
.grp.lake .readout{border-left-color:var(--blue)}
.readout b{color:var(--txt);font-weight:600;font-variant-numeric:tabular-nums}
table.eff{width:100%;border-collapse:collapse;font-size:10.8px;margin-top:6px}
table.eff th,table.eff td{border-top:1px solid var(--edge);padding:4px 3px;text-align:left;vertical-align:top}
table.eff th{color:var(--dim);font-weight:600}
table.eff td:nth-child(2){color:var(--teal)}
table.eff td:nth-child(3){color:var(--blue)}
table.eff td:first-child{color:var(--dim)}
.note{font-size:10.6px;color:var(--dim);line-height:1.6;margin-top:9px;padding:8px 9px;
border-radius:7px;background:rgba(255,180,84,.07);border:1px solid rgba(255,180,84,.22)}
.note b{color:var(--amber)}
button{font:inherit;color:var(--txt);background:rgba(255,255,255,.08);border:1px solid var(--edge);
border-radius:6px;padding:5px 10px;cursor:pointer}
button:hover{background:rgba(255,255,255,.15)}
/* ---- top right legend ---- */
#legend{right:12px;top:12px;padding:9px 12px;font-size:11px;color:var(--dim)}
#legend b{color:var(--txt)}
#legend .sw{display:inline-block;width:16px;height:3px;border-radius:2px;vertical-align:middle;margin-right:6px}
#legend div{margin:3px 0}
/* ---- charts ---- */
#charts{right:12px;bottom:12px;padding:10px 12px 11px;width:452px}
#charts h2{font-size:11px;margin:0 0 5px;color:var(--dim);font-weight:600;letter-spacing:.3px}
#charts h2 span{color:var(--txt)}
canvas.cv{display:block;width:100%;border-radius:6px;background:rgba(0,0,0,.35)}
.two{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:8px}
#hud{position:fixed;left:352px;top:12px;font-size:11px;color:var(--dim);
background:var(--panel);border:1px solid var(--edge);border-radius:8px;padding:7px 11px}
#labels{position:fixed;inset:0;pointer-events:none}
.lbl{position:absolute;transform:translate(-50%,-50%);white-space:nowrap;font-size:11px;
padding:2px 7px;border-radius:5px;background:rgba(6,10,14,.62);border:1px solid rgba(255,255,255,.16);
text-shadow:0 1px 3px #000;pointer-events:none}
.lbl.lk{color:#9fd0ff;border-color:rgba(90,169,255,.45)}
.lbl.ft{color:#ffd39b;border-color:rgba(255,180,84,.45)}
.lbl.vt{color:#b9c8d6}
@media (max-width:1180px){#charts{display:none}}
</style>
</head>
<body>
<div id="app"></div>
<div id="labels"></div>
<div id="hud">drag orbit · wheel zoom · shift+drag pan · click terrain = move section</div>
<aside id="ctl" class="panel">
<h1>East African Rift</h1>
<div class="sub">Two independent processes, shown on <b>two separate clocks</b> — not one compressed event.</div>
<div class="grp tect">
<div class="gtitle"><span class="num">1</span> Fault displacement <span class="scale">tectonic · 10⁵–10⁶ yr</span></div>
<div class="clocks">clock: <b>1 s ≈ 50 000 yr</b> · rate: <b id="rateEcho">0.5 mm/yr</b></div>
<label class="ctl-l">Vertical offset, main bounding fault <b id="vOffset">1 320 m</b></label>
<input type="range" id="sOffset" min="0" max="3000" step="10" value="1320">
<label class="ctl-l">Slip rate <b id="vRate">0.5 mm/yr</b></label>
<input type="range" id="sRate" min="0.1" max="5" step="0.1" value="0.5">
<div class="row"><input type="checkbox" id="cTect"><label for="cTect">run tectonic clock</label><span class="val" id="tClock">4.20 Myr</span></div>
<div class="readout" id="tRead"></div>
</div>
<div class="grp lake">
<div class="gtitle"><span class="num">2</span> Lake level <span class="scale">hydrological · 10⁰–10¹ yr</span></div>
<div class="clocks">clock: <b>1 s ≈ 1 yr</b> · baseline levels are fixed reference datums</div>
<label class="ctl-l">Mean level anomaly <b id="vAnom">+0.00 m</b></label>
<input type="range" id="sAnom" min="-3" max="3" step="0.05" value="0">
<label class="ctl-l">Seasonal / interannual amplitude <b id="vAmp">0.8 m</b></label>
<input type="range" id="sAmp" min="0" max="2" step="0.05" value="0.8">
<label class="ctl-l">Cycle length <b id="vPeriod">4 yr</b></label>
<input type="range" id="sPeriod" min="1" max="12" step="1" value="4">
<div class="row"><input type="checkbox" id="cLake" checked><label for="cLake">run lake clock</label><span class="val" id="lClock">year 0.0</span></div>
<div class="readout" id="lRead"></div>
</div>
<div class="grp">
<div class="gtitle"><span class="num" style="background:#8899aa;color:#0b1016">≡</span> View & display</div>
<label class="ctl-l">Vertical exaggeration <b id="vExag">×4</b></label>
<input type="range" id="sExag" min="1" max="8" step="0.5" value="4">
<label class="ctl-l">Section station (along strike) <b id="vStation">x = −20 km</b></label>
<input type="range" id="sStation" min="-200" max="200" step="1" value="-20">
<div class="row"><input type="checkbox" id="cFaults" checked><label for="cFaults">fault traces & planes</label></div>
<div class="row"><input type="checkbox" id="cLabels" checked><label for="cLabels">labels</label></div>
<div class="row"><button id="btnReset">reset view</button></div>
</div>
<div class="grp">
<div class="gtitle" style="margin-bottom:5px">What each process does to the geometry</div>
<table class="eff">
<tr><th>quantity</th><th>fault disp.</th><th>lake level</th></tr>
<tr><td>rock elevation / scarps</td><td>changes, km</td><td>no change</td></tr>
<tr><td>basin shape & depth</td><td>changes</td><td>no change</td></tr>
<tr><td>water-surface elevation</td><td>no change</td><td>changes, m</td></tr>
<tr><td>shoreline & area</td><td>indirectly</td><td>directly</td></tr>
<tr><td>timescale</td><td>10⁵–10⁶ yr</td><td>10⁰–10¹ yr</td></tr>
</table>
<div class="note">
<b>Read this as two clocks, not one story.</b> Fault slip rebuilds the rock over
10⁵–10⁶ years; lake level oscillates over 10⁰–10¹ years — about five orders of
magnitude apart. The scene therefore runs them on separate time bases
(tectonic 1 s ≈ 50 000 yr, lake 1 s ≈ 1 yr) and no control lets a lake cycle
drive faulting. Relief is vertically exaggerated ×4 and the along-strike
distances are compressed; heights and timescales are the point.
</div>
</div>
</aside>
<div id="legend" class="panel">
<div><span class="sw" style="background:#ffb454"></span><b>Normal fault</b> traces (dip 60°)</div>
<div><span class="sw" style="background:#49d6c8"></span><b>Scarp</b> height — rock, from faulting</div>
<div><span class="sw" style="background:#5aa9ff"></span><b>Lake surface</b> — water, from level</div>
</div>
<div id="charts" class="panel">
<h2>Cross-section E–W at <span id="secTitle">x = −20 km</span> <span style="color:#49d6c8">scarp = rock</span> · <span style="color:#5aa9ff">surface = water</span></h2>
<canvas class="cv" id="cvSec" height="196"></canvas>
<div class="two">
<div><h2>Scarp height vs cumulative offset</h2><canvas class="cv" id="cvScarp" height="118"></canvas></div>
<div><h2>Lake area vs level anomaly</h2><canvas class="cv" id="cvArea" height="118"></canvas></div>
</div>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ============================================================
0. helpers
============================================================ */
const clamp=(v,a,b)=>v<a?a:v>b?b:v;
const lerp=(a,b,t)=>a+(b-a)*t;
const smoothstep=(e0,e1,x)=>{const t=clamp((x-e0)/(e1-e0||1e-9),0,1);return t*t*(3-2*t);};
function hash2(i,j){let n=(i|0)*374761393+(j|0)*668265263; n=(n^(n>>13))*1274126177; return ((n^(n>>16))>>>0)/4294967296;}
function noise2(x,y){
const xi=Math.floor(x),yi=Math.floor(y),xf=x-xi,yf=y-yi;
const u=xf*xf*(3-2*xf),v=yf*yf*(3-2*yf);
const a=hash2(xi,yi),b=hash2(xi+1,yi),c=hash2(xi,yi+1),d=hash2(xi+1,yi+1);
return (a+(b-a)*u)*(1-v)+(c+(d-c)*u)*v;
}
const fmtN=(v,d=0)=>v.toLocaleString('en-US',{minimumFractionDigits:d,maximumFractionDigits:d});
/* ============================================================
1. configuration & state
============================================================ */
const CFG={x0:-220,x1:220,z0:-75,z1:75,nx:240,nz:150,refOffset:1320,scarp:2.6};
const GX=CFG.nx+1, GZ=CFG.nz+1;
const DX=(CFG.x1-CFG.x0)/CFG.nx, DZ=(CFG.z1-CFG.z0)/CFG.nz;
const state={
offset:1320, // m — vertical offset on the main bounding fault
rate:0.5, // mm/yr
anom:0, // m — mean lake-level anomaly
amp:0.8, // m — seasonal amplitude
period:4, // yr — cycle length
runTect:false, runLake:true,
vExag:4, stationX:-20,
showFaults:true, showLabels:true,
phase:0
};
const TECT_YRS_PER_SEC=50000, LAKE_YRS_PER_SEC=1;
/* ---- along-strike geometry of the rift ---- */
const WCP=[ /* main (western) margin fault offset profile, metres */
[-220,350],[-214,700],[-120,700],[-100,260],[-86,220],[-76,300],[-66,700],[-56,1200],[-46,1320],
[-20,1320],[-8,1290],[8,1320],[18,900],[28,400],[40,320],[52,420],[64,900],[80,1420],
[130,1450],[150,1390],[214,1350],[220,900]];
const ECP=[ /* eastern splay (shelf) fault offset profile, metres */
[-220,133],[-214,266],[-120,265],[-100,100],[-86,84],[-76,114],[-66,266],[-56,456],[-46,500],
[-20,500],[-8,490],[8,500],[18,342],[28,152],[40,122],[52,160],[64,342],[80,540],
[130,551],[150,528],[214,513],[220,342]];
function interpCP(cp,x){
if(x<=cp[0][0])return cp[0][1];
const n=cp.length;
if(x>=cp[n-1][0])return cp[n-1][1];
for(let i=0;i<n-1;i++) if(x<=cp[i+1][0]){
const t=(x-cp[i][0])/(cp[i+1][0]-cp[i][0]); return cp[i][1]+t*(cp[i+1][1]-cp[i][1]);
}
return cp[n-1][1];
}
const axisZ=x=>4*Math.sin(x*0.02)+2*Math.sin(x*0.05);
const jogW=x=>2.5*smoothstep(-19,-15,x)-1.5*smoothstep(9,13,x)+3*smoothstep(31,35,x);
const jogS=x=>1.0*smoothstep(-13,-9,x)-1.0*smoothstep(15,19,x);
const jogE=x=>2.0*smoothstep(-23,-19,x)-2.5*smoothstep(7,11,x)+2.0*smoothstep(33,37,x);
const zwT=x=>axisZ(x)-(12+2.5*Math.sin(x*0.02))+jogW(x); // western margin fault
const zsT=x=>axisZ(x)+(5+1.5*Math.sin(x*0.03+1.2))+jogS(x); // eastern splay (shelf) fault
const zeT=x=>axisZ(x)+(13+2.5*Math.sin(x*0.018+0.6))+jogE(x);// eastern margin fault
const LAKES=[
{id:'turkana', name:'Lake Turkana', xMin:-220,xMax:-78, base:360, color:0x3f93a0, label:[-150,axisZ(-150)]},
{id:'tanganyika',name:'Lake Tanganyika',xMin:-75,xMax:32, base:770,color:0x1d4a76, label:[-20,axisZ(-20)]},
{id:'malawi', name:'Lake Malawi / Nyasa',xMin:45,xMax:220, base:474,color:0x22496f, label:[130,axisZ(130)]}
];
/* ============================================================
2. terrain field
============================================================ */
function baseElev(x,z){
let h=1250;
h-=450*smoothstep(-60,-170,x); // lower in the north (Turkana domain)
h+=300*smoothstep(60,180,x); // higher in the south (Malawi domain)
h+=850*smoothstep(-50,60,z); // asymmetric flanks: east higher than west
h+=130*(noise2(x*0.011,z*0.011)-0.5);
h+= 65*(noise2(x*0.038,z*0.038)-0.5);
h+= 26*(noise2(x*0.115,z*0.115)-0.5);
return h;
}
const wCol=new Float32Array(GX), eCol=new Float32Array(GX);
function computeCols(f){for(let i=0;i<GX;i++){const x=CFG.x0+i*DX;wCol[i]=interpCP(WCP,x)*f;eCol[i]=interpCP(ECP,x)*f;}}
function heightAt(x,z,i){
const s=CFG.scarp, W=wCol[i], E=eCol[i];
const zw=zwT(x), zs=zsT(x), ze=zeT(x);
const A=smoothstep(zw-s,zw+s,z); // east of western fault
const B=smoothstep(ze-s,ze+s,z); // east of eastern margin fault
const C=smoothstep(zs-s,zs+s,z); // east of shelf fault
const G=A*(1-B); // graben block
const drop=W*G + E*A*(1-C); // + shelf step inside the trough
return baseElev(x,z)-drop;
}
function elevColor(h,j){
let r,g,b;
if(h<-150){r=.13;g=.17;b=.24;} else if(h<150){r=.17;g=.25;b=.28;}
else if(h<450){r=.28;g=.36;b=.27;} else if(h<850){r=.44;g=.48;b=.29;}
else if(h<1250){r=.57;g=.53;b=.33;} else if(h<1700){r=.60;g:.50; b:.39;}
else if(h<2100){r=.66;g=.60;b=.53;} else {r=.77;g=.76;b=.73;}
const k=(j-.5)*0.075;
return [clamp(r+k,0,1),clamp(g+k*.8,0,1),clamp(b+k*.6,0,1)];
}
/* ============================================================
3. three.js scene
============================================================ */
const app=document.getElementById('app');
const renderer=new THREE.WebGLRenderer({antialias:true});
renderer.setPixelRatio(Math.min(devicePixelRatio,2));
renderer.setSize(innerWidth,innerHeight);
renderer.outputColorSpace=THREE.SRGBColorSpace;
app.appendChild(renderer.domElement);
const scene=new THREE.Scene();
const sky=document.createElement('canvas'); sky.width=4; sky.height=256;
const sctx=sky.getContext('2d');
const grad=sctx.createLinearGradient(0,0,0,256);
grad.addColorStop(0,'#1b2c40'); grad.addColorStop(.55,'#2f4557'); grad.addColorStop(1,'#5b5145');
sctx.fillStyle=grad; sctx.fillRect(0,0,4,256);
const skyTex=new THREE.CanvasTexture(sky); skyTex.colorSpace=THREE.SRGBColorSpace;
scene.background=skyTex;
scene.fog=new THREE.Fog(0x33404a,220,760);
const camera=new THREE.PerspectiveCamera(46,innerWidth/innerHeight,1,2400);
scene.add(new THREE.HemisphereLight(0xbcd6f0,0x3b3226,0.62));
const sun=new THREE.DirectionalLight(0xfff0d8,1.35); sun.position.set(-160,210,-120); scene.add(sun);
const rim=new THREE.DirectionalLight(0x7fa8d8,0.32); rim.position.set(180,90,150); scene.add(rim);
/* ---- terrain mesh ---- */
const heights=new Float32Array(GX*GZ);
const terrPos=new Float32Array(GX*GZ*3), terrCol=new Float32Array(GX*GZ*3);
const terrIdx=new Uint32Array(CFG.nx*CFG.nz*6);
{let k=0;for(let j=0;j<CFG.nz;j++)for(let i=0;i<CFG.nx;i++){
const a=j*GX+i,b=a+1,c=a+GX,d=c+1; terrIdx[k++]=a;terrIdx[k++]=c;terrIdx[k++]=b;terrIdx[k++]=b;terrIdx[k++]=c;terrIdx[k++]=d;}}
for(let j=0;j<GZ;j++)for(let i=0;i<GX;i++){const o=(j*GX+i)*3;terrPos[o]=CFG.x0+i*DX;terrPos[o+2]=CFG.z0+j*DZ;}
const terrGeo=new THREE.BufferGeometry();
terrGeo.setAttribute('position',new THREE.BufferAttribute(terrPos,3));
terrGeo.setAttribute('color',new THREE.BufferAttribute(terrCol,3));
terrGeo.setIndex(new THREE.BufferAttribute(terrIdx,1));
const terrMesh=new THREE.Mesh(terrGeo,new THREE.MeshLambertMaterial({vertexColors:true,flatShading:true}));
terrMesh.frustumCulled=false; scene.add(terrMesh);
/* ---- water meshes (one per lake, clipped against the terrain) ---- */
function makeWater(lake){
const i0=Math.max(0,Math.floor((lake.xMin-CFG.x0)/DX)), i1=Math.min(CFG.nx,Math.ceil((lake.xMax-CFG.x0)/DX));
const maxV=(i1-i0+1)*(GZ-1)*6;
const geo=new THREE.BufferGeometry();
const pos=new Float32Array(maxV*3);
geo.setAttribute('position',new THREE.BufferAttribute(pos,3)); geo.setDrawRange(0,0);
const m=new THREE.Mesh(geo,new THREE.MeshPhongMaterial({
color:lake.color,transparent:true,opacity:.88,shininess:90,specular:0x6a8baa,
flatShading:true,side:THREE.DoubleSide,depthWrite:false}));
m.frustumCulled=false; m.renderOrder=2; scene.add(m);
return {lake,mesh:m,pos,i0,i1,maxV};
}
const waterObjs=LAKES.map(makeWater);
/* ---- fault traces, dip markers, fault planes ---- */
const faultDefs=[
{name:'Western Rift Fault',trace:zwT,hanging:'E',color:0xffb454},
{name:'Eastern Rift Splay (shelf)',trace:zsT,hanging:'W',color:0xff9a3c},
{name:'Eastern Rift Margin Fault',trace:zeT,hanging:'W',color:0xffb454}
];
const faultVis=[];
for(const fd of faultDefs){
const n=120;
const lineGeo=new THREE.BufferGeometry();
lineGeo.setAttribute('position',new THREE.BufferAttribute(new Float32Array((n+1)*3),3));
const line=new THREE.Line(lineGeo,new THREE.LineBasicMaterial({color:fd.color,transparent:true,opacity:.95}));
line.frustumCulled=false; scene.add(line);
const planeGeo=new THREE.BufferGeometry();
const ppos=new Float32Array((n+1)*6);
planeGeo.setAttribute('position',new THREE.BufferAttribute(ppos,3));
const plane=new THREE.Mesh(planeGeo,new THREE.MeshBasicMaterial({color:fd.color,transparent:true,opacity:.16,side:THREE.DoubleSide,depthWrite:false}));
plane.frustumCulled=false; plane.renderOrder=1; scene.add(plane);
const teeth=new THREE.InstancedMesh(new THREE.ConeGeometry(1.5,4.5,4),new THREE.MeshBasicMaterial({color:fd.color}),34);
teeth.frustumCulled=false; scene.add(teeth);
faultVis.push({fd,line,lineGeo,plane,ppos,teeth});
}
/* ============================================================
4. rebuild pipeline
============================================================ */
function rebuildTerrain(){
const f=state.offset/CFG.refOffset;
computeCols(f);
for(let j=0;j<GZ;j++)for(let i=0;i<GX;i++){
const x=CFG.x0+i*DX, z=CFG.z0+j*DZ;
const h=heightAt(x,z,i);
const idx=j*GX+i, o=idx*3;
heights[idx]=h;
terrPos[o+1]=h/1000*state.vExag;
const c=elevColor(h,hash2(i*3,j*7));
terrCol[o]=c[0]; terrCol[o+1]=c[1]; terrCol[o+2]=c[2];
}
terrGeo.attributes.position.needsUpdate=true;
terrGeo.attributes.color.needsUpdate=true;
}
function hAt(x,z){
const i=clamp(Math.round((x-CFG.x0)/DX),0,CFG.nx);
const j=clamp(Math.round((z-CFG.z0)/DZ),0,CFG.nz);
return heights[j*GX+i];
}
/* clip one grid cell against a level; corners are [x,z,h] */
function clipCell(c,level){
const out=[];
for(let k=0;k<4;k++){
const a=c[k], b=c[(k+1)%4];
const ain=a[2]<=level, bin=b[2]<=level;
if(ain) out.push(a);
if(ain!==bin){const t=(level-a[2])/(b[2]-a[2]); out.push([a[0]+t*(b[0]-a[0]),a[1]+t*(b[1]-a[1]),level]);}
}
return out;
}
function rebuildWater(step=1){
const stats={};
for(const w of waterObjs){
const lake=w.lake, level=lake.base+currentAnom();
const i0=Math.max(0,Math.floor((lake.xMin-CFG.x0)/DX)), i1=Math.min(CFG.nx,Math.ceil((lake.xMax-CFG.x0)/DX));
let v=0, area=0, vol=0, dmax=0;
const p=w.pos;
for(let j=0;j<GZ-1;j+=step)for(let i=i0;i<i1;i+=step){
const i2=Math.min(i+step,i1), j2=Math.min(j+step,GZ-1);
const x0=CFG.x0+i*DX,x1=CFG.x0+i2*DX,z0=CFG.z0+j*DZ,z1=CFG.z0+j2*DZ;
const corners=[[x0,z0,heights[j*GX+i]],[x1,z0,heights[j*GX+i2]],[x1,z1,heights[j2*GX+i2]],[x0,z1,heights[j2*GX+i]]];
if(corners.every(c=>c[2]>level)) continue;
const poly=clipCell(corners,level);
if(poly.length<3) continue;
// area + volume of the clipped polygon
let a2=0,dep=0;
for(let k=0;k<poly.length;k++){
const p1=poly[k],p2=poly[(k+1)%poly.length];
a2+=p1[0]*p2[1]-p2[0]*p1[1]; dep+=level-p1[2];
}
const pa=Math.abs(a2)/2; area+=pa; vol+=pa*(dep/poly.length); dmax=Math.max(dmax,level-Math.min(...poly.map(p=>p[2])));
const y=level/1000*state.vExag+0.03;
for(let k=1;k<poly.length-1;k++){
const A=poly[0],B=poly[k],C=poly[k+1];
const tri=[[A[0],A[1]],[B[0],B[1]],[C[0],C[1]]];
for(const t of tri){ if(v>=w.maxV) break; p[v*3]=t[0]; p[v*3+1]=y; p[v*3+2]=t[1]; v++; }
}
}
w.mesh.geometry.setDrawRange(0,v);
w.mesh.geometry.attributes.position.needsUpdate=true;
stats[lake.id]={level,area,vol:vol/1000,dmax};
}
return stats;
}
function currentAnom(){ return state.anom + (state.runLake? state.amp*Math.sin(2*Math.PI*state.phase/state.period) : 0); }
function currentSeason(){ return state.runLake? state.amp*Math.sin(2*Math.PI*state.phase/state.period):0; }
function updateFaultVis(){
const n=120, s=CFG.scarp;
for(const fv of faultVis){
const {fd,lineGeo,ppos,teeth}=fv;
const lp=lineGeo.attributes.position.array;
const dipSign=fd.hanging==='E'?1:-1;
for(let k=0;k<=n;k++){
const x=lerp(CFG.x0+2,CFG.x1-2,k/n);
const z=fd.trace(x);
const h=hAt(x,z);
lp[k*3]=x; lp[k*3+1]=h/1000*state.vExag+0.25; lp[k*3+2]=z;
// fault plane: dip 60° from horizontal, into the hanging wall
const depth=9, run=depth/Math.tan(60*Math.PI/180)*dipSign;
const b=(k*6);
ppos[b]=x; ppos[b+1]=h/1000*state.vExag+0.2; ppos[b+2]=z;
ppos[b+3]=x; ppos[b+4]=(h-depth*1000)/1000*state.vExag; ppos[b+5]=z+run;
}
lineGeo.attributes.position.needsUpdate=true;
fv.plane.geometry.attributes.position.needsUpdate=true;
const m=new THREE.Matrix4(), q=new THREE.Quaternion(), e=new THREE.Euler();
for(let k=0;k<34;k++){
const x=lerp(CFG.x0+10,CFG.x1-10,k/33);
const z=fd.trace(x), h=hAt(x,z);
e.set(dipSign>0?Math.PI*0.17:-Math.PI*0.17,0,0);
q.setFromEuler(e);
m.compose(new THREE.Vector3(x,h/1000*state.vExag+1.2,z),q,new THREE.Vector3(1,1,1));
teeth.setMatrixAt(k,m);
}
teeth.instanceMatrix.needsUpdate=true;
teeth.visible=state.showFaults; fv.line.visible=state.showFaults; fv.plane.visible=state.showFaults;
}
}
/* ============================================================
5. labels
============================================================ */
const labelBox=document.getElementById('labels');
const labels=[];
function mkLabel(txt,cls){const d=document.createElement('div');d.className='lbl '+cls;d.textContent=txt;labelBox.appendChild(d);return d;}
const lakeLabels=LAKES.map(l=>mkLabel(l.name,'lk'));
const faultLabels=[
mkLabel('Western Rift Fault','ft'), mkLabel('Eastern Rift Splay','ft'), mkLabel('Eastern Rift Margin Fault','ft')];
const v3=new THREE.Vector3();
function placeLabels(){
if(!state.showLabels){labels.forEach(l=>l.style.display='none');return;}
const items=[];
LAKES.forEach((l,i)=>{
const [x,z]=l.label; items.push([lakeLabels[i],x,hAt(x,z)+2.0,z]);
});
const fx=[-40,-10,0];
faultDefs.forEach((fd,i)=>{
const x=fx[i], z=fd.trace(x); items.push([faultLabels[i],x,hAt(x,z)+3.2,z]);
});
for(const [el,x,h,z] of items){
v3.set(x,h/1000*state.vExag,z).project(camera);
if(v3.z>1||v3.z<-1){el.style.display='none';continue;}
el.style.display='block';
el.style.left=((v3.x*.5+.5)*innerWidth)+'px';
el.style.top=((-v3.y*.5+.5)*innerHeight)+'px';
}
}
/* ============================================================
6. camera controls (hand-rolled, no addons)
============================================================ */
const cam={tgt:new THREE.Vector3(-10,2,0),r:430,th:-2.30,ph:1.02};
const camT={tgt:new THREE.Vector3(-10,2,0),r:430,th:-2.30,ph:1.02};
let drag=false,px=0,py=0,pan=false;
const dom=renderer.domElement;
dom.addEventListener('pointerdown',e=>{drag=true;pan=e.shiftKey||e.button===2;px=e.clientX;py=e.clientY;dom.setPointerCapture(e.pointerId);});
dom.addEventListener('pointerup',e=>{drag=false;});
dom.addEventListener('pointermove',e=>{
if(!drag)return;
const dx=e.clientX-px, dy=e.clientY-py; px=e.clientX; py=e.clientY;
if(pan){
const s=camT.r*0.0016;
const right=new THREE.Vector3(Math.cos(camT.th),0,-Math.sin(camT.th));
const up=new THREE.Vector3().crossVectors(right,new THREE.Vector3(0,1,0)).normalize();
camT.tgt.addScaledVector(right,-dx*s).addScaledVector(up,dy*s);
}else{
camT.th-=dx*0.0045; camT.ph=clamp(camT.ph-dy*0.0035,0.18,1.45);
}
});
dom.addEventListener('wheel',e=>{e.preventDefault();camT.r=clamp(camT.r*Math.exp(e.deltaY*0.0011),40,900);},{passive:false});
dom.addEventListener('contextmenu',e=>e.preventDefault());
const ray=new THREE.Raycaster(), ndc=new THREE.Vector2();
dom.addEventListener('click',e=>{
ndc.set(e.clientX/innerWidth*2-1,-e.clientY/innerHeight*2+1);
ray.setFromCamera(ndc,camera);
const hit=ray.intersectObject(terrMesh,false)[0];
if(hit){ state.stationX=clamp(hit.point.x,-200,200); document.getElementById('sStation').value=state.stationX; syncUI(); drawSection(); }
});
function updateCamera(){
cam.tgt.lerp(camT.tgt,.12); cam.r=lerp(cam.r,camT.r,.14);
cam.th=lerp(cam.th,camT.th,.14); cam.ph=lerp(cam.ph,camT.ph,.14);
const s=Math.sin(cam.ph);
camera.position.set(cam.tgt.x+cam.r*s*Math.sin(cam.th),cam.tgt.y+cam.r*Math.cos(cam.ph),cam.tgt.z+cam.r*s*Math.cos(cam.th));
camera.lookAt(cam.tgt);
}
/* ============================================================
7. charts
============================================================ */
function fitCanvas(cv){const dpr=Math.min(devicePixelRatio,2);const w=cv.clientWidth,h=cv.clientHeight;
if(cv.width!==Math.round(w*dpr)||cv.height!==Math.round(h*dpr)){cv.width=Math.round(w*dpr);cv.height=Math.round(h*dpr);}
const ctx=cv.getContext('2d');ctx.setTransform(dpr,0,0,dpr,0,0);return {ctx,w,h};}
const ELEV_MIN=-600,ELEV_MAX=2700;
function drawSection(){
const cv=document.getElementById('cvSec'); if(!cv.clientWidth) return;
const {ctx,w,h}=fitCanvas(cv);
ctx.clearRect(0,0,w,h);
const X0=34,X1=w-8,YT=h-18,YB=10;
const zx=z=>X0+(z-CFG.z0)/(CFG.z1-CFG.z0)*(X1-X0);
const ey=e=>YB+(e-ELEV_MIN)/(ELEV_MAX-ELEV_MIN)*(YT-YB);
// grid
ctx.strokeStyle='rgba(255,255,255,.07)';ctx.lineWidth=1;ctx.font='9px system-ui';ctx.fillStyle='rgba(255,255,255,.35)';
for(let e=0;e<=2500;e+=500){const y=ey(e);ctx.beginPath();ctx.moveTo(X0,y);ctx.lineTo(X1,y);ctx.stroke();
ctx.textAlign='right';ctx.fillText(e+' m',X0-4,y+3);}
for(let z=-60;z<=60;z+=30){const x=zx(z);ctx.beginPath();ctx.moveTo(x,YB);ctx.lineTo(x,YT);ctx.stroke();}
// profile
const i=clamp(Math.round((state.stationX-CFG.x0)/DX),0,CFG.nx);
const prof=[];for(let j=0;j<GZ;j++){const z=CFG.z0+j*DZ;prof.push([z,heights[j*GX+i]]);}
// water fill
for(const lake of LAKES){
if(state.stationX<lake.xMin||state.stationX>lake.xMax)continue;
const L=lake.base+currentAnom(); let inside=false,start=0;
const pts=[];
for(let k=0;k<prof.length-1;k++){
const [z1,h1]=prof[k],[z2,h2]=prof[k+1];
if(!inside&&h1<=L){inside=true;start=z1;}
if(inside&&((h1<=L)!==(h2<=L))){
const t=(L-h1)/(h2-h1); const zc=z1+t*(z2-z1);
if(h1<=L)pts.push([zc,L]); else {pts.push([zc,L]);pts.push([zc,L]);}
inside=false;
}
}
// simple: fill contiguous below-level spans
let span=null;const spans=[];
for(let k=0;k<prof.length-1;k++){
const [z1,h1]=prof[k],[z2,h2]=prof[k+1];
if(h1<=L){if(!span){span=[z1,z2];}else span[1]=z2;}
else if(span){spans.push(span);span=null;}
}
if(span)spans.push(span);
ctx.fillStyle='rgba(90,169,255,.35)';
for(const [a,b] of spans){ctx.fillRect(zx(a),ey(L),zx(b)-zx(a),YT-ey(L));}
ctx.strokeStyle='#5aa9ff';ctx.lineWidth=1.4;
for(const [a,b] of spans){ctx.beginPath();ctx.moveTo(zx(a),ey(L));ctx.lineTo(zx(b),ey(L));ctx.stroke();}
}
// terrain
ctx.beginPath();ctx.moveTo(zx(prof[0][0]),YT);
for(const [z,e] of prof)ctx.lineTo(zx(z),ey(e));
ctx.lineTo(zx(prof[prof.length-1][0]),YT);ctx.closePath();
const g=ctx.createLinearGradient(0,YB,0,YT);
g.addColorStop(0,'#6b5c43');g.addColorStop(1,'#241f18');
ctx.fillStyle=g;ctx.fill();
ctx.strokeStyle='#c8b089';ctx.lineWidth=1.2;
ctx.beginPath();prof.forEach(([z,e],k)=>k?ctx.lineTo(zx(z),ey(e)):ctx.moveTo(zx(z),ey(e)));ctx.stroke();
// datum
ctx.setLineDash([3,3]);ctx.strokeStyle='rgba(255,255,255,.35)';
ctx.beginPath();ctx.moveTo(X0,ey(0));ctx.lineTo(X1,ey(0));ctx.stroke();ctx.setLineDash([]);
// faults
faultDefs.forEach(fd=>{
const z=fd.trace(state.stationX), e=hAt(state.stationX,z);
const sign=fd.hanging==='E'?1:-1, run=9/Math.tan(Math.PI/3)*sign;
ctx.strokeStyle='rgba(255,180,84,.85)';ctx.lineWidth=1.3;
ctx.beginPath();ctx.moveTo(zx(z),ey(e));ctx.lineTo(zx(z+run),YT);ctx.stroke();
});
// annotations: scarp (rock) in teal, lake surface (water) in blue
const zw=zwT(state.stationX);
const crest=hAt(state.stationX,zw-7), toe=hAt(state.stationX,zw+7);
const scarp=crest-toe;
if(scarp>5){
const px=zx(zw-3.4);
ctx.strokeStyle='#49d6c8';ctx.lineWidth=1.6;
ctx.beginPath();ctx.moveTo(px,ey(crest));ctx.lineTo(px,ey(toe));ctx.stroke();
ctx.beginPath();ctx.moveTo(px-3,ey(crest)+4);ctx.lineTo(px,ey(crest));ctx.lineTo(px+3,ey(crest)+4);
ctx.moveTo(px-3,ey(toe)-4);ctx.lineTo(px,ey(toe));ctx.lineTo(px+3,ey(toe)-4);ctx.stroke();
ctx.fillStyle='#49d6c8';ctx.textAlign='left';ctx.font='bold 10px system-ui';
ctx.fillText('scarp '+fmtN(scarp)+' m',px+5,(ey(crest)+ey(toe))/2+3);
}
for(const lake of LAKES){
if(state.stationX<lake.xMin||state.stationX>lake.xMax)continue;
const L=lake.base+currentAnom();
const zz=lake.id==='malawi'?60:lake.id==='turkana'?-50:5;
const px=zx(zz);
ctx.strokeStyle='#5aa9ff';ctx.lineWidth=1.6;
ctx.beginPath();ctx.moveTo(px,ey(0));ctx.lineTo(px,ey(L));ctx.stroke();
ctx.beginPath();ctx.moveTo(px-3,ey(L)-4);ctx.lineTo(px,ey(L));ctx.lineTo(px+3,ey(L)-4);ctx.stroke();
ctx.fillStyle='#5aa9ff';ctx.textAlign='right';ctx.font='bold 10px system-ui';
ctx.fillText('surface '+L.toFixed(1)+' m',px-5,ey(L)-4);
ctx.font='9px system-ui';ctx.fillStyle='rgba(255,255,255,.55)';
ctx.fillText(lake.name,px-5,ey(L)-16);
}
ctx.fillStyle='rgba(255,255,255,.4)';ctx.font='9px system-ui';ctx.textAlign='left';
ctx.fillText('W',X0,YT+12);ctx.textAlign='right';ctx.fillText('E',X1,YT+12);
ctx.textAlign='center';ctx.fillText('cross-strike distance (km) · schematic',(X0+X1)/2,YT+12);
document.getElementById('secTitle').textContent='x = '+Math.round(state.stationX)+' km';
}
function drawScarpChart(){
const cv=document.getElementById('cvScarp'); if(!cv.clientWidth)return;
const {ctx,w,h}=fitCanvas(cv); ctx.clearRect(0,0,w,h);
const maxOff=3000, maxS=2600, P=26;
const X=o=>P+(o/maxOff)*(w-P-8), Y=s=>h-16-(s/maxS)*(h-26);
ctx.strokeStyle='rgba(255,255,255,.08)';ctx.lineWidth=1;
for(let o=0;o<=maxOff;o+=1000){ctx.beginPath();ctx.moveTo(X(o),8);ctx.lineTo(X(o),h-16);ctx.stroke();}
ctx.strokeStyle='#49d6c8';ctx.lineWidth=1.8;ctx.beginPath();
ctx.moveTo(X(0),Y(0));ctx.lineTo(X(maxOff),Y(maxS*maxOff/3000*1.0));ctx.stroke();
ctx.fillStyle='#49d6c8';ctx.beginPath();ctx.arc(X(state.offset),Y(state.offset/3000*maxS),3.4,0,7);ctx.fill();
ctx.fillStyle='rgba(255,255,255,.5)';ctx.font='9px system-ui';ctx.textAlign='left';
ctx.fillText('offset 0–3 000 m →',P,h-4);
ctx.textAlign='right';ctx.fillText(Math.round(state.offset)+' m',w-8,12);
}
function drawAreaChart(){
const cv=document.getElementById('cvArea'); if(!cv.clientWidth)return;
const {ctx,w,h}=fitCanvas(cv); ctx.clearRect(0,0,w,h);
const pts=areaCurve; if(!pts.length)return;
const maxA=Math.max(...pts.map(p=>p.a))*1.12||1, P=26;
const X=o=>P+((o+3)/6)*(w-P-8), Y=a=>h-16-(a/maxA)*(h-26);
ctx.strokeStyle='rgba(255,255,255,.08)';ctx.lineWidth=1;
for(let o=-3;o<=3;o++){ctx.beginPath();ctx.moveTo(X(o),8);ctx.lineTo(X(o),h-16);ctx.stroke();}
ctx.strokeStyle='#5aa9ff';ctx.lineWidth=1.8;ctx.beginPath();
pts.forEach((p,k)=>k?ctx.lineTo(X(p.o),Y(p.a)):ctx.moveTo(X(p.o),Y(p.a)));ctx.stroke();
const cur=state.anom+currentSeason();
ctx.fillStyle='#5aa9ff';ctx.beginPath();ctx.arc(X(clamp(cur,-3,3)),Y(pts.reduce((s,p)=>s+p.a,0)/3/maxA*maxA*0+ (function(){let best=pts[0];for(const p of pts)if(Math.abs(p.o-cur)<Math.abs(best.o-cur))best=p;return best.a;})()),3.4,0,7);ctx.fill();
ctx.fillStyle='rgba(255,255,255,.5)';ctx.font='9px system-ui';ctx.textAlign='left';
ctx.fillText('level anomaly −3…+3 m',P,h-4);
ctx.textAlign='right';ctx.fillStyle='#5aa9ff';ctx.fillText('now '+(cur>=0?'+':'')+cur.toFixed(2)+' m',w-8,12);
}
let areaCurve=[];
function computeAreaCurve(){
areaCurve=[];
for(let o=-3;o<=3.001;o+=0.5){
const save=state.anom; state.anom=o;
const st=rebuildWater(2); let tot=0;
for(const k in st)tot+=st[k].area;
areaCurve.push({o,a:tot});
state.anom=save;
}
rebuildWater(1);
}
/* ============================================================
8. UI wiring
============================================================ */
const $=id=>document.getElementById(id);
let dirty=true, dirtyCharts=true;
function bind(id,key,fmt,after){
const el=$(id);
const upd=()=>{state[key]=parseFloat(el.value);if(fmt)$('v'+id.slice(1)).textContent=fmt(state[key]);if(after)after();dirty=true;};
el.addEventListener('input',upd); upd();
}
bind('sOffset','offset',v=>fmtN(v)+' m');
bind('sRate','rate',v=>v.toFixed(1)+' mm/yr',()=>{$('rateEcho').textContent=state.rate.toFixed(1)+' mm/yr';});
bind('sAnom','anom',v=>(v>=0?'+':'')+v.toFixed(2)+' m');
bind('sAmp','amp',v=>v.toFixed(2)+' m');
bind('sPeriod','period',v=>v.toFixed(0)+' yr');
bind('sExag','vExag',v=>'×'+v);
$('sStation').addEventListener('input',()=>{state.stationX=parseFloat($('sStation').value);syncUI();drawSection();});
$('cTect').addEventListener('change',()=>state.runTect=$('cTect').checked);
$('cLake').addEventListener('change',()=>state.runLake=$('cLake').checked);
$('cFaults').addEventListener('change',()=>{state.showFaults=$('cFaults').checked;dirty=true;});
$('cLabels').addEventListener('change',()=>state.showLabels=$('cLabels').checked);
$('btnReset').addEventListener('click',()=>{camT.tgt.set(-10,2,0);camT.r=430;camT.th=-2.30;camT.ph=1.02;});
function syncUI(){
$('sOffset').value=state.offset; $('vOffset').textContent=fmtN(state.offset)+' m';
$('sRate').value=state.rate; $('vRate').textContent=state.rate.toFixed(1)+' mm/yr'; $('rateEcho').textContent=state.rate.toFixed(1)+' mm/yr';
$('sAnom').value=state.anom; $('vAnom').textContent=(state.anom>=0?'+':'')+state.anom.toFixed(2)+' m';
$('sAmp').value=state.amp; $('vAmp').textContent=state.amp.toFixed(2)+' m';
$('sPeriod').value=state.period; $('vPeriod').textContent=state.period.toFixed(0)+' yr';
$('sExag').value=state.vExag; $('vExag').textContent='×'+state.vExag;
$('sStation').value=state.stationX; $('vStation').textContent='x = '+Math.round(state.stationX)+' km';
}
/* ============================================================
9. readouts
============================================================ */
function scarpAt(x){
const zw=zwT(x), ze=zeT(x);
const w=hAt(x,zw-7)-hAt(x,zw+7), e=hAt(x,ze+7)-hAt(x,ze-7);
return {w,e};
}
let lastStats={};
function updateReadouts(){
const Myr=state.offset/(state.rate)/1000;
$('tClock').textContent=Myr.toFixed(2)+' Myr';
const sc=scarpAt(state.stationX);
$('tRead').innerHTML=
'Vertical offset on the main fault: <b>'+fmtN(state.offset)+' m</b><br>'+
'At <b>'+state.rate.toFixed(1)+' mm/yr</b> that is <b>'+Myr.toFixed(2)+' Myr</b> of slip.<br>'+
'Rock response at section: west scarp <b>'+fmtN(sc.w)+' m</b>, east scarp <b>'+fmtN(sc.e)+' m</b>.<br>'+
'<span style="color:#8ea0b2">Changes rock elevation, basin depth and width.</span>';
const rows=LAKES.map(l=>{
const s=lastStats[l.id]; if(!s)return '';
return l.name.split(' /')[0]+': <b>'+s.level.toFixed(1)+' m</b> · '+fmtN(s.area)+' km² · '+fmtN(s.vol,1)+' km³';
}).join('<br>');
const season=currentSeason();
$('lClock').textContent='year '+state.phase.toFixed(1)+' / '+state.period;
$('lRead').innerHTML=rows+'<br>'+
'Seasonal term now: <b>'+(season>=0?'+':'')+season.toFixed(2)+' m</b> (mean '+(state.anom>=0?'+':'')+state.anom.toFixed(2)+' m).<br>'+
'<span style="color:#8ea0b2">Changes only the water surface, shoreline and area.</span>';
}
/* ============================================================
10. main loop
============================================================ */
rebuildTerrain();
let stats=rebuildWater(1); lastStats=stats;
updateFaultVis();
computeAreaCurve();
drawSection(); drawScarpChart(); drawAreaChart();
let last=performance.now(), acc=0, chartAcc=0;
renderer.setAnimationLoop(now=>{
const dt=Math.min((now-last)/1000,0.1); last=now;
// ---- two independent clocks ----
if(state.runTect){
state.offset=clamp(state.offset+state.rate/1000*TECT_YRS_PER_SEC*dt,0,3000);
$('sOffset').value=state.offset; $('vOffset').textContent=fmtN(state.offset)+' m';
dirty=true;
}
if(state.runLake){ state.phase=(state.phase+LAKE_YRS_PER_SEC*dt)%(state.period*10); }
// ---- rebuilds ----
if(dirty){
rebuildTerrain();
lastStats=rebuildWater(1);
updateFaultVis();
dirty=false; dirtyCharts=true;
}else if(state.runLake){
lastStats=rebuildWater(1); // water only: rock is untouched
}
if(dirtyCharts){ chartAcc+=dt; if(chartAcc>0.35){chartAcc=0;dirtyCharts=false;computeAreaCurve();drawSection();drawScarpChart();drawAreaChart();} }
updateCamera();
placeLabels();
updateReadouts();
renderer.render(scene,camera);
});
addEventListener('resize',()=>{
camera.aspect=innerWidth/innerHeight; camera.updateProjectionMatrix();
renderer.setSize(innerWidth,innerHeight);
drawSection();drawScarpChart();drawAreaChart();
});
</script>
</body>
</html>
```