# Example · Move a row of particles

Update independent positions using float buffers and elapsed time.

Last updated: 2026-09-09

Package: recipes | Status: complete-program

Tags: cpu, gpu, recipe

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.

```yh
start.yh · compute example
```


## Example · Move a row of particles

Update independent positions using float buffers and elapsed time.

Verification: type checked

```yh
[auto]
compute Move(buffer of float positions, buffer of float velocities, float dt)
{
    int index = compute.index
    if index >= positions.count { return }
    if index >= velocities.count { return }
    positions[index] = positions[index] + velocities[index] * dt
}

buffer of float positions
positions.Add(0.0) positions.Add(1.0) positions.Add(2.0)
buffer of float velocities
velocities.Add(2.0) velocities.Add(0.0) velocities.Add(-2.0)
computeTask job = dispatch Move(positions, velocities, 0.5)
wait job
if job.failed { Console.Error(job.error.message) Process.Exit(1) }
for index from 0 < positions.count { Console.Log(Text.From(positions[index])) }
```

Save this beside start.yh as project.mech:

```toml
manifestVersion = "2"
package = "api.example.recipe__compute_particles"
version = "0.1.0"
languageEdition = "yeho-core-2026.1"

[app]
kind = "headless"

```

Expected output:

```text
1
1
1
```

Extract the example archive beside the yeho and dolphin checkouts. This example requires those source dependencies and a current developer compiler.

```sh
./yeho/build/dolphin-metal/yehoc ./api-examples/recipe--compute-particles/program --backend metal -o /tmp/yeho-example
/tmp/yeho-example
```


Change dt from 0.5 to 0.25. Predict all three positions before dispatching.

Source: demonhunterlabs/app/lib/yeho-walkthrough.ts

AI training permission: https://demonhunterlabs.com/ai-use
