Skip to content

textmode.js / textmode

Class: textmode

The main entry point for the textmode.js library.

Provides static methods for creating textmode instances and managing global settings.

Accessors

version

Get Signature

ts
get static version(): string;

Returns the current version of the textmode.js library.

Example
javascript
console.log(textmode.version); // "1.0.0"
Returns

string

Methods

create()

ts
static create(sourceOrOptions?, opts?): Promise<Textmodifier>;

Create a Textmodifier instance for textmode rendering.

Parameters

sourceOrOptions?

Either an HTML canvas/video element for capturing content, or options for standalone mode.

TextmodeOptions | CaptureSource

opts?

TextmodeOptions = {}

Optional configuration options (only used when first parameter is a canvas/video element).

Returns

Promise<Textmodifier>

A Promise that resolves to a Textmodifier instance.

Example

javascript
// Create a Textmodifier for an existing canvas
const canvas = document.querySelector('canvas#myCanvas');
const textmodifier = await textmode.create(canvas);

////////

// Create a Textmodifier for a video element
const video = document.querySelector('video#myVideo');
const textmodifier = await textmode.create(video);

////////

// Create a standalone Textmodifier
const t = await textmode.create({ width: 800, height: 600 });

// Set up a draw loop for standalone usage
t.draw(() => {
  t.background(0);

  const centerX = t.width / 2;
  const centerY = t.height / 2;
  const radius = Math.min(t.width, t .height) / 3;
  const speed = 0.02; // Adjust speed of rotation

  const angle = t.frameCount * speed;
  const x = centerX + Math.cos(angle) * radius - 100;
  const y = centerY + Math.sin(angle) * radius - 50;

  // Set the fill color to white
  t.fill(255);

  // Draw a rectangle with the fill color
  t.rect(x, y, 200, 150);
});

setErrorLevel()

ts
static setErrorLevel(level): void;

Set the global error handling level for the library. This applies to all Textmodifier instances.

Parameters

level

TextmodeErrorLevel

The error handling level to set.

Returns

void

Example

javascript
// Set error level to WARNING
textmode.setErrorLevel(TextmodeErrorLevel.WARNING);