recipes · recipe ·

Example · Move a row of particles

Update independent positions using float buffers and elapsed time.

cpugpurecipe

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.

start.yh · compute example

Status: complete-program

Example · Move a row of particles

Update independent positions using float buffers and elapsed time.

gpu · cpu · type checked

[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])) }
project.mech
manifestVersion = "2"
package = "api.example.recipe__compute_particles"
version = "0.1.0"
languageEdition = "yeho-core-2026.1"

[app]
kind = "headless"
Expected output
1
1
1
Notes and source

Change dt from 0.5 to 0.25. Predict all three positions before dispatching.

demonhunterlabs/app/lib/yeho-walkthrough.ts