BTPRNT
How to use btprnt
in monolith.
Gradually adding things as I go.
Basic Setup
Straight-up btprnt inside of monolith.
Write "hello monolith" to a 256x256 bitmap, then write it to a PBM file.
(def bp (monolith/btprnt-new 256 256))
(monolith/btprnt-textbox
bp
(monolith/btprnt-font-default)
@[0 0 256 256] 10 112 "hello monolith!" 2 1)
(monolith/btprnt-write-pbm bp "hello.pbm")
drawbits
drawbits
allows one to copy janet buffers to a btprnt
buffer.
(def bits @"")
(var bp (monolith/btprnt-new 64 64))
# a slightly offset black box
# offset by 1 pixel
(put bits 0 0x00)
(put bits 1 0xe)
(put bits 2 0xe)
(put bits 3 0xe)
(put bits 4 0x00)
(pp bits)
# move the slightly offset box
# to be flush against the corner
(monolith/btprnt-drawbits
bp bits
@(0 0 8 4)
0 0
8 4
1 1)
(monolith/btprnt-write-pbm bp "bits.pbm")
stencil
The function monolith/gfx-btprnt-stencil
can be used
to copy a region of a btprnt buffer to a location on
a monolith framebuffer using a certain color.
It takes in 10 arguments:
The btprnt instance.
x,y: the top left starting point to draw the btprnt stencil.
w,h: the width and height of the space to draw. If these exceed the bounds of the btprnt buffer, these will be ignored.
offx, offy: the starting offset values to start reading from btprnt.
R,G,B: the color to use.
(monolith/gfx-btprnt-stencil bp 0 32 width height 0 0 0 0 0)
More information on the implementation can be found in 13. btprnt + gfx framebuffer.
Rectangles
Done with monolith/btprnt-rect
and
monolith/btprnt-rect-filled
.
(monolith/btprnt-rect-filled bp @(0 0 64 64) 0 0 10 10 1)
(monolith/btprnt-rect bp @(4 4 64 64) 0 0 10 10 0)
Alignment
Center Box
monolith/btprnt-centerbox
creates a centered subregion
from a region.
(monolith/btprnt-centerbox bp reg w h)
Border
monolith/btprnt-border
creates a centered subregion
from a region with a specified border size.
(monolith/btprnt-border bp reg size)
grid
monolith/btprnt-grid
returns a region that belongs
to a grid of arbitrary rows and columns.
(monolith/btprnt-grid bp reg ncols nrows col row)
Text
Text is typically done with btprnt-textbox
:
(monolith/btprnt-textbox bp font reg xpos ypos clr scale)
(def bp (monolith/btprnt-new 256 256))
(def fnt (monolith/btprnt-font-default))
(def cherry (monolith/btprnt-font-cherry))
(monolith/btprnt-textbox
bp fnt @[0 0 256 256] 0 0 "hello monolith" 1 1)
(monolith/btprnt-textbox
bp cherry @[0 0 256 256] 0 8 "hello monolith" 1 2)
(monolith/btprnt-write-pbm bp "hello.pbm")
Bezier
Draws a quadratic bezier curve.
(monolith/btprnt-bezier bp x0 y0 x1 y1 x2 y2 color)
Standalone Janet Plugin
The btprnt library in lib/btprnt
can be compiled
as a standalone janet plugin that can exist
outside of Monolith. In addition to the config files needed
for Monolith's Makefile build system, there are also config
files set up for for the Janet Plugin Management system,
JPM.
Running jpm build
in the lib/btprnt
directory will
create a directory called build
with the plugin contents
in it.
The standalone btprnt plugin is currently used in Monolith
to generate diagrams for this wiki. You can see some example
code in doc/trig.janet
and doc/trig.org
, with the
resulting image found here.
Note: not everything gets built with the btprnt standalone. cratewav is disabled because of the hard dependency on SQLite (even though it's on most systems already, removing it simplifies things).