textmode.js / loadables / TextmodeVideo
Class: TextmodeVideo
Represents a video element for textmode rendering via Textmodifier.loadVideo.
It can be drawn to the canvas via Textmodifier.image.
A video uploaded currently runs through an adjustable brightness-converter that converts the video frames into a textmode representation using characters. Those adjustable options are available via chainable methods on this interface.
const t = textmode.create({
width: 800,
height: 600,
});
let video;
t.setup(async () => {
video = await t.loadVideo('https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4');
// Start playback and enable looping so the video keeps playing
video.play();
video.loop();
video.characters(" .:-=+*#%@");
// ... other adjustments like video.flipX(boolean), video.cellColorMode('sampled' | 'fixed'), etc.
// (can also be chained or updated during runtime)
});
t.draw(() => {
t.background(0);
// Draw the loaded video
t.image(video);
});Extends
TextmodeSource
Implements
ITextmodeVideo
Accessors
currentTime
Get Signature
get currentTime(): number;Current playback time in seconds.
Returns
number
Implementation of
ITextmodeVideo.currentTimeduration
Get Signature
get duration(): number;Total duration of the video in seconds.
Returns
number
Implementation of
ITextmodeVideo.durationheight
Get Signature
get height(): number;Ideal height in grid cells.
Returns
number
Implementation of
ITextmodeVideo.heightInherited from
TextmodeSource.heightisPlaying
Get Signature
get isPlaying(): boolean;Whether the video is currently playing.
Returns
boolean
Implementation of
ITextmodeVideo.isPlayingoriginalHeight
Get Signature
get originalHeight(): number;Original pixel height.
Returns
number
Implementation of
ITextmodeVideo.originalHeightInherited from
TextmodeSource.originalHeightoriginalWidth
Get Signature
get originalWidth(): number;Original pixel width.
Returns
number
Implementation of
ITextmodeVideo.originalWidthInherited from
TextmodeSource.originalWidthtexture
Get Signature
get texture(): WebGLTexture;Return the WebGL texture currently backing this source.
Returns
WebGLTexture
Implementation of
ITextmodeVideo.textureInherited from
TextmodeSource.texturevideoElement
Get Signature
get videoElement(): HTMLVideoElement;The underlying HTML video element.
Returns
HTMLVideoElement
Implementation of
ITextmodeVideo.videoElementwidth
Get Signature
get width(): number;Ideal width in grid cells.
Returns
number
Implementation of
ITextmodeVideo.widthInherited 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.
Implementation of
ITextmodeVideo.backgroundInherited 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.
Implementation of
ITextmodeVideo.cellColorInherited 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.
Implementation of
ITextmodeVideo.cellColorModeInherited 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.
Implementation of
ITextmodeVideo.charactersInherited 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.
Implementation of
ITextmodeVideo.charColorInherited 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.
Implementation of
ITextmodeVideo.charColorModeInherited 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.
Implementation of
ITextmodeVideo.charRotationInherited from
TextmodeSource.charRotationconversionMode()
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 | string | Conversion mode to use. |
Returns
this
Implementation of
ITextmodeVideo.conversionModeInherited 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.
Implementation of
ITextmodeVideo.flipXInherited 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.
Implementation of
ITextmodeVideo.flipYInherited 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.
Implementation of
ITextmodeVideo.invertInherited from
TextmodeSource.invertloop()
loop(shouldLoop): this;Set whether the video should loop.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
shouldLoop | boolean | true | Whether to loop (defaults to true) |
Returns
this
Implementation of
ITextmodeVideo.looppause()
pause(): void;Pause the video.
Returns
void
Implementation of
ITextmodeVideo.pauseplay()
play(): Promise<void>;Play the video.
Returns
Promise<void>
Promise that resolves when playback starts
Implementation of
ITextmodeVideo.playspeed()
speed(rate): this;Set the playback speed.
Parameters
| Parameter | Type | Description |
|---|---|---|
rate | number | Playback rate (1.0 = normal speed) |
Returns
this
Implementation of
ITextmodeVideo.speedstop()
stop(): void;Stop the video and reset to beginning.
Returns
void
Implementation of
ITextmodeVideo.stoptime()
time(seconds): this;Set the current time position in the video.
Parameters
| Parameter | Type | Description |
|---|---|---|
seconds | number | Time in seconds |
Returns
this
Implementation of
ITextmodeVideo.timevolume()
volume(level): this;Set the volume.
Parameters
| Parameter | Type | Description |
|---|---|---|
level | number | Volume level (0.0-1.0) |
Returns
this
Implementation of
ITextmodeVideo.volume