Module pico8lib.graphics

Drawing and sprite manipulation

Local Functions

line_ (x1, y1, x2, y2, c) Draw a line connecting two points Uses Bresenham's line drawing algorithm
line_fat (x1, y1, x2, y2, fx, fy, c) Draw a fat line connecting two points Uses Bresenham's line drawing algorithm and rectfill
line_func (x1, y1, x2, y2, f, c) Draw a line connecting two points using a custom draw function Uses Bresenham's line drawing algorithm and the custom function for each point on the line line_func(...,pset) is equivalent to line_(...)
spr4_fast (s, x, y) Draw a 4x4 sprite
spr4 (s, x, y[, w=4[, h=4[, flip_h=false[, flip_v=false]]]]) Draw a 4x4 sprite with additional sspr() options 2.5x the runtime of spr4_fast()
circ_even (s, x, y, r, c) Draw a circle of even diameter (2-16)
circfill_even (s, x, y, r, c) Draw a filled circle of even diameter (2-16)
circ_even_small (s, x, y, r, c) Draw a small circle of even diameter (2-8)
circfill_even_small (s, x, y, r, c) Draw a small filled circle of even diameter (2-8)
circinverse (x, y, r, c) Draw every pixel outside a given circle
rectinverse (x, y, i, j, c) Draw every pixel outside a given rectangle
fillp (p, x, y) fillp with support for x/y offsets to shift the mask
ellipsefill (x0, y0, w, h, angle, c) Draw a filled ellipse
chromakey (drawfunc, x1, y1, x2, y2, c) "Green Screen" function Replaces pixels of a given color in a rectangle with output of a draw function
mapstring (mapstr, mapw[, celx[, cely[, sx[, sy[, celw[, celh[, layer]]]]]]]) Draw a map from a string
string_to_map (mapstr[, mapw], celx, cely) Replace existing map data with map described by a string
print_shadow (string, x, y, c, b) Print string with a shadow
print_shadow (string, x, y, c, b[, dx=1[, dy=1]]) Print string with a shadow
print_border_4 (string, x, y, c, b) Print string with an outline 4-direction outline
print_border_8 (string, x, y, c, b) Print string with an outline 8-direction outline
drawp (p, func, ...) Wrap any drawing function in a fillp() Replace fillp(1234)rect(5,6,7,8,9)fillp() with drawp(1234,rect,5,6,7,8,9) Break even on tokens and/or bytes after 5-9 calls


Local Functions

line_ (x1, y1, x2, y2, c)
Draw a line connecting two points Uses Bresenham's line drawing algorithm

Parameters:

  • x1 number X coordinate of starting point of the line
  • y1 number Y coordinate of starting point of the line
  • x2 number X coordinate of ending point of the line
  • y2 number Y coordinate of ending point of the line
  • c number Color of the line
line_fat (x1, y1, x2, y2, fx, fy, c)
Draw a fat line connecting two points Uses Bresenham's line drawing algorithm and rectfill

Parameters:

  • x1 number x coordinate of starting point
  • y1 number y coordinate of starting point
  • x2 number x coordinate of ending point
  • y2 number y coordinate of ending point
  • fx number width of line pixels (east of the original line)
  • fy number height of line pixels (south of the original line)
  • c number color
line_func (x1, y1, x2, y2, f, c)
Draw a line connecting two points using a custom draw function Uses Bresenham's line drawing algorithm and the custom function for each point on the line line_func(...,pset) is equivalent to line_(...)

Parameters:

  • x1 number x coordinate of starting point
  • y1 number y coordinate of starting point
  • x2 number x coordinate of ending point
  • y2 number y coordinate of ending point
  • f function function to call for each pixel of the line
  • c number color
spr4_fast (s, x, y)
Draw a 4x4 sprite

Parameters:

  • s number Sprite index
  • x number X coordinate for sprite placement
  • y number Y coordinate for sprite placement
spr4 (s, x, y[, w=4[, h=4[, flip_h=false[, flip_v=false]]]])
Draw a 4x4 sprite with additional sspr() options 2.5x the runtime of spr4_fast()

Parameters:

  • s number Sprite index
  • x number X coordinate for sprite placement
  • y number Y coordinate for sprite placement
  • w number Width to scale the sprite (default 4)
  • h number Height to scale the sprite (default 4)
  • flip_h bool Flip the sprite horizontally (default false)
  • flip_v bool Flip the sprite vertically (default false)
circ_even (s, x, y, r, c)
Draw a circle of even diameter (2-16)

Parameters:

  • s number sprite index
  • x number x coordinate, top left corner of bounding box
  • y number y coordinate, top left corner of bounding box
  • r number radius (1-8)
  • c number color
circfill_even (s, x, y, r, c)
Draw a filled circle of even diameter (2-16)

Parameters:

  • s number Sprite index
  • x number X coordinate, top left corner of bounding box
  • y number Y coordinate, top left corner of bounding box
  • r number Radius (1-8)
  • c number Color
circ_even_small (s, x, y, r, c)
Draw a small circle of even diameter (2-8)

Parameters:

  • s number Sprite index
  • x number X coordinate, top left corner of bounding box
  • y number Y coordinate, top left corner of bounding box
  • r number Radius (1-4)
  • c number Color
circfill_even_small (s, x, y, r, c)
Draw a small filled circle of even diameter (2-8)

Parameters:

  • s number Sprite index
  • x number X coordinate, top left corner of bounding box
  • y number Y coordinate, top left corner of bounding box
  • r number Radius (1-4)
  • c number Color
circinverse (x, y, r, c)
Draw every pixel outside a given circle

Parameters:

  • x number X coordinate, top left corner of bounding box
  • y number Y coordinate, top left corner of bounding box
  • r number Radius (1-4)
  • c number Color
rectinverse (x, y, i, j, c)
Draw every pixel outside a given rectangle

Parameters:

  • x number X coordinate, top left corner of rectangle
  • y number Y coordinate, top left corner of rectagle
  • i number X coordinate, bottom right corner of rectangle
  • j number Y coordinate, bottom right corner of rectangle
  • c number Color
fillp (p, x, y)
fillp with support for x/y offsets to shift the mask

Parameters:

  • p original algorithm from https
  • x
  • y //www.lexaloffle.com/bbs/?tid=30518
ellipsefill (x0, y0, w, h, angle, c)
Draw a filled ellipse

Parameters:

  • x0 number X coordinate, center of the ellipse
  • y0 number Y coordinate, center of the ellipse
  • w number Width of the ellipse
  • h number Height of the ellipse
  • angle number Rotation angle of the ellipse major axis
  • c number Color
chromakey (drawfunc, x1, y1, x2, y2, c)
"Green Screen" function Replaces pixels of a given color in a rectangle with output of a draw function

Parameters:

  • drawfunc function A function that takes x1, y1, x2, y2 coordinates and draws a rectangle of content
  • x1 number X coordinate, top left corner of rectangle
  • y1 number Y coordinate, top left corner of rectangle
  • x2 number X coordinate, bottom right corner of rectangle
  • y2 number Y coordinate, bottom right corner of rectangle
  • c number Color
mapstring (mapstr, mapw[, celx[, cely[, sx[, sy[, celw[, celh[, layer]]]]]]])
Draw a map from a string

Parameters:

  • mapstr string The map string, two hex digits per tile
  • mapw number Width of the map in tiles
  • celx number (optional)
  • cely number (optional)
  • sx number (optional)
  • sy number (optional)
  • celw number (optional)
  • celh number (optional)
  • layer number (optional)
string_to_map (mapstr[, mapw], celx, cely)
Replace existing map data with map described by a string

Parameters:

  • mapstr string The map string, two hex digits per tile (e.g. "00DEADBEEF99")
  • mapw number Width of the map in tiles (optional)
  • celx number X coordinate to start replacing in the map space
  • cely number Y coordinate to start replacing in the map space
print_shadow (string, x, y, c, b)
Print string with a shadow

Parameters:

  • string string The string to print
  • x number X coordinate, top left corner of print area
  • y number Y coordinate, top left corner of print area
  • c number Color of text
  • b number Color of shadow
print_shadow (string, x, y, c, b[, dx=1[, dy=1]])
Print string with a shadow

Parameters:

  • string string The string to print
  • x number X coordinate, top left corner of print area
  • y number Y coordinate, top left corner of print area
  • c number Color of text
  • b number Color of shadow
  • dx number X offset of shadow (default 1)
  • dy number Y offset of shadow (default 1)
print_border_4 (string, x, y, c, b)
Print string with an outline 4-direction outline

Parameters:

  • string string The string to print
  • x number X coordinate, top left corner of print area
  • y number Y coordinate, top left corner of print area
  • c number Color of text
  • b number Color of outline
print_border_8 (string, x, y, c, b)
Print string with an outline 8-direction outline

Parameters:

  • string string The string to print
  • x number X coordinate, top left corner of print area
  • y number Y coordinate, top left corner of print area
  • c number Color of text
  • b number Color of outline
drawp (p, func, ...)
Wrap any drawing function in a fillp() Replace fillp(1234)rect(5,6,7,8,9)fillp() with drawp(1234,rect,5,6,7,8,9) Break even on tokens and/or bytes after 5-9 calls

Parameters:

  • p numbert Fill pattern
  • func function The draw function to call
  • ... Paramters for func
generated by LDoc 1.5.0 Last updated 2024-09-08 14:28:56