Taos Engine · Agent Tutorials

Agent Tutorials · Step 2

Turtle Verbs & the Step Program

▶ Live demo: run this tutorial — built from src/02_turtle_verbs.ts.

The agent.* verbs are the Taos Engine turtle vocabulary, and the step array is the per-agent program — the GPU equivalent of turtles.ask(...). This demo has agents seek the world center and then orbit it, exercising face, towards, distance, turn, and moveForward together.

The verb catalog (AgentScript → Taos Engine)#

Movement & heading:

AgentScriptTaos Engine
forward(d) / fdagent.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)
headingagent.heading(); unit vector: agent.headingDir()
distance(agent) / distanceXYagent.distance(target) / agent.distanceXY(x, z)
randomHeading jitteragent.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:

TypeScript
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:

ValueBehaviorNetLogo
'torus'wrap at the edges (default)torus
'bounded'clamp to the rectanglebox
'bounce'reflect the heading off the wallsbounce
'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#