{"app":"explainer","title":"Inside a Four-Stroke Engine","idea":"How does a four-stroke car engine turn fuel into motion?","facts":{"level":"general","focus":"Show the valves opening and closing in time with the piston"},"seed":1,"outline":{"title":"Inside a Four-Stroke Engine","summary":"An interactive glass cutaway of one engine cylinder you can rotate, slow down and step through, watching the piston, valves and crankshaft move in perfect timing.","palette":{"accent":"#ff8a3d","alt":"#4fb3ff","bg":"#101820","fg":"#e8ecef"},"look":"glass","parts":[{"name":"Engine Block","shape":"Translucent rectangular housing with a cylindrical bore cut through its center, the largest part, pale blue-gray glass-like material"},{"name":"Piston","shape":"Short solid cylinder (puck) fitting snugly inside the bore, about 1/8 the bore's height, brushed silver metal with a darker rim"},{"name":"Connecting Rod","shape":"Slim flattened box linking the piston's underside to the crankshaft, about 1/4 the bore's length, dark steel gray"},{"name":"Crankshaft","shape":"Horizontal cylinder with one offset cylindrical lobe the rod attaches to, spans the block's base, polished steel gray"},{"name":"Camshaft","shape":"Thin horizontal cylinder with two teardrop-shaped lobes above the valves, about 1/3 the bore's width, dark matte metal"},{"name":"Intake Valve","shape":"Slim vertical stem topped with a small flat disc like a mushroom, about 1/6 the bore's height, light blue"},{"name":"Exhaust Valve","shape":"Slim vertical stem topped with a small flat disc, mirrored opposite the intake valve, warm orange"},{"name":"Spark Plug","shape":"Tiny cylinder with a thin metal electrode poking into the top of the bore, white ceramic body with a silver tip"}],"steps":[{"title":"Meet the Cylinder","caption":"One engine cylinder holds a piston, two valves, a spark plug, and the shafts that time everything together.","focus":["Engine Block","Piston","Intake Valve","Exhaust Valve","Spark Plug"],"motion":"Camera slowly orbits the transparent block while all parts sit still, labels fade in on each one in turn."},{"title":"Intake Stroke","caption":"The piston slides down, the intake valve opens, and a fresh mix of air and fuel gets pulled into the cylinder.","focus":["Piston","Intake Valve","Camshaft"],"motion":"Camshaft lobe rotates to lift the intake valve open; piston drops to the bottom as the crankshaft turns a half-circle."},{"title":"Compression Stroke","caption":"Both valves shut tight, and the rising piston squeezes the air-fuel mixture into a small, high-pressure pocket.","focus":["Piston","Intake Valve","Exhaust Valve"],"motion":"Both valves snap closed and stay flat; piston rises back to the top while the crankshaft completes another half-turn."},{"title":"Power Stroke","caption":"The spark plug fires, the compressed mixture ignites, and the expanding gas slams the piston back down with force.","focus":["Spark Plug","Piston","Connecting Rod","Crankshaft"],"motion":"Spark plug flashes bright orange; piston is punched downward fast, rod and crankshaft lobe spin with a visible speed burst."},{"title":"Exhaust Stroke","caption":"The exhaust valve opens and the rising piston pushes the spent, burned gases out of the cylinder to finish the cycle.","focus":["Piston","Exhaust Valve","Camshaft"],"motion":"Camshaft's second lobe lifts the exhaust valve open; piston rises to the top, pushing gas out before the cycle loops again."}]},"html":"<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n<title>Inside a Four-Stroke Engine</title>\n<style>\n:root{color-scheme:dark;--bg:#101820;--fg:#e8ecef;--accent:#ff8a3d;--alt:#4fb3ff;--muted:#a9bac6;--space:8px}\n*{box-sizing:border-box}html,body{width:100%;height:100%;margin:0;overflow:hidden}body{background:var(--bg);color:var(--fg);font-family:Gabarito,sans-serif}main{position:relative;width:100vw;height:100vh;height:100dvh;isolation:isolate}#scene{position:absolute;inset:0;touch-action:none}canvas{display:block;outline:none}header{position:absolute;z-index:2;left:clamp(20px,4vw,64px);top:clamp(20px,4vh,44px);max-width:530px;pointer-events:none}header:before{content:'';display:block;width:42px;height:3px;background:var(--accent);margin-bottom:16px;border-radius:2px}h1{font-family:'Bricolage Grotesque',sans-serif;font-size:clamp(25px,3vw,43px);font-weight:600;line-height:1.06;letter-spacing:-.045em;margin:0;max-width:440px;text-wrap:balance}header p{max-width:440px;color:var(--muted);font-size:14px;line-height:1.5;margin:14px 0 0;text-wrap:pretty}.orbit-hint{position:absolute;z-index:2;bottom:20px;left:clamp(20px,4vw,64px);display:flex;align-items:center;gap:10px;font-size:12px;letter-spacing:.02em;color:var(--muted);pointer-events:none}.orbit-hint svg{width:22px;height:22px;stroke:var(--alt);fill:none;stroke-width:1.4}.key{position:absolute;right:clamp(20px,4vw,64px);bottom:22px;display:flex;gap:18px;color:var(--muted);font-size:12px;pointer-events:none}.key span{display:flex;align-items:center;gap:7px}.key i{width:6px;height:6px;display:inline-block;background:var(--alt);border-radius:50%}.key span:last-child i{background:var(--accent)}#loading{position:absolute;left:50%;top:56%;transform:translate(-50%,-50%);font-size:13px;color:var(--muted);pointer-events:none;transition:opacity .3s}#loading.hidden{opacity:0} @media(max-width:600px){header{top:20px;left:20px;right:20px;max-width:310px}h1{font-size:28px;max-width:280px}header p{display:none}header:before{margin-bottom:12px;width:30px}.orbit-hint{bottom:17px;font-size:11px;left:16px}.key{bottom:19px;right:16px;gap:10px;font-size:11px}.orbit-hint svg{display:none}}@media(max-width:370px){.orbit-hint{max-width:140px;line-height:1.5}.key{gap:8px}}@media(max-height:520px){header{top:16px;left:20px;max-width:280px}h1{font-size:25px}header p{display:none}header:before{margin-bottom:10px}.orbit-hint,.key{bottom:12px}}@media(prefers-reduced-motion:reduce){#loading{transition:none}}\n</style>\n</head>\n<body>\n<main aria-label=\"Interactive four-stroke engine cutaway\">\n<div id=\"scene\" aria-label=\"Rotatable 3D engine showing timed piston and valve movement\"></div>\n<header><h1>Inside a Four-Stroke Engine</h1><p>An interactive glass cutaway of one engine cylinder you can rotate, slow down and step through, watching the piston, valves and crankshaft move in perfect timing.</p></header>\n<div id=\"loading\" role=\"status\">Preparing the cutaway…</div>\n<div class=\"orbit-hint\"><svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><ellipse cx=\"12\" cy=\"12\" rx=\"10\" ry=\"4.5\" transform=\"rotate(-30 12 12)\"/><path d=\"M12 2v4m0 12v4M2 12h4m12 0h4\"/></svg><span>Drag to rotate · Pinch or scroll to zoom</span></div>\n<div class=\"key\" aria-hidden=\"true\"><span><i></i>Intake</span><span><i></i>Exhaust</span></div>\n</main>\n<script type=\"module\">\nimport { stage, mat, geo, mesh, loadModel, ease, THREE } from 'popnow/three-kit';\nawait window.PN.ready;\nconst reducedMotion=window.matchMedia('(prefers-reduced-motion: reduce)').matches;\nconst host=document.getElementById('scene');\nconst s=stage({container:host,look:'glass',background:'#101820',fov:36,floor:true,controls:true,autoRotate:false});\nconst model=new THREE.Group();model.name='Four-Stroke Engine';\nconst parts={};\nconst C={blue:'#4fb3ff',orange:'#ff8a3d',silver:'#becbd4',steel:'#566978',dark:'#263945',glass:'#a8c6d6'};\nconst silver=mat.brushedMetal(C.silver),steel=mat.brushedMetal(C.steel),polished=mat.polishedMetal('#9aacb9'),dark=mat.mattePlastic(C.dark),rubber=mat.rubber('#27333d');\nconst blue=mat.polishedMetal(C.blue),orange=mat.polishedMetal(C.orange);\nconst glass=mat.cutaway(C.glass,{transparent:true,opacity:.19,depthWrite:false});\nconst headGlass=mat.cutaway('#c3d6df',{transparent:true,opacity:.27,depthWrite:false});\nfunction group(name,parent=model){const g=new THREE.Group();g.name=name;parent.add(g);return g}\nfunction part(name){const g=group(name);parts[name]=g;return g}\nfunction add(parent,name,geometry,material,x=0,y=0,z=0){const o=mesh(geometry,material,{name});o.position.set(x,y,z);parent.add(o);return o}\nfunction cylinder(parent,name,r,h,material,x,y,z,axis='y',bevel=.008){const o=add(parent,name,geo.bevelCylinder(r,h,Math.min(bevel,h*.22)),material,x,y,z);if(axis==='x')o.rotation.z=Math.PI/2;if(axis==='z')o.rotation.x=Math.PI/2;return o}\nfunction ringGeometry(outer,inner,h){return geo.lathe([[inner,-h/2],[outer-.006,-h/2],[outer,-h/2+.006],[outer,h/2-.006],[outer-.006,h/2],[inner,h/2],[inner,-h/2]])}\nfunction ring(parent,name,outer,inner,h,material,x,y,z,axis='y'){const o=add(parent,name,ringGeometry(outer,inner,h),material,x,y,z);if(axis==='x')o.rotation.z=Math.PI/2;if(axis==='z')o.rotation.x=Math.PI/2;return o}\nfunction roundedProfile(w,d,r){const q=new THREE.Shape(),x=-w/2,y=-d/2;q.moveTo(x+r,y);q.lineTo(x+w-r,y);q.quadraticCurveTo(x+w,y,x+w,y+r);q.lineTo(x+w,y+d-r);q.quadraticCurveTo(x+w,y+d,x+w-r,y+d);q.lineTo(x+r,y+d);q.quadraticCurveTo(x,y+d,x,y+d-r);q.lineTo(x,y+r);q.quadraticCurveTo(x,y,x+r,y);return q}\nfunction hole(shape,x,y,r){const p=new THREE.Path();p.absarc(x,y,r,0,Math.PI*2,true);shape.holes.push(p)}\nfunction piercedHousing(parent,name,w,d,h,top,holes,material){const shape=roundedProfile(w,d,.12);for(const a of holes)hole(shape,...a);const geometry=new THREE.ExtrudeGeometry(shape,{depth:h,steps:1,bevelEnabled:true,bevelSegments:2,bevelSize:.012,bevelThickness:.012,curveSegments:40});const o=add(parent,name,geometry,material,0,top,0);o.rotation.x=Math.PI/2;return o}\nconst base=group('Lower Crankcase');\nadd(base,'Bevelled engine foot',geo.roundedBox(1.65,.13,1.22,.055),steel,0,.075,0);\nadd(base,'Rear crankcase cutaway',geo.roundedBox(1.48,.76,.08,.045),glass,0,.53,-.58);\nfor(const x of [-.6,.6]){\n add(base,'Main bearing pedestal',geo.roundedBox(.19,.28,.42,.045),steel,x,.26,0);\n ring(base,'Main bearing collar',.185,.108,.17,polished,x,.43,0,'x');\n for(const z of [-.44,.44])add(base,'Foot retaining nut',geo.hexNut(.048,.035,.024),polished,x,.16,z);\n}\nconst block=part('Engine Block');\npiercedHousing(block,'Glass block with cylindrical bore',1.48,1.3,.92,1.96,[[0,0,.505]],glass);\nring(block,'Upper bore rim',.528,.499,.034,polished,0,1.96,0);\nring(block,'Lower bore rim',.528,.499,.035,steel,0,1.025,0);\nfor(const x of [-.625,.625])for(const z of [-.515,.515]){\n cylinder(block,'Block tie rod',.027,1.01,steel,x,1.5,z);\n add(block,'Cylinder head nut',geo.hexNut(.055,.05,.028),polished,x,2.064,z);\n ring(block,'Head nut washer',.066,.029,.015,steel,x,2.035,z);\n}\nfor(const y of [1.15,1.34,1.53,1.72])for(const x of [-.746,.746])add(block,'Cast cooling rib',geo.roundedBox(.034,.03,1.09,.012),mat.cutaway('#97bbc9',{transparent:true,opacity:.32,depthWrite:false}),x,y,0);\npiercedHousing(block,'Transparent cylinder head',1.48,1.3,.09,2.06,[[-.27,0,.169],[.27,0,.169],[0,.27,.055]],headGlass);\nfor(const x of [-.27,.27])ring(block,'Machined valve seat',.184,.15,.027,steel,x,1.962,0);\nconst piston=part('Piston');\ncylinder(piston,'Brushed piston crown',.472,.145,silver,0,.061,0);\ncylinder(piston,'Recessed piston skirt',.452,.112,silver,0,-.061,0);\nfor(const y of [.092,.054,.016])ring(piston,'Dark compression ring',.477,.459,.013,rubber,0,y,0);\ncylinder(piston,'Wrist pin',.052,.87,polished,0,0,0,'x');\nfor(const x of [-.439,.439])cylinder(piston,'Wrist pin end',.07,.019,steel,x,0,0,'x');\nconst crank=part('Crankshaft');crank.position.y=.43;\ncylinder(crank,'Polished main shaft',.102,1.72,polished,0,0,0,'x');\nfor(const x of [-.195,.195]){\n cylinder(crank,'Crank web',.312,.077,steel,x,.015,0,'x');\n add(crank,'Rounded counterweight',geo.roundedBox(.105,.245,.445,.075),polished,x,-.14,0);\n cylinder(crank,'Offset crankpin boss',.101,.085,polished,x,.29,0,'x');\n}\ncylinder(crank,'Offset crankpin',.071,.43,polished,0,.29,0,'x');\nfor(const x of [-.88,.88]){\n cylinder(crank,'Shaft end hub',.148,.065,steel,x,0,0,'x');\n const n=add(crank,'Shaft retaining nut',geo.hexNut(.081,.036,.035),polished,x+(x<0?-.045:.045),0,0);n.rotation.z=Math.PI/2;\n}\nadd(crank,'Crank timing mark',geo.roundedBox(.012,.07,.021,.005),mat.emissive(C.orange,.35),.922,.106,0);\nconst rod=part('Connecting Rod');const rodLength=.96;\nadd(rod,'Forged connecting rod',geo.roundedBox(.108,rodLength,.094,.032),steel,0,0,0);\nadd(rod,'Raised connecting rod rib',geo.roundedBox(.045,rodLength-.17,.117,.018),silver,0,0,0);\nring(rod,'Big end bearing',.113,.071,.145,polished,0,-rodLength/2,0,'x');\nring(rod,'Small end bearing',.076,.052,.13,polished,0,rodLength/2,0,'x');\nfor(const z of [-.094,.094]){const n=add(rod,'Rod cap fastener',geo.hexNut(.029,.037,.013),silver,0,-rodLength/2-.012,z);n.rotation.z=Math.PI/2;}\nconst valves={};\nfunction makeValve(name,x,material){\n const g=part(name);g.position.x=x;\n cylinder(g,'Valve head',.155,.035,material,0,1.935,0);\n cylinder(g,'Valve head bevel',.127,.028,polished,0,1.957,0);\n cylinder(g,'Valve stem',.026,.44,polished,0,2.17,0);\n cylinder(g,'Valve spring retainer',.075,.035,material,0,2.384,0);\n cylinder(g,'Cam follower',.074,.032,steel,0,2.418,0);\n const fixed=group(name+' Guide',block);\n cylinder(fixed,'Valve guide',.054,.14,steel,x,2.146,0);\n ring(fixed,'Spring seat',.088,.046,.023,polished,x,2.208,0);\n const spring=add(fixed,'Return spring',geo.spring(.06,.165,6,.009),polished,x,2.298,0);\n valves[name]={g,spring};return g;\n}\nconst intake=makeValve('Intake Valve',-.27,blue);\nconst exhaust=makeValve('Exhaust Valve',.27,orange);\nconst ports=group('Cylinder Head Ports');\nadd(ports,'Intake passage',geo.tube([[-.95,2.12,0],[-.72,2.12,0],[-.48,2.11,0],[-.27,2.035,0]],.103),mat.cutaway(C.blue,{transparent:true,opacity:.3,depthWrite:false}));\nadd(ports,'Exhaust passage',geo.tube([[.27,2.035,0],[.48,2.11,0],[.72,2.12,0],[.95,2.12,0]],.103),mat.cutaway(C.orange,{transparent:true,opacity:.3,depthWrite:false}));\nring(ports,'Intake port lip',.124,.094,.043,blue,-.96,2.12,0,'x');\nring(ports,'Exhaust port lip',.124,.094,.043,orange,.96,2.12,0,'x');\nconst cam=part('Camshaft');cam.position.y=2.553;\ncylinder(cam,'Camshaft spindle',.055,1.41,steel,0,0,0,'x');\nfunction lobeGeometry(){const shape=new THREE.Shape();const n=96;for(let j=0;j<=n;j++){const a=j/n*Math.PI*2;const q=Math.max(0,(Math.cos(a)-Math.SQRT1_2)/(1-Math.SQRT1_2));const r=.099+.106*q*q;const x=r*Math.sin(a),y=r*Math.cos(a);if(j===0)shape.moveTo(x,y);else shape.lineTo(x,y)}shape.closePath();const g=new THREE.ExtrudeGeometry(shape,{depth:.092,bevelEnabled:true,bevelThickness:.007,bevelSize:.005,bevelSegments:2,steps:1,curveSegments:32});g.translate(0,0,-.046);g.rotateY(Math.PI/2);return g}\nconst lobeGeo=lobeGeometry();\nconst intakeLobe=group('Intake cam lobe',cam);intakeLobe.position.x=-.27;\nadd(intakeLobe,'Teardrop intake cam',lobeGeo,polished);\nconst exhaustLobe=group('Exhaust cam lobe',cam);exhaustLobe.position.x=.27;\nadd(exhaustLobe,'Teardrop exhaust cam',lobeGeo,polished);\nfor(const x of [-.61,.61]){\n cylinder(cam,'Camshaft journal',.082,.135,polished,x,0,0,'x');\n add(block,'Cam bearing tower',geo.roundedBox(.145,.43,.16,.035),steel,x,2.295,-.10);\n ring(block,'Cam bearing cap',.118,.082,.115,silver,x,2.553,0,'x');\n const nut=add(block,'Cam cap nut',geo.hexNut(.033,.025,.014),polished,x,2.677,0);\n}\nconst timing=group('Timing Drive');\nconst crankPulley=add(timing,'Crank timing pulley',geo.gear(20,.129,.058,.016,.055),steel,-.772,.43,0);crankPulley.rotation.y=Math.PI/2;\nconst camPulley=add(timing,'Cam timing pulley',geo.gear(40,.258,.058,.016,.055),steel,-.772,2.553,0);camPulley.rotation.y=Math.PI/2;\nconst beltPoints=[];for(let j=0;j<=24;j++){const a=j/24*Math.PI;beltPoints.push([-.81,2.553+.274*Math.sin(a),.274*Math.cos(a)])}for(let j=0;j<=24;j++){const a=Math.PI+j/24*Math.PI;beltPoints.push([-.81,.43+.145*Math.sin(a),.145*Math.cos(a)])}beltPoints.push(beltPoints[0]);\nadd(timing,'Synchronous timing belt',geo.tube(beltPoints,.018),rubber);\nconst timingDotMat=mat.mattePlastic('#778b98');\nfor(const pulley of [crankPulley,camPulley]){const r=pulley===crankPulley?.091:.203;const dot=mesh(geo.bevelCylinder(.021,.009,.002),timingDotMat,{name:'Timing pulley index'});dot.rotation.x=Math.PI/2;dot.position.set(0,r,.034);pulley.add(dot)}\nconst plug=part('Spark Plug');plug.position.set(0,0,-.27);\ncylinder(plug,'White ceramic insulator',.052,.17,mat.ceramic('#eef1ed'),0,2.223,0);\nfor(let j=0;j<4;j++)cylinder(plug,'Ceramic insulator rib',.06,.016,mat.ceramic('#eef1ed'),0,2.188+j*.027,0);\ncylinder(plug,'Plug terminal',.028,.045,polished,0,2.328,0);\nadd(plug,'Spark plug hex',geo.hexNut(.079,.055,.039),polished,0,2.114,0);\nadd(plug,'Threaded plug shell',geo.threadedRod(.042,.136,.018),steel,0,2.023,0);\ncylinder(plug,'Center electrode',.014,.066,polished,0,1.926,0);\nadd(plug,'Ground electrode',geo.tube([[.035,1.969,0],[.035,1.895,0],[.012,1.895,0]],.009),polished);\nconst sparkMat=mat.emissive(C.orange,2.2,{transparent:true,opacity:0,depthWrite:false});\nconst spark=add(plug,'Ignition glow',geo.capsule(.027,.014),sparkMat,0,1.899,0);spark.visible=false;\nconst chargeMat=mat.emissive(C.blue,.12,{transparent:true,opacity:.09,depthWrite:false});\nconst charge=add(model,'Working gas volume',geo.bevelCylinder(.442,1,.009),chargeMat,0,1.5,0);charge.visible=false;\nconst particles=group('Gas Flow Tracers');\nconst particleMat=mat.emissive(C.blue,.7,{transparent:true,opacity:.7,depthWrite:false});\nconst particleGeo=geo.capsule(.009,.012);const tracers=[];\nfor(let j=0;j<36;j++){const o=add(particles,'Gas flow tracer',particleGeo,particleMat);tracers.push(o)}particles.visible=false;\ns.add(model);s.fit(model,1.48);\nif(s.controls){s.controls.enableDamping=true;s.controls.autoRotateSpeed=.28;s.controls.minDistance=2.1;s.controls.maxDistance=11;s.controls.maxPolarAngle=Math.PI*.88;}\ns.camera.position.set(3.8,2.95,5.6);if(s.controls){s.controls.target.set(0,1.43,0);s.controls.update()}\ns.fit(model,1.48);\nconst steps=[\n{title:'Meet the Cylinder',caption:'One engine cylinder holds a piston, two valves, a spark plug, and the shafts that time everything together.',focus:['Engine Block','Piston','Intake Valve','Exhaust Valve','Spark Plug']},\n{title:'Intake Stroke',caption:'The piston slides down, the intake valve opens, and a fresh mix of air and fuel gets pulled into the cylinder.',focus:['Piston','Intake Valve','Camshaft']},\n{title:'Compression Stroke',caption:'Both valves shut tight, and the rising piston squeezes the air-fuel mixture into a small, high-pressure pocket.',focus:['Piston','Intake Valve','Exhaust Valve']},\n{title:'Power Stroke',caption:'The spark plug fires, the compressed mixture ignites, and the expanding gas slams the piston back down with force.',focus:['Spark Plug','Piston','Connecting Rod','Crankshaft']},\n{title:'Exhaust Stroke',caption:'The exhaust valve opens and the rising piston pushes the spent, burned gases out of the cylinder to finish the cycle.',focus:['Piston','Exhaust Valve','Camshaft']}\n];\nconst anchors={\n'Engine Block':{offset:[-88,4],anchor:[-.62,1.54,.57]},\n'Piston':{offset:[75,16],anchor:[.39,.07,.24]},\n'Intake Valve':{offset:[-85,-19],anchor:[0,2.17,0]},\n'Exhaust Valve':{offset:[82,-5],anchor:[0,2.19,0]},\n'Spark Plug':{offset:[47,-57],anchor:[0,2.31,0]},\n'Camshaft':{offset:[-52,-45],anchor:[-.12,.1,0]},\n'Connecting Rod':{offset:[75,5],anchor:[.075,0,.035]},\n'Crankshaft':{offset:[70,36],anchor:[.66,0,0]}\n};\nconst labels={};for(const [name,obj]of Object.entries(parts)){labels[name]=s.label(obj,name,anchors[name]);labels[name].visible=false}\nlet currentStep=0,simTime=0,speed=1,paused=false,orbitTouched=false;\nlet lastLabelMask='';\nfunction updateLabels(){const list=steps[currentStep].focus;const visibleNames=currentStep===0?list.slice(0,Math.min(list.length,1+Math.floor(simTime/.65))):list;const key=visibleNames.join('|');if(key===lastLabelMask)return;lastLabelMask=key;for(const name in labels)labels[name].visible=visibleNames.includes(name)}\nfunction valveLift(camAngle,phase){const q=Math.max(0,(-Math.cos(camAngle+phase)-Math.SQRT1_2)/(1-Math.SQRT1_2));return .106*q*q}\nfunction updateValve(name,lift){const {g,spring}=valves[name];g.position.y=-lift;const length=.165-lift;spring.scale.y=length/.165;spring.position.y=2.216+length/2}\nconst intakePhase=3*Math.PI/4,exhaustPhase=-3*Math.PI/4;\nfunction sample(){\n let theta=0,progress=0,cycle=0;\n if(currentStep>0){const duration=currentStep===3?3.5:4.8;cycle=(simTime%duration)/duration;progress=THREE.MathUtils.clamp((cycle-.055)/.83,0,1);if(currentStep===3)progress=1-Math.pow(1-progress,2.05);theta=(currentStep-1)*Math.PI+progress*Math.PI;}\n const pinY=.43+.29*Math.cos(theta),pinZ=.29*Math.sin(theta);\n const pistonY=pinY+Math.sqrt(rodLength*rodLength-pinZ*pinZ);\n piston.position.y=pistonY;\n rod.position.set(0,(pinY+pistonY)/2,pinZ/2);rod.rotation.x=Math.atan2(-pinZ,pistonY-pinY);\n crank.rotation.x=theta;\n const camAngle=theta/2;\n intakeLobe.rotation.x=camAngle+intakePhase;exhaustLobe.rotation.x=camAngle+exhaustPhase;\n crankPulley.rotation.set(theta,Math.PI/2,0);camPulley.rotation.set(camAngle,Math.PI/2,0);\n const inLift=currentStep===1?valveLift(camAngle,intakePhase):0;\n const outLift=currentStep===4?valveLift(camAngle,exhaustPhase):0;\n updateValve('Intake Valve',inLift);updateValve('Exhaust Valve',outLift);\n const lower=pistonY+.143,upper=1.91,height=Math.max(.03,upper-lower);\n charge.position.y=lower+height/2;charge.scale.y=height;charge.visible=currentStep!==0;\n particles.visible=currentStep!==0;\n const gasColor=currentStep===3?C.orange:currentStep===4?'#c29577':C.blue;\n chargeMat.color.set(gasColor);if(chargeMat.emissive)chargeMat.emissive.set(gasColor);\n chargeMat.opacity=currentStep===2?.08+.18*progress:currentStep===3?.20-.11*progress:currentStep===4?.1*(1-progress):.08;\n particleMat.color.set(gasColor);if(particleMat.emissive)particleMat.emissive.set(gasColor);\n particleMat.opacity=currentStep===4?.6:.72;\n const ignition=currentStep===3?Math.max(0,1-cycle/.26):0;\n spark.visible=ignition>0;sparkMat.opacity=ignition*(reducedMotion?.65:.9);spark.scale.setScalar(1+ignition*1.6);\n for(let j=0;j<tracers.length;j++){\n  const o=tracers[j],seed=j*.61803398875,angle=j*2.39996323+simTime*.4,r=.085+.30*((j*13%31)/31);\n  let x=Math.cos(angle)*r,z=Math.sin(angle)*r,y=lower+.026+(height-.043)*((seed+simTime*.08)%1);\n  o.visible=true;\n  if(currentStep===1&&j<14){const u=(j/14+simTime*.6)%1;if(u<.45){const a=u/.45;x=-.98+.71*a;y=2.12-.24*a;z=.025*Math.sin(j*2)}else{const a=(u-.45)/.55;x=-.27*(1-a)+Math.cos(angle)*r*a;y=1.865+(lower+.035-1.865)*a;z=Math.sin(angle)*r*a}o.visible=inLift>.006&&progress<.98;}\n  if(currentStep===4){const u=(j/tracers.length+simTime*.55)%1;if(u>.45){const a=(u-.45)/.55;x=.27+.72*a;y=1.845+.275*Math.min(1,a*1.6);z=.035*Math.sin(j)}else{const a=u/.45;x=x*(1-a)+.27*a;y=y*(1-a)+1.84*a;z*=1-a}o.visible=outLift>.006&&j/tracers.length<1-progress*.65;}\n  o.position.set(x,y,z);o.scale.setScalar(currentStep===2?.9+progress*.3:1);\n }\n updateLabels();\n}\nfunction setStep(index){\n if(!Number.isFinite(index))return;currentStep=THREE.MathUtils.clamp(Math.trunc(index),0,steps.length-1);simTime=0;lastLabelMask='';sample();\n const selected=steps[currentStep].focus.map(name=>parts[name]);\n s.focus(selected,{color:currentStep>=3?C.orange:C.blue,dim:.32});\n if(s.controls)s.controls.autoRotate=currentStep===0&&!reducedMotion&&!orbitTouched;\n if(currentStep!==0){\n  model.updateMatrixWorld(true);\n  const box=new THREE.Box3();for(const object of selected)box.expandByObject(object);\n  const center=box.getCenter(new THREE.Vector3());center.x=0;center.z=0;center.y=THREE.MathUtils.clamp(center.y,1.28,1.68);\n  const aspect=host.clientWidth/Math.max(1,host.clientHeight);const distance=aspect<.8?6.9:5.55;\n  const direction=new THREE.Vector3(currentStep===3?2.8:3.5,1.5,5.8).normalize();const position=center.clone().addScaledVector(direction,distance);\n  s.flyTo({position:position.toArray(),target:center.toArray()},{duration:reducedMotion?0.01:1.1});\n }\n}\nhost.addEventListener('pointerdown',()=>{orbitTouched=true;if(s.controls)s.controls.autoRotate=false},{passive:true});\nhost.addEventListener('wheel',()=>{orbitTouched=true;if(s.controls)s.controls.autoRotate=false},{passive:true});\nsetStep(0);\ns.onFrame((dt)=>{simTime+=Math.min(dt,.06)*(paused?0:speed);sample()});\nwindow.PN.explainer({\n steps:steps.map(({title,caption})=>({title,caption})),\n setStep,\n setSpeed(x){if(Number.isFinite(x))speed=THREE.MathUtils.clamp(x,.1,2)},\n setPaused(p){paused=Boolean(p)},\n reset(){speed=1;paused=false;orbitTouched=false;setStep(0);s.fit(model,1.48)}\n});\nlet resizeTimer;window.addEventListener('resize',()=>{clearTimeout(resizeTimer);resizeTimer=setTimeout(()=>s.fit(model,1.48),140)},{passive:true});\ndocument.getElementById('loading').classList.add('hidden');\n</script>\n</body>\n</html>","notes":"Built a glass cutaway with synchronized piston, crankshaft, camshaft and valve motion, five guided views, and runtime-controlled playback.","provenance":"GPT 6 Astra (reasoning medium) via Atlas, PopNow code plan v2 with three-kit (outline by Claude Sonnet 5, 2026-11-11), 2026-11-12, unedited"}