xnano.pixel
xnano.pixel
¶
xnano.pixel
One cell or dot of a region: a character with a foreground and a background color.
Classes:
-
Pixel–One cell (or one dot, at half-block and braille resolution) of a region.
Attributes:
-
PixelPreset(TypeAlias) –The names of the characters
Pixelknows:Pixel('diamond')draws◆.
PixelPreset
module-attribute
¶
PixelPreset: TypeAlias = Literal['block', 'half_top', 'half_bottom', 'shade_light', 'shade_medium', 'shade_dark', 'braille', 'circle', 'circle_outline', 'dot', 'diamond', 'star', 'line_horizontal', 'line_vertical', 'corner_top_left_rounded', 'corner_top_right_rounded', 'corner_bottom_left_rounded', 'corner_bottom_right_rounded', 'corner_top_left_square', 'corner_top_right_square', 'corner_bottom_left_square', 'corner_bottom_right_square', 'arrow_up', 'arrow_down', 'arrow_left', 'arrow_right', 'check', 'cross']
The names of the characters Pixel knows: Pixel('diamond') draws ◆.
Pixel
dataclass
¶
Pixel(preset_or_character: PixelPreset | str = 'block', *, foreground: ColorValue | None = None, background: ColorValue | None = None, symbol: str | None = None)
One cell (or one dot, at half-block and braille resolution) of a region.
The first argument is a preset name such as 'diamond', the name of a registered
symbol, or a single character that is drawn as it is. A pixel is a value: it compares by
its fields, and region[x, y] returns one and accepts one.
Parameters:
-
preset_or_character(PixelPreset | str, default:'block') –A
PixelPreset, the name of a registered symbol, or one character. -
foreground(ColorValue | None, default:None) –The color of the character.
-
background(ColorValue | None, default:None) –The color behind the character.
-
symbol(str | None, default:None) –A name to register this pixel under, so that
Pixel('wall')finds it later. The name takes two characters or more; seeregister.
Attributes:
-
character(str) –The glyph drawn in the cell or dot.
-
foreground(ColorValue | None) –The color of the glyph, or
Nonefor the cell's own. -
background(ColorValue | None) –The color behind the glyph, or
Nonefor the cell's own. -
symbol(str | None) –The registered symbol name, or
None.
Raises:
-
ValueError–The name is not a preset or a registered symbol (the message lists both and the closest names first), or the character is empty.
Examples:
import xnano
from xnano import Pixel
diamond = Pixel('diamond', foreground='red')
assert diamond.character == '◆'
assert Pixel('x').character == 'x'
with xnano.new(width=4, height=1) as canvas:
canvas.region[1, 0] = diamond
assert canvas.region[1, 0].character == '◆'
Make a pixel from a preset, a symbol name or a character.
Parameters:
-
preset_or_character(PixelPreset | str, default:'block') –A preset name, a registered symbol name or one character.
-
foreground(ColorValue | None, default:None) –The color of the character.
-
background(ColorValue | None, default:None) –The color behind the character.
-
symbol(str | None, default:None) –A name to register this pixel under.
Methods:
-
cell–Return the core cell that draws this pixel.
-
__str__–Return the character of the pixel, so
print(pixel)shows what it draws. -
__xnano_render__–Return a buffer of one cell that shows the pixel.
Source code in xnano/pixel.py
foreground
instance-attribute
¶
foreground: ColorValue | None
The color of the glyph, or None for the cell's own.
background
instance-attribute
¶
background: ColorValue | None
The color behind the glyph, or None for the cell's own.
cell
¶
cell() -> Cell
Return the core cell that draws this pixel.
The cell is built once and kept, so writing the same pixel many times is cheap.
Source code in xnano/pixel.py
__xnano_render__
¶
Return a buffer of one cell that shows the pixel.