{"id":"recipe--compute-particles","name":"Example · Move a row of particles","owner":"yeho","package":"recipes","kind":"recipe","signature":"start.yh · compute example","description":"Update independent positions using float buffers and elapsed time.","context":"A particle can be as small as a position and velocity. Give each invocation one particle index, read its velocity, and add velocity times elapsed seconds to its position. This first example moves three particles along one axis and prints the positions. It is a compute simulation step, not a complete particle renderer. The same ownership idea extends to separate X, Y, and Z buffers.","parameters":[],"returns":"","members":[],"tags":["cpu","gpu","recipe"],"updated":"2026-09-09","source":{"repository":"demonhunterlabs","path":"app/lib/yeho-walkthrough.ts"},"status":"complete-program","notes":["Change dt from 0.5 to 0.25. Predict all three positions before dispatching."],"examples":[{"id":"program","title":"Example · Move a row of particles","description":"Update independent positions using float buffers and elapsed time.","code":"[auto]\ncompute Move(buffer of float positions, buffer of float velocities, float dt)\n{\n    int index = compute.index\n    if index >= positions.count { return }\n    if index >= velocities.count { return }\n    positions[index] = positions[index] + velocities[index] * dt\n}\n\nbuffer of float positions\npositions.Add(0.0) positions.Add(1.0) positions.Add(2.0)\nbuffer of float velocities\nvelocities.Add(2.0) velocities.Add(0.0) velocities.Add(-2.0)\ncomputeTask job = dispatch Move(positions, velocities, 0.5)\nwait job\nif job.failed { Console.Error(job.error.message) Process.Exit(1) }\nfor index from 0 < positions.count { Console.Log(Text.From(positions[index])) }","manifest":"manifestVersion = \"2\"\npackage = \"api.example.recipe__compute_particles\"\nversion = \"0.1.0\"\nlanguageEdition = \"yeho-core-2026.1\"\n\n[app]\nkind = \"headless\"\n","tags":["gpu","cpu"],"run":"metal","expected":"1\n1\n1","verification":"type checked","sha256":"dd87e66ed93d3e483c81166c600624daafed4ff5c9b543686e1dc6c599ae9cf9","checked":"2026-09-09","diagnostic":"","observedOutput":null,"checkedBackend":null}],"searchTerms":[],"url":"https://demonhunterlabs.com/academy/api?item=recipe--compute-particles","json":"https://demonhunterlabs.com/reference/items/recipe--compute-particles.json","markdown":"https://demonhunterlabs.com/reference/text/recipe--compute-particles.md"}
