[{"data":1,"prerenderedAt":450,"buildId":451},["ShallowReactive",2],{"doc-\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fstage-iterate":3,"github-stars":358,"guide-nav":360},{"id":4,"title":5,"body":6,"categoryId":341,"categorySlug":342,"categoryTitle":343,"curated":344,"description":345,"editUrl":346,"extension":347,"group":348,"groupTitle":349,"kind":350,"meta":351,"navigation":352,"path":353,"seo":354,"sourceUrl":355,"stem":356,"wordCount":346,"__hash__":357},"primitives\u002Fdocs\u002Fprimitives\u002F48.sim-grids\u002F6.stage-iterate.md","stage.iterate",{"type":7,"value":8,"toc":334},"minimark",[9,13,22,111,126,136,141,178,182,279,289,293,320,324,330],[10,11,5],"h1",{"id":12},"stageiterate",[14,15,16,17,21],"p",{},"Run a step ",[18,19,20],"code",{},"count"," times this frame.",[23,24,29],"pre",{"className":25,"code":26,"language":27,"meta":28,"style":28},"language-ts shiki shiki-themes github-dark","stage.iterate(opts: {count: (f: GridFrame) => number; step: (i: number, nodes: ComputeStep[], f: GridFrame) => void}): GridStage\n","ts","",[18,30,31],{"__ignoreMap":28},[32,33,36,40,44,47,49,52,56,60,63,66,69,72,75,77,81,84,87,89,92,95,97,99,101,103,105,108],"span",{"class":34,"line":35},"line",1,[32,37,39],{"class":38},"s95oV","stage.",[32,41,43],{"class":42},"svObZ","iterate",[32,45,46],{"class":38},"(opts: {",[32,48,20],{"class":42},[32,50,51],{"class":38},": (",[32,53,55],{"class":54},"s9osk","f",[32,57,59],{"class":58},"snl16",":",[32,61,62],{"class":42}," GridFrame",[32,64,65],{"class":38},") ",[32,67,68],{"class":58},"=>",[32,70,71],{"class":38}," number; step: (",[32,73,74],{"class":54},"i",[32,76,59],{"class":58},[32,78,80],{"class":79},"sDLfK"," number",[32,82,83],{"class":38},", ",[32,85,86],{"class":54},"nodes",[32,88,59],{"class":58},[32,90,91],{"class":42}," ComputeStep",[32,93,94],{"class":38},"[], ",[32,96,55],{"class":54},[32,98,59],{"class":58},[32,100,62],{"class":42},[32,102,65],{"class":38},[32,104,68],{"class":58},[32,106,107],{"class":58}," void",[32,109,110],{"class":38},"}): GridStage\n",[14,112,113,114,117,118,121,122,125],{},"Import ",[18,115,116],{},"sim"," from ",[18,119,120],{},"shaders\u002Fstd"," and use ",[18,123,124],{},"sim.grids.stage.iterate",".",[14,127,128,129,132,133,135],{},"Your ",[18,130,131],{},"step"," adds the pass for iteration ",[18,134,74],{}," and picks which buffer it reads and writes.",[137,138,140],"h2",{"id":139},"parameters","Parameters",[142,143,144,160],"table",{},[145,146,147],"thead",{},[148,149,150,154,157],"tr",{},[151,152,153],"th",{},"Name",[151,155,156],{},"Type",[151,158,159],{},"Notes",[161,162,163],"tbody",{},[148,164,165,171,176],{},[166,167,168],"td",{},[18,169,170],{},"opts",[166,172,173],{},[18,174,175],{},"{count: (f: GridFrame) => number; step: (i: number, nodes: ComputeStep[], f: GridFrame) => void}",[166,177],{},[137,179,181],{"id":180},"example","Example",[23,183,185],{"className":25,"code":184,"language":27,"meta":28,"style":28},"stage.iterate({count: (f) => Math.round(f.num('speed', 8)), step: (i, nodes) => nodes.push(react.with(i % 2 ? groupBA : groupAB))})\n",[18,186,187],{"__ignoreMap":28},[32,188,189,191,193,196,198,200,202,204,206,209,212,215,218,221,225,227,230,233,235,237,239,241,243,245,247,250,253,256,259,262,265,268,271,274,276],{"class":34,"line":35},[32,190,39],{"class":38},[32,192,43],{"class":42},[32,194,195],{"class":38},"({",[32,197,20],{"class":42},[32,199,51],{"class":38},[32,201,55],{"class":54},[32,203,65],{"class":38},[32,205,68],{"class":58},[32,207,208],{"class":38}," Math.",[32,210,211],{"class":42},"round",[32,213,214],{"class":38},"(f.",[32,216,217],{"class":42},"num",[32,219,220],{"class":38},"(",[32,222,224],{"class":223},"sU2Wk","'speed'",[32,226,83],{"class":38},[32,228,229],{"class":79},"8",[32,231,232],{"class":38},")), ",[32,234,131],{"class":42},[32,236,51],{"class":38},[32,238,74],{"class":54},[32,240,83],{"class":38},[32,242,86],{"class":54},[32,244,65],{"class":38},[32,246,68],{"class":58},[32,248,249],{"class":38}," nodes.",[32,251,252],{"class":42},"push",[32,254,255],{"class":38},"(react.",[32,257,258],{"class":42},"with",[32,260,261],{"class":38},"(i ",[32,263,264],{"class":58},"%",[32,266,267],{"class":79}," 2",[32,269,270],{"class":58}," ?",[32,272,273],{"class":38}," groupBA ",[32,275,59],{"class":58},[32,277,278],{"class":38}," groupAB))})\n",[280,281,282],"blockquote",{},[14,283,284,288],{},[285,286,287],"strong",{},"Tip."," A reaction-diffusion field reads smoother when you raise the iteration count than when you raise the step size.",[137,290,292],{"id":291},"see-also","See also",[294,295,296,307],"ul",{},[297,298,299,306],"li",{},[300,301,303],"a",{"href":302},"\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fstage-pass",[18,304,305],{},"stage.pass"," — One GPU pass, the same every frame.",[297,308,309,315,316,319],{},[300,310,312],{"href":311},"\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fstage-sortpass",[18,313,314],{},"stage.sortPass"," — A compare-and-swap sort that converges a little more every frame: ",[18,317,318],{},"passes"," swaps per frame, alternating odd and even pairs and the two buffers.",[137,321,323],{"id":322},"used-by","Used by",[14,325,326],{},[300,327,329],{"href":328},"\u002Fdocs\u002Fcomponents\u002Freactiondiffusion","ReactionDiffusion",[331,332,333],"style",{},"html pre.shiki code .s95oV, html code.shiki .s95oV{--shiki-default:#E1E4E8}html pre.shiki code .svObZ, html code.shiki .svObZ{--shiki-default:#B392F0}html pre.shiki code .s9osk, html code.shiki .s9osk{--shiki-default:#FFAB70}html pre.shiki code .snl16, html code.shiki .snl16{--shiki-default:#F97583}html pre.shiki code .sDLfK, html code.shiki .sDLfK{--shiki-default:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}",{"title":28,"searchDepth":335,"depth":335,"links":336},2,[337,338,339,340],{"id":139,"depth":335,"text":140},{"id":180,"depth":335,"text":181},{"id":291,"depth":335,"text":292},{"id":322,"depth":335,"text":323},"sim.grids","sim-grids","Grid programs",false,"Run a step `count` times this frame.",null,"md","simulation","Simulation","function",{},true,"\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fstage-iterate",{"title":5,"description":345},"https:\u002F\u002Fgithub.com\u002Fshader-effects-inc\u002Fshaders\u002Fblob\u002Fmain\u002Fpackages\u002Fcore\u002Fsrc\u002Fstd\u002Fsim\u002Fgrids.ts#L338","docs\u002Fprimitives\u002F48.sim-grids\u002F6.stage-iterate","cOM6dxIwEKE4YXliftXVJkFmmjET6qVOixu3rYTuBL8",{"stars":359},6080,[361,365,369,373,377,381,385,389,393,397,401,405,409,413,417,421,425,430,434,438,442,446],{"path":362,"title":363,"description":364,"category":18},"\u002Fdocs\u002Fguide","Getting started","Shaders is a desktop app where your AI agent designs interactive effects on an infinite canvas, and you shape them by hand.",{"path":366,"title":367,"description":368,"category":18},"\u002Fdocs\u002Fguide\u002Fquickstart","Quickstart","Install Shaders, render your first effect, and drive a prop from state.",{"path":370,"title":371,"description":372,"category":18},"\u002Fdocs\u002Fguide\u002Fcomposing-effects","Composing effects","Stack components as layers and nest them to control which layers an effect touches.",{"path":374,"title":375,"description":376,"category":18},"\u002Fdocs\u002Fguide\u002Fblending-masking","Blending and masking","Control how a layer mixes with the layers below it, and reveal one layer through another.",{"path":378,"title":379,"description":380,"category":18},"\u002Fdocs\u002Fguide\u002Fprops-reactivity","Props and reactivity","Bind props to your framework's state so effects update when it changes, and animate props with an animation library.",{"path":382,"title":383,"description":384,"category":18},"\u002Fdocs\u002Fguide\u002Fanimation","Animating a shader","Tween a shader's props with Motion, GSAP or anything else that animates a number.",{"path":386,"title":387,"description":388,"category":18},"\u002Fdocs\u002Fguide\u002Fdynamic-props","Dynamic props","Drive any numeric or position prop from time, the cursor, or another layer, without writing animation code.",{"path":390,"title":391,"description":392,"category":18},"\u002Fdocs\u002Fguide\u002Flayout-positioning","Layout and positioning","Size and place a shader in your page with CSS, as a background, a fill, or an inline block.",{"path":394,"title":395,"description":396,"category":18},"\u002Fdocs\u002Fguide\u002Fsizing-and-units","Sizing and units","Size and place layers in CSS units (px, %, vw, rem, and canvas units) that stay correct as the canvas and window resize.",{"path":398,"title":399,"description":400,"category":18},"\u002Fdocs\u002Fguide\u002Ftransforms","Transforms","Position, size, and rotate any layer inside the canvas with a bounding box, in any CSS unit.",{"path":402,"title":403,"description":404,"category":18},"\u002Fdocs\u002Fguide\u002Fshape-effects","Shape effects","Pick the 2D, 3D or custom SVG shape that Glass, Neon, Emboss and other shape effects draw inside.",{"path":406,"title":407,"description":408,"category":18},"\u002Fdocs\u002Fguide\u002Fcolor-space","Color space","Match colors to your design tool with the output color space, and keep bright layers from clipping with tone mapping.",{"path":410,"title":411,"description":412,"category":18},"\u002Fdocs\u002Fguide\u002Fhooks-events","Hooks and events","Run code when an effect is ready to show, and show a fallback when the GPU can't run it.",{"path":414,"title":415,"description":416,"category":18},"\u002Fdocs\u002Fguide\u002Fperformance","Performance","Learn what makes an effect expensive on the GPU and how to keep it inside the frame budget.",{"path":418,"title":419,"description":420,"category":18},"\u002Fdocs\u002Fguide\u002Fcustom-shaders","Custom components","Write your own component in TypeScript, use it like any component in the library, and write WGSL by hand when you need to.",{"path":422,"title":423,"description":424,"category":18},"\u002Fdocs\u002Fguide\u002Ftelemetry","Telemetry","The `\u003CShader>` component occasionally sends an anonymous performance report to help us improve the engine over time.",{"path":426,"title":427,"description":428,"category":429},"\u002Fdocs\u002Fguide\u002Fmcp","Working with your agent","The Shaders MCP connects your AI agent to the desktop app, so it can design shaders on your canvas and install them in your project.","workflows",{"path":431,"title":432,"description":433,"category":429},"\u002Fdocs\u002Fguide\u002Fcli","Working with the CLI","The Shaders CLI installs shaders from your projects and the Pro library into your codebase as component files, and keeps them in sync as you keep designing.",{"path":435,"title":436,"description":437,"category":429},"\u002Fdocs\u002Fguide\u002Fframeworks","Supported frameworks","Shaders runs in any web project that renders in a browser with WebGPU, with components for React, Vue, Svelte and Solid and a JavaScript API for everything else.",{"path":439,"title":440,"description":441,"category":18},"\u002Fdocs\u002Fguide\u002Fagent-skill","Agent skill for the engine","Teach your coding agent to write Shaders code with the open-source engine, for when it's working in your codebase instead of on the canvas.",{"path":443,"title":444,"description":445,"category":18},"\u002Fdocs\u002Fguide\u002Fvideo-rendering","Rendering to video","Render a shader effect to video frame by frame, from Remotion, Hyperframes or your own headless Chrome script.",{"path":447,"title":448,"description":449,"category":18},"\u002Fdocs\u002Fguide\u002Fssr","Server rendering","Render Shaders in Next.js, Nuxt, SvelteKit, SolidStart and other SSR apps by keeping each shader on the client.",1796051187341,"06e02370-81a6-4d74-9931-661d71414be1"]