Canvas
Must be included via require
.
canvas.new
Creates a new canvas instance.
Parameters
- Width.
- Height.
canvas.bmp
Creates a new canvas instance based on a BMP image.
Parameters
- The BMP image as a string.
canvas.qrcode
Creates a new canvas instance containing a QR code.
Parameters
- The string to be encoded.
- An optional table of options.
Options
- "ecl" specifies the error correction level between "low", "medium", "quartile", "high". defaults to "low".
- "border" specifies the number of pixels around the QR code. defaults to 0.
- "bg" specifies the background color. defaults to
0x000000
for black. - "fg" specifies the background color. defaults to
0xffffff
for white.
pluto
local canvas = require "canvas"local c = canvas.qrcode("Hello from Pluto!", { fg = 0xffffff, bg = 0x000000 })print(c:tobwstring(0xffffff))--> █▀▀▀▀▀█ ▄ █▄▄ █▀▀▀▀▀█--> █ ███ █ ▄█▄▄█ █ ███ █--> █ ▀▀▀ █ ▄▀ █▄ █ ▀▀▀ █--> ▀▀▀▀▀▀▀ ▀▄▀▄█ ▀▀▀▀▀▀▀--> ▀▀███ ▀███ █▀▀ ▀▄█▄▀▄--> █▄▀▄▀█▀█▀▀ ▀█▄▀▄▄██▀--> ▀▀▀▀▀ ▀ █▀█▀ ▄█▄▄▄ ▀--> █▀▀▀▀▀█ ▀ ▀██▀▄ ▄██--> █ ███ █ █▄ ▄█▄██▄▄ ▄--> █ ▀▀▀ █ █▄ ▀█▀ ▀▄▄█--> ▀▀▀▀▀▀▀ ▀ ▀ ▀ ▀ ▀
canvas.get
Gets the color of the pixel at the given coordinates.
Parameters
- The canvas instance.
- The X coordinate.
- The Y coordinate.
Returns
The color as an integer.
canvas.set
Sets the color of the pixel at the given coordinates.
Parameters
- The canvas instance.
- The X coordinate.
- The Y coordinate.
- The color as an integer.
canvas.fill
Sets every pixel to the given color.
Parameters
- The canvas instance.
- The color as an integer.
canvas.size
Get the size of a canvas.
Parameters
- The canvas instance.
Returns
- Width.
- Height.
canvas.mulsize
Multiplies the size of a canvas.
Parameters
- The canvas instance.
- The multiplier. Must be 2 or higher.
canvas.tobmp
Convert a canvas to a BMP image.
Parameters
- The canvas instance.
Returns
A string.
canvas.topng
Convert a canvas to a PNG image.
Parameters
- The canvas instance.
Returns
A string.
pluto
local { base64, canvas } = require "*"local c = new canvas(5, 5)c:fill(0xff0000)print("data:image/png;base64,"..base64.encode(c:topng()))--> data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAAW0lEQVQIHQFQAK//AP8AAP8AAP8AAP8AAP8AAAD/AAD/AAD/AAD/AAD/AAAA/wAA/wAA/wAA/wAA/wAAAP8AAP8AAP8AAP8AAP8AAAD/AAD/AAD/AAD/AAD/AAD9fBjo3iScjwAAAABJRU5ErkJggg==
canvas.tobwstring
Convert a canvas to a black and white unicode string. This requires the height of the canvas to be an even number; if it is not, a black line will be added to the bottom of the canvas.
Parameters
- The canvas instance.
- The color to be "white." Any other color will be "black."
Returns
A string.