Skip to content
Teffen Ellis edited this page Feb 15, 2023 · 9 revisions

Asciify by Sister Software

Fileoverview

This file is the entry point for the @sister.software/asciify module.

See

API documentation

Copyright

Sister Software. All rights reserved.

License

MIT

Author

Teffen Ellis

Table of contents

Main Classes

Other Classes

Utility Classes

Configuration Interfaces

Other Interfaces

Helper Functions

Other Functions

Configuration Variables

Other Variables

Type Aliases

Helper Functions

readFromCanvas

readFromCanvas(ctx): Uint8ClampedArray

Reads the pixel buffer from a canvas element. This function is useful when you want to rasterize an existing canvas to ASCII art.

See

Parameters

Name Type Description
ctx Canvas2dContextLike The 2D context to read from. Make sure to provide a canvas with the same dimensions as the asciify instance you're using. See setSize

Returns

Uint8ClampedArray

Defined in

utils/readers.mts:28


readFromImage

readFromImage(sourceImage, ctx): Promise<Uint8ClampedArray>

Reads the pixel buffer from an image element. This function is useful when you want to rasterize an image to ASCII art.

See

Parameters

Name Type Description
sourceImage CanvasImageSource The image to read pixels from. This will be resized to match the next given canvas argument.
ctx Canvas2dContextLike The 2D context to read from. Make sure to provide a canvas with the same dimensions as the asciify instance you're using. See setSize

Returns

Promise<Uint8ClampedArray>

Defined in

utils/readers.mts:51


readFromVideo

readFromVideo(video, canvas?): Uint8ClampedArray

Reads the pixel buffer from a video element. This function is useful when you want to rasterize a video to ASCII art.

See

Parameters

Name Type Description
video HTMLVideoElement The video to read pixels from. See - MDN on HTMLVideoElement - MDN on HTMLMediaElement - MDN on Media captureStream - MDN on Canvas captureStream
canvas CanvasLike A canvas to use for reading the video. You should provide this parameter if you'd like to cache the canvas. Optional

Returns

Uint8ClampedArray

A Uint8ClampedArray containing the RGBA pixel buffer

Defined in

utils/readers.mts:91


Other Functions

calculateTextureMetrics

calculateTextureMetrics(fontSize, pixelRatio): TextureMetrics

Internel

Parameters

Name Type
fontSize number
pixelRatio number

Returns

TextureMetrics

Defined in

utils/TextureCache.mts:117


normalizeNumericOption

normalizeNumericOption(min, value, max): number

Parameters

Name Type
min number
value string | number
max number

Returns

number

Defined in

options/common.mts:130

Configuration Variables

OptionPresets

Const OptionPresets: Object

A collection of ready-made character presets.

Type declaration

Name Type Description
ascii { characterSet: string = DEFAULT_CHARACTER_SET } A default character set to use for the ASCII art. This looks good with both black and white and color output.
ascii.characterSet string -
asterisks { characterSet: string ; characterSpacingRatio: number = 1.5; contrastRatio: number = 2; fontSize: number = 8 } -
asterisks.characterSet string -
asterisks.characterSpacingRatio number -
asterisks.contrastRatio number -
asterisks.fontSize number -
blocks { characterSet: string } A richer character set made of dithered blocks.
blocks.characterSet string -
chess { characterSet: string ; characterSpacingRatio: number = 1; contrastRatio: number = 0; fontSize: number = 12 } -
chess.characterSet string -
chess.characterSpacingRatio number -
chess.contrastRatio number -
chess.fontSize number -
circles { characterSet: string ; characterSpacingRatio: number = 1; contrastRatio: number = 2 } A character set made of circular shapes.
circles.characterSet string -
circles.characterSpacingRatio number -
circles.contrastRatio number -
diamonds { characterSet: string ; characterSpacingRatio: number = 1; contrastRatio: number = 2 } A character set made of diamond shapes.
diamonds.characterSet string -
diamonds.characterSpacingRatio number -
diamonds.contrastRatio number -
faces { characterSet: string = '🫥😶😑😐😏😵🤩'; contrastRatio: number = 0 } -
faces.characterSet string -
faces.contrastRatio number -
hands { characterSet: string ; contrastRatio: number = 0; fontFamily: string } -
hands.characterSet string -
hands.contrastRatio number -
hands.fontFamily string -
numerals { characterSet: string ; characterSpacingRatio: number = 1; contrastRatio: number = 0; fontSize: number = 20 } A character set made of numerals.
numerals.characterSet string -
numerals.characterSpacingRatio number -
numerals.contrastRatio number -
numerals.fontSize number -
squares { characterSet: string } A character set made of squares.
squares.characterSet string -
stacks { characterSet: string } A character set made of dithered stacks.
stacks.characterSet string -
thin { characterSet: string } A character set made of thin blocks.
thin.characterSet string -

Defined in

options/presets.mts:14


Other Variables

DEFAULT_CHARACTER_SET

Const DEFAULT_CHARACTER_SET: "..,'\":;-~=+*#&%@"

Defined in

options/common.mts:121


DEFAULT_CONTRAST_RATIO

Const DEFAULT_CONTRAST_RATIO: 3

Defined in

options/common.mts:120


DEFAULT_FONT_SIZE

Const DEFAULT_FONT_SIZE: 12

Defined in

options/common.mts:119


DEFAULT_PIXEL_RATIO

Const DEFAULT_PIXEL_RATIO: number

Defined in

options/common.mts:118

Type Aliases

Canvas2dContextLike

Ƭ Canvas2dContextLike: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D

Either a canvas 2D context or an offscreen canvas 2D context. Note that the offscreen canvas support varies between browsers. Safari tends to produce slight visual artifacts when using offscreen canvases.

See

MDN on Offscreen Canvas 2D Context

Defined in

utils/canvas.mts:28


CanvasLike

Ƭ CanvasLike: OffscreenCanvas | HTMLCanvasElement

Either a canvas or an offscreen canvas. Note that the offscreen canvas support varies between browsers. Safari tends to produce slight visual artifacts when using offscreen canvases.

See

MDN on Offscreen Canvas

Defined in

utils/canvas.mts:19


CharacterCoords

Ƭ CharacterCoords: Map<number, [number, number]>

Defined in

utils/LookupTable.mts:1


PixelIndex

Ƭ PixelIndex: Uint32Array

Defined in

utils/LookupTable.mts:3


WithStringlyNumbers

Ƭ WithStringlyNumbers<T>: { [P in keyof T]: T[P] extends number ? T[P] | string : T[P] }

Type utility that allows number properties to be strings. Useful for accepting form inputs.

Type parameters

Name
T

Defined in

options/common.mts:126