textmode.js / loadables / TextmodeImage
Class: TextmodeImage
Represents an image uploaded for textmode rendering via Textmodifier.loadImage.
It can be drawn to the canvas via Textmodifier.image.
An image uploaded currently runs through an adjustable brightness-converter that converts the original image into a textmode representation using characters. Those adjustable options are available via chainable methods on this class.
Example
const t = textmode.create({
width: 800,
height: 600,
});
let img;
t.setup(async () => {
img = await t.loadImage('https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=800&q=80');
img.characters(" .:-=+*#%@");
// ... other adjustments like img.flipX(boolean), img.cellColorMode('sampled' | 'fixed'), etc.
// (can also be chained or updated during runtime)
});
t.draw(() => {
t.background(0);
if (img) {
// Draw the loaded image
t.image(img);
}
});Extends
TextmodeSource
Accessors
height
Get Signature
get height(): number;Ideal height in grid cells.
Returns
number
Inherited from
TextmodeSource.heightoriginalHeight
Get Signature
get originalHeight(): number;Original pixel height.
Returns
number
Inherited from
TextmodeSource.originalHeightoriginalWidth
Get Signature
get originalWidth(): number;Original pixel width.
Returns
number
Inherited from
TextmodeSource.originalWidthtexture
Get Signature
get texture(): WebGLTexture;Return the WebGL texture currently backing this source.
Returns
WebGLTexture
Inherited from
TextmodeSource.texturewidth
Get Signature
get width(): number;Ideal width in grid cells.
Returns
number
Inherited from
TextmodeSource.widthMethods
background()
background(
colorOrGray,
g?,
b?,
a?): this;Defines the background color used for transparent pixels.
Parameters
| Parameter | Type | Description |
|---|---|---|
colorOrGray | | string | number | TextmodeColor | A grayscale value (0-255), hex string ('#RGB', '#RRGGBB', '#RRGGBBAA'), or TextmodeColor instance |
g? | number | Green component (0-255) if using RGB format |
b? | number | Blue component (0-255) if using RGB format |
a? | number | Alpha component (0-255) if using RGBA format |
Returns
this
This instance for chaining.
Inherited from
TextmodeSource.backgroundcellColor()
cellColor(
colorOrGray,
g?,
b?,
a?): this;Defines the cell color when cellColorMode is 'fixed'.
Parameters
| Parameter | Type | Description |
|---|---|---|
colorOrGray | | string | number | TextmodeColor | A grayscale value (0-255), hex string ('#RGB', '#RRGGBB', '#RRGGBBAA'), or TextmodeColor instance |
g? | number | Green component (0-255) if using RGB format |
b? | number | Blue component (0-255) if using RGB format |
a? | number | Alpha component (0-255) if using RGBA format |
Returns
this
This instance for chaining.
Inherited from
TextmodeSource.cellColorcellColorMode()
cellColorMode(mode): this;Set cell color mode: 'sampled' (from source) or 'fixed'.
Parameters
| Parameter | Type | Description |
|---|---|---|
mode | "sampled" | "fixed" | The cell color mode |
Returns
this
This instance for chaining.
Inherited from
TextmodeSource.cellColorModecharacters()
characters(chars): this;Define the characters to use for brightness mapping as a string. Maximum length is 255; excess characters are ignored.
Parameters
| Parameter | Type | Description |
|---|---|---|
chars | string | String of characters to map |
Returns
this
This instance for chaining.
Inherited from
TextmodeSource.characterscharColor()
charColor(
colorOrGray,
g?,
b?,
a?): this;Defines the character color when charColorMode is 'fixed'.
Parameters
| Parameter | Type | Description |
|---|---|---|
colorOrGray | | string | number | TextmodeColor | A grayscale value (0-255), hex string ('#RGB', '#RRGGBB', '#RRGGBBAA'), or TextmodeColor instance |
g? | number | Green component (0-255) if using RGB format |
b? | number | Blue component (0-255) if using RGB format |
a? | number | Alpha component (0-255) if using RGBA format |
Returns
this
This instance for chaining.
Inherited from
TextmodeSource.charColorcharColorMode()
charColorMode(mode): this;Set character color mode: 'sampled' (from source) or 'fixed'.
Parameters
| Parameter | Type | Description |
|---|---|---|
mode | "sampled" | "fixed" | The character color mode |
Returns
this
This instance for chaining.
Inherited from
TextmodeSource.charColorModecharRotation()
charRotation(degrees): this;Set the character rotation in degrees (0-360).
Parameters
| Parameter | Type | Description |
|---|---|---|
degrees | number | Rotation in degrees |
Returns
this
This instance for chaining.
Inherited from
TextmodeSource.charRotationcolorFilter()
colorFilter(palette?): this;Applies an optional color filter palette before MRT conversion. When a palette is provided, all sampled pixels are quantized to the closest palette color prior to character/color analysis.
Parameters
| Parameter | Type | Description |
|---|---|---|
palette? | | null | string[] | [number, number, number][] | [number, number, number, number][] | TextmodeColor[] | A list of colors defined as TextmodeColor instances, hex strings, or RGBA tuples (0-255). Providing an empty array or null disables the filter. |
Returns
this
Inherited from
TextmodeSource.colorFilterconversionMode()
conversionMode(mode): this;Select the conversion mode for this source.
textmode.js includes only a single built-in conversion strategy 'brightness'.
Additional conversion strategies may be provided via add-on libraries.
Parameters
| Parameter | Type | Description |
|---|---|---|
mode | TextmodeConversionMode | Conversion mode to use. |
Returns
this
Inherited from
TextmodeSource.conversionModeflipX()
flipX(v): this;Set horizontal flip indicator flag.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
v | number | boolean | true | Flip flag |
Returns
this
This instance for chaining.
Inherited from
TextmodeSource.flipXflipY()
flipY(v): this;Set vertical flip indicator flag.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
v | number | boolean | true | Flip flag |
Returns
this
This instance for chaining.
Inherited from
TextmodeSource.flipYinvert()
invert(v): this;Set the invert flag, swapping character and cell colors when enabled.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
v | number | boolean | true | Invert flag |
Returns
this
This instance for chaining.
Inherited from
TextmodeSource.invert