X Tools - mgismissing/cosmos GitHub Wiki
X Tools are extensions of already existing vanilla classes.
imageX
The imageX
extension adds generic functions that extend the vanilla image
library:
name | description |
---|---|
drawCheckerLineH |
Draws a horizontal line with a checkerboard pattern |
drawCheckerLineV |
Draws a vertical line with a checkerboard pattern |
drawCheckerLineV |
Draws a vertical line with a checkerboard pattern |
drawCheckerRect |
Draws a rectangle with a checkerboard pattern |
fillCheckerRect |
Draws a filled rectangle with a checkerboard pattern |
Fonts
One of the main features is a general implementation of the image.Font
class to make font creation simpler.
Creating a new font
There are two methods to create a new font: the first one is static and the second one is dynamic.
The static method works by creating a new imageX.Font
and giving it all the font data directly as a raw Buffer
:
let myFont: image.Font = new imageX.Font(4, 8, Buffer.fromArray([
ord(" "), 0x00, // Header (Unicode Little Endian)
0b00000000, 0b00000000, 0b00000000, 0b00000000, // Data (1-bit per pixel image of the font's character read from bottom to top and from left to right)
// Repeat to add more characters
The dynamic (and simpler) method works by creating a new empty imageX.Font
and adding the characters one by one:
let myFont: image.Font = new imageX.Font(4, 8, Buffer.create(0))
// Add font glyphs
myFont.add_glyph(" ", [0b00000000, 0b00000000, 0b00000000, 0b00000000])
// Repeat to add more characters
Using an existing font
To use a custom font, the method is the same as using a vanilla one (like image.font5
).
List of custom pre-made fonts
Cosmos includes some pre-made fonts in the imageX.font
namespace:
Name | Style |
---|---|
SYS_4x8 |
Sharp edges |