Light as table lookups: a ramp of light tables built from a palette, and which table a surface at some light level and distance is drawn through.
tables = Light.tables(palette)
Light.table(160, 384.0)A light table maps a colour index to the index of that colour darkened, so lighting a
picture costs one lookup a pixel whatever the light. tables/2 builds maps of them,
table 0 the palette as it is and each further table darker, the last nearly black.
A game may instead bring its own tables made for its palette.
A surface's light level is 0..255. start/2 turns it into the table it is drawn
through close up, and table/3 moves that table brighter or darker with distance:
start - floor(fade / distance), clamped to the tables, so nearer is brighter and a
surface fades by its light level's own amount as it recedes.
Options
:maps— how many tables the ramp has. Default32:levels— how many steps the0..255light level is cut into. Default16:fade— how strongly distance darkens, in world units. Default1280.0
Summary
Functions
The table a surface at light (0..255) is drawn through close up.
The table a surface at light is drawn through from distance away.
maps light tables for a 768-byte palette, darkening towards black: table n holds
for each colour the palette entry nearest that colour scaled by (maps - n) / maps.
Types
@type option() :: {:maps, pos_integer()} | {:levels, pos_integer()} | {:fade, number()}
Functions
The table a surface at light (0..255) is drawn through close up.
@spec table(integer(), number(), [option()]) :: non_neg_integer()
The table a surface at light is drawn through from distance away.
maps light tables for a 768-byte palette, darkening towards black: table n holds
for each colour the palette entry nearest that colour scaled by (maps - n) / maps.