Engine#
ttt.core.engine.Bit
#
Bases: ABC
Rendereable element of the ttt engine.
Can be either made from pixels (RasterBit) or verbatim text (RawBit).
blit
#
blit(
available_width: int = term.get_size()[0] * 2,
invert: bool = False,
braille: bool = False,
do_print: bool = True,
) -> str
Recursively render the Bit tree and convert to printable text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
available_width
|
int
|
Width budget given to this Bit and its children for rendering. Defaults to current terminal width. |
get_size()[0] * 2
|
invert
|
bool
|
Render with inverted colors. |
False
|
do_print
|
bool
|
Also print the final rendered result. |
True
|
Returns:
-
str–A rendered Bit
ttt.core.engine.RawBit
#
RawBit(raw_text: str)
Bases: Bit
Renderable Bit representing verbatim text.
Contents of this type of Bit are not rendered using pixels but will instead be outputed as-is to the terminal.
Since real text cannot be precisely positioned like pixels, the final position of a raw Bit will be rounded to the nearest multiple of 2 horizontally, and 4 vertically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_text
|
str
|
Text content to be rendered verbatim. |
required |
ttt.core.engine.Canvas
#
Canvas(contents: Image.Image | str)
Abstraction layer for drawing with pixels and text at the same time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents
|
Image | str
|
Initial contents of this Canvas, either an Image or some verbatim text. |
required |
height: int
property
#
Height of this Canvas.
width: int
property
#
Width of this Canvas.
draw_text
#
draw_text(x: int, y: int, text: str, font: FreeTypeFont, fill: int)
Draw rasterized text on this Canvas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int
|
Horizontal coordinate of the text, in pixels. |
required |
y
|
int
|
Vertical offset of the text, in pixels. |
required |
text
|
str
|
Text to write. |
required |
font
|
FreeTypeFont
|
PIL Font object. |
required |
fill
|
int
|
Text color (0 = black, 255 = white). |
required |
invert
#
invert()
Returns a copy of this Canvas with inverted colors.
Returns:
-
Canvas–A copy of this Canvas with inverted colors.
new
classmethod
#
new(width: int, height: int, color: int) -> Canvas
Create a new blank Canvas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
Width in pixels. |
required |
height
|
int
|
Height in pixels. |
required |
color
|
int
|
Fill color of the new Canvas (0 = black, 255 = white). |
required |
Returns:
-
Canvas–A new blank Canvas.
paste
#
paste(other: Self | Image.Image, x: int, y: int)
Draw another Canvas on top of this one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Canvas | Image
|
Other Canvas to draw (or PIL Image). |
required |
x
|
int
|
Horizontal offset of where to draw the other Canvas. |
required |
y
|
int
|
Vertical offset of where to draw the other Canvas. |
required |
pixels
#
pixels() -> np.ndarray
Returns a 2D numpy array representing the pixel values of this Canvas.
Values are 0 for black and 255 for white.
put_pixel
#
put_pixel(x: int, y: int, fill: int)
Change the color value of the given pixel coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int
|
Horizontal coordinate of the pixel. |
required |
y
|
int
|
Vertical coordinate of the pixel. |
required |
fill
|
int
|
New color value (0 = black, 255 = white). |
required |
shifted_raws
#
shifted_raws(dx: int, dy: int, toggle_invert: bool = False) -> list[Raw]
Returns a copy of the verbatim texts of this Canvas, shifted by an offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dx
|
int
|
Horizontal offset. |
required |
dy
|
int
|
Vertical offset. |
required |
toggle_invert
|
bool
|
Also invert the colors of the verbatim text. |
False
|
Returns:
-
list[Raw]–A copy of the verbatim texts with shifted coordinates.