Module: pcface

Exported module of PC Face.

Source:

Methods

(static) drawChar(bitmaps, ctx, c, x, y, scale)

Draw a single character on a canvas using the given canvas context. The (x, y) coordinates represent the top-left corner of the glyph. The x-coordinate represents the column index the leftmost edge of the glyph. Similarly, the y-coordinate represents the row index of the topmost edge of the glyph. The character c may either be an integer ASCII code of a CP437 character or a string containing a single Unicode character that represents a CP437 character.

If c is an ASCII code, then bitmaps must be an array of bitmaps. If s is a string containing a single Unicode character, then bitmaps must be an object that maps each Unicode character that represents a CP437 character to its bitmap array.

Parameters:
Name Type Description
bitmaps Array | Object

An array/object containing bitmap arrays.

ctx CanvasRenderingContext2D

Canvas context.

c number | string

Character to draw on canvas.

x number

X coordinate of the leftmost edge of the glyph.

y number

Y coordinate of the topmost edge of the glyph.

scale number

Scale multiplier.

Source:

(static) drawString(bitmaps, ctx, s, w, x, y, scale)

Draw a single string with its top-left corner placed at coordinate (x, y). The string s may either be an array of integers where each integer is an ASCII code of a CP437 character of it may be a string of Unicode characters where each Unicode character represents a CP437 character.

If s is an array of ASCII codes, then bitmaps must be an array of bitmaps. If s is a string of Unicode characters, then bitmaps must be an object that maps each Unicode character that represents a CP437 character to its bitmap array.

Parameters:
Name Type Description
bitmaps Array | Object

An array/object containing bitmap arrays.

ctx CanvasRenderingContext2D

Canvas context.

s Array | string

Characers to draw on canvas.

w number

Horizontal width to allocate for each glyph.

x number

X coordinate of the leftmost edge of the glyphs.

y number

Y coordinate of the topmost edge of the glyphs.

scale number

Scale multiplier (should be a positive integer).

Source:

(static) drawStrings(ctx, bitmaps, w, h, ss, x, y, scale)

Draw multiple strings with the top-left corner of the first string placed at coordinate (x, y). Each subsequent string is placed below the previous one. The height h specifies the distance between the top edge of one string and the top edge of the next one. The width w specifies the distance between the left edge of one glyph and the left edge of the next one.

The string s may either be an array of array of integers where each integer is an ASCII code of a CP437 character of it may be an array of strings of Unicode characters where each Unicode character represents a CP437 character.

If s is an array of array of ASCII codes, then bitmaps must be an array of bitmaps. If s is an array of strings of Unicode characters, then bitmaps must be an object that maps each Unicode character that represents a CP437 character to its bitmap.

Parameters:
Name Type Description
ctx CanvasRenderingContext2D

Canvas context.

bitmaps Array | Object

An array or an object of bitmap arrays.

w number

Horizontal width to allocate for each glyph.

h number

Horizontal height to allocate for each glyph.

ss Array

An array of array of integers or an array of strings.

x number

X coordinate of the leftmost edge of the glyphs.

y number

Y coordinate of the topmost edge of the glyphs.

scale number

Scale multiplier (should be a positive integer).

Source:

(static) range(start, stop)

Create an array of consecutive integers with start as the first integer and stop - 1 as the last integer in the array. This function may be useful for creating a range of CP437 character codes for demos. For example, calling pcface.range(65, 70) returns [65, 66, 67, 68, 69] which can then be passed to module:pcface.drawString to draw the glyphs represented by these integers.

Parameters:
Name Type Description
start number

Start integer.

stop number

Stop integer.

Source:

(static) ranges(start, stop, chunk)

Return an array of arrays of integers. This function may be useful for creating ranges of CP437 character codes for demos. All nested arrays together contain consecutive integers from start to stop - 1. These integers are split into multiple nested arrays such that each nested array contains no more than chunk number of integers. For example, calling pcface.range(65, 78, 5) returns [[65, 66, 67, 68, 69], [70, 71, 72, 73, 74], [75, 76, 77]]. This array of arrays can then be passed to module:pcface.drawStrings to draw the glyphs represented by these integers.

Parameters:
Name Type Description
start number

Start integer.

stop number

Stop integer.

chunk number

Maximum length of each nested array.

Source: