UNPKG

led-matrix-ts

Version:

Highly customizable led matrix for the browser

53 lines 1.65 kB
import { Exception } from "../utils/exception"; export class Character { constructor(pattern, output, width) { this.CLASS_NAME = Character.name; this._pattern = pattern; this._output = output; if (output.size >= width) { this._width = width; } else { throw `Output size (${output.size}) can't be smaller than the character's width (${width})`; } if (output.size % width === 0) { this._height = output.size / width; } else { throw `Output size (${output.size}) must be divisible by the character's width (${width})`; } } get width() { return this._width; } get height() { return this._height; } get pattern() { return this._pattern; } get output() { return this._output; } getColumn(index) { Exception.throwIfNotBetween(index, Exception.getDescriptionForProperty(this.CLASS_NAME, 'getColumn'), 0, this._width - 1); let column = []; for (let i = 0; i < this._height; i++) { column.push(this._output.atIndex(i * this._width + index)); } return column; } getRow(index) { Exception.throwIfNotBetween(index, Exception.getDescriptionForProperty(this.CLASS_NAME, 'getRow'), 0, this._height - 1); let row = []; for (let i = 0; i < this._width; i++) { row.push(this._output.atIndex(index * this._width + i)); } return row; } hasPattern(input) { return this._pattern == input; } } ; //# sourceMappingURL=character.js.map