Reference / Physics & grids namespace Grid Algorithms 5 functions
datumhue.grid 2D integer grids with pathfinding, FOV, flood-fill, cellular automata, and procedural fills.
Returns handles Grid , LightField
Functions 5
datumhue.grid. newfunction datumhue.grid.new (width: integer, height: integer ) -> Grid Create a zeroed width x height grid (each dimension 1..=4096).
Example local map = datumhue .grid.new (40 , 30 )
print (map.width , map.height )
print (map:get (0 , 0 ), map:get (39 , 29 ), map:get (40 , 0 ))
datumhue.grid. light_fieldfunction datumhue.grid.light_field (width: integer, height: integer ) -> LightField Create a zeroed width x height light field (each dimension 1..=4096).
datumhue.grid. voronoifunction Example
local hives = datumhue .grid.voronoi (16 , 12 , 4 , {
seed = 7 ,
distance = "manhattan" ,
})
local owned = 0
for _, hive in ipairs (hives) do
owned = owned + #hive.cells
end
print (#hives, owned) opts grid.VoronoiOptions options 3 keys
Key Type Default Description distance "euclidean" | "manhattan" | "chebyshev" "euclidean" Metric used to assign cells to the nearest hive. seed integer placement draws from rng, or without it from a source that random.new streams do not affect Seed for deterministic hive placement. rng Rng placement follows seed, if given Draw hive placement from this stream (advancing it). Mutually exclusive with seed.
datumhue.grid. linefunction datumhue.grid.line (x1: integer, y1: integer, x2: integer, y2: integer ) -> grid.Cell [] The rasterized cells of a straight line from (x1,y1) to (x2,y2).
Example
local cells = datumhue .grid.line (0 , 0 , 4 , 2 )
print (#cells)
print (cells[5 ].x, cells[5 ].y) returns grid.Cell record 2 keys
Key Type Description x integer Cell column. y integer Cell row.
datumhue.grid. distancefunction datumhue.grid.distance (x1: integer, y1: integer, x2: integer, y2: integer, opts? : grid.DistanceOptions ) -> number Distance between two cells.
Example local distance = datumhue .grid.distance
print (distance (0 , 0 , 3 , 4 ))
print (distance (0 , 0 , 3 , 4 , { type = "manhattan" }))
print (distance (0 , 0 , 3 , 4 , { type = "chebyshev" }))
Types 5
grid.AgentStep record record 5 keys
Key Type Description x number position after the step, in cells y number position after the step, in cells arrived boolean the target cell has been reached blocked boolean a target is set but no path to it exists stopped? grid.AgentStop when the walk halted before a stop_before cell: the cell and its value
Used by: PathAgent:advance , PathAgent:drive
grid.AgentStop record record 3 keys
Key Type Description x integer the halting cell y integer the halting cell value integer the cell's value at the halt
Nested in: grid.AgentStep
grid.Cell record record 2 keys
Key Type Description x integer Cell column. y integer Cell row.
Used by: datumhue.grid.line , Grid:find_path , Grid:field_of_view , Grid:flood_fill
Nested in: grid.VoronoiCell
grid.DijkstraSource options options 3 keys
Key Type Default Description x required integer – no default Source cell x coordinate. y required integer – no default Source cell y coordinate. score number 0 Starting distance score.
Nested in: grid.DijkstraOptions
grid.DistanceType enum Value Description "euclidean""manhattan""chebyshev"
Nested in: grid.DistanceOptions , grid.VoronoiOptions