gizgame/nature
how a thing a person places in a world moves by itself. A ship sails, a car drives, a bird flies, a dog walks, a fish swims and a house stays: its nature is read from its name (or said by its behavior), and one step moves any of them: it wanders about its home, turns away from what is in its way and stops before what it cannot pass.
import * as Nature from "gizgame/nature";Types
Nature
type Nature = { way: string; speed: f64; turn: f64; leash: f64; high: f64; draft: f64; }How a thing moves by itself: the WAY ("stays", "sails", "swims", "flies", "drives", "walks"), its SPEED in meters a second, how fast it TURNS in radians a second, the LEASH in meters it keeps to about its home, how HIGH over the ground it flies and the DRAFT of water it needs under it.
way:stringspeed:f64turn:f64leash:f64high:f64draft:f64
Roamer
type Roamer = { at: Point3; yaw: f64; speed: f64; home: Point3; }A thing that moves by itself: where it is (x, z), the way it heads (geometry facing), its speed now and its home.
at:gizlang_geometry.Point3yaw:f64speed:f64home:gizlang_geometry.Point3
Functions
natureOf
function natureOf(name: string, behavior: string = ""): NatureThe nature of the thing NAME. BEHAVIOR says it when it is a way ("sails", "still" for one that stays whatever its name); else the name's last word that says a way does, also in its plural. A name with none stays.
Effects: fail, read, write, console, io, alloc.
roamed
function roamed(r: Roamer, n: Nature, seed: f64, time: f64, dt: f64, reach: f64, clear: (from: Point3, to: Point3) => bool): RoamerR after DT seconds at TIME, of nature N; SEED makes its wandering its own and REACH is half its length. It wanders about its home and comes back from its leash's end. CLEAR says whether it may go from a place to another (the ground suits it and nothing solid is between): where its way is not clear it turns to the nearest way that is, and with none it stops and turns where it stands. One that walks stands still a while now and then.
Effects: fail, read, write, console, io, alloc.