-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Fileoverview
This file is the entry point for the @sister.software/asciify module.
See
Copyright
Sister Software. All rights reserved.
License
MIT
Author
Teffen Ellis
▸ 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
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
|
Uint8ClampedArray
▸ 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
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
|
Promise
<Uint8ClampedArray
>
▸ 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
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
|
Uint8ClampedArray
A Uint8ClampedArray containing the RGBA pixel buffer
▸ calculateTextureMetrics(fontSize
, pixelRatio
): TextureMetrics
Internel
Name | Type |
---|---|
fontSize |
number |
pixelRatio |
number |
▸ normalizeNumericOption(min
, value
, max
): number
Name | Type |
---|---|
min |
number |
value |
string | number
|
max |
number |
number
• Const
OptionPresets: Object
A collection of ready-made character presets.
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 |
- |
• Const
DEFAULT_CHARACTER_SET: "..,'\":;-~=+*#&%@"
• Const
DEFAULT_CONTRAST_RATIO: 3
• Const
DEFAULT_FONT_SIZE: 12
• Const
DEFAULT_PIXEL_RATIO: number
Ƭ 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
Ƭ 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
Ƭ CharacterCoords: Map
<number
, [number
, number
]>
Ƭ PixelIndex: Uint32Array
Ƭ 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.
Name |
---|
T |