▶ Live demo: run this tutorial — built from src/02_turtle_verbs.ts.
The
agent.*verbs are the Taos Engine turtle vocabulary, and thesteparray is the per-agent program — the GPU equivalent ofturtles.ask(...). This demo has agents seek the world center and then orbit it, exercisingface,towards,distance,turn, andmoveForwardtogether.
The verb catalog (AgentScript → Taos Engine)#
Movement & heading:
| AgentScript | Taos Engine |
|---|---|
forward(d) / fd | agent.forward(d) (one step) / agent.moveForward(speed) (per-second) |
right(a) / left(a) | agent.turn(±a) |
setHeading(a) | agent.setHeading(a) |
towards(agent) | agent.towards(target) → an angle |
face(agent) | agent.face(target) |
heading | agent.heading(); unit vector: agent.headingDir() |
distance(agent) / distanceXY | agent.distance(target) / agent.distanceXY(x, z) |
randomHeading jitter | agent.randomTurn(spread) |
Sensing a patch field (tutorial 3): agent.sense(f), agent.senseAhead(f, d),
agent.senseAt(f, d, angle), agent.steer(f, …).
Neighbors (tutorial 4): agent.neighborCenter/Velocity/Separation/Count(r),
agent.nearest(r), agent.neighborsAhead(r, halfAngle).
A target is any vec3 expression — expr.vec3(0,0,0) for a fixed point, or a
neighbor query, or another agent's position. Heading lives on the XZ plane.
Branching and the step program#
step is an array of Actions run top to bottom, each compiled to WGSL. Use
action.if_(cond, [...], [...else]) to branch and action.set(attr, value) to
write an attribute. The seek-then-orbit logic:
const center = expr.vec3(0, 0, 0);
step: [
agent.face(center), // point at the center
action.if_(expr.gt(agent.distance(center), RING), [
agent.moveForward(16), // far → drive straight in
]),
action.if_(expr.le(agent.distance(center), RING), [
agent.turn(1.5), // close → ~tangent → orbit
agent.moveForward(9),
]),
agent.turn(agent.randomTurn(0.05)), // a little shimmer
],Reads see the start-of-frame snapshot; writes within one step apply in order (so
face then moveForward does what you'd expect). This is the deliberate,
well-defined version of AgentScript's ask ordering.
Edge topologies#
For position-movement models, the world boundary is appended to your step
automatically. Pick it with world.topology:
| Value | Behavior | NetLogo |
|---|---|---|
'torus' | wrap at the edges (default) | torus |
'bounded' | clamp to the rectangle | box |
'bounce' | reflect the heading off the walls | bounce |
'die' | agents that leave expire (the emitter refills them) | die at edge |
This demo uses 'bounce' so the wanderers that escape the ring turn back.
Next#
- Tutorial 3 — Patches & Stigmergy: the grid agents sense and deposit into — the slime-mold model.