Tline
New in PICO-8 0.2.0.
- Draws a textured line between two points, sampling the map for texture data.
- x0
-
- The x coordinate of the start of the line.
- y0
-
- The y coordinate of the start of the line.
- x1
-
- The x coordinate of the end of the line.
- y1
-
- The y coordinate of the end of the line.
- mx
-
- The x coordinate to begin sampling the map, expressed in (fractional) map tiles.
- my
-
- The y coordinate to begin sampling the map, expressed in (fractional) map tiles.
- mdx
-
- The amount to add to mx after each pixel is drawn, expressed in (fractional) map tiles. Default is 1/8 (move right one map pixel).
- mdy
-
- The amount to add to mx after each pixel is drawn, expressed in (fractional) map tiles. Default is 0 (a horizontal line).
The tline()
function draws a line while sampling colors from the map to provide a texture for the line. The mx and my parameters are similar to u,v coordinates used in 3D texture mapping, with the exception that they are expressed in units of map tiles. For example, a coordinate of 4.5,10 would sample from the pixel at 4.5*8,10*8 = 36,80 in the map.
The mdx and mdy parameters are effectively the slope of the line being sampled in the map. They can be fractional, they can be negative, and they can be 0. If both are 0, the whole line will sample from the same pixel on the map.
The map coordinates (mx, my) are masked by values calculated by subtracting 0x0.0001 from the values at address 0x5F38 and 0x5F39. In simpler terms, this means you can loop a section of the map by poking the width and height you want to loop within, as long as they are powers of 2 (2,4,8,16..)
For example, to loop every 8 tiles horizontally, and every 4 tiles vertically, you would type in the program:
POKE(0x5F38, 8)
POKE(0x5F39, 4)
The default values of (0,0) gives a mask of 0xff.ffff causing the samples to loop every 256 tiles.
To choose the offset where the loop starts from (in tiles) you would need to poke addresses 0x5f3a and 0x5f3b:
POKE(0x5F3A, OFFSET_X)
POKE(0x5F3B, OFFSET_Y)
Examples
-- draw 20 textured lines in random locations,
-- sampling from the first pixel row of the map
for x=1,20 do
tline(rnd(128), rnd(128), rnd(128), rnd(128))
end
-- draw 20 textured lines in random locations,
-- sampling from the tenth pixel column of the map
for x=1,20 do
tline(rnd(128), rnd(128), rnd(128), rnd(128), 10/8, 0, 0, 1/8)
end