UNPKG

suranadira-core

Version:

Strokes, Elements, Words and Phases of Suranadira

85 lines (77 loc) 2.38 kB
/** * Suranadira Phases. * * @module * @exports (default) suranadiraPhases * * @link suranadira-core/phases.suranadira.js * @file Produces a Suranadira Phase of up to four positions (a Word). * @memberof suranadira-core * * @author Armands Strazds <strazds@suranadira.com> * @since 0.0.1 */ import strokes from "./strokes.suranadira"; import elements from "./elements.suranadira"; import words from "./words.suranadira"; /** * suranadiraPhases, a module producing the Suranadira Phases of up to four positions. * * Syntax: * @property {Number} value, the truth value of the Element * @property {Array} strokes, an array of arrays: ["strokeName", offset] * * @since 0.0.1 * @access public * @see strokes, elements, words * * @exports {Function} compose * @exports {Object} properties * */ const suranadiraPhases = (() => { let _properties = { ctx: null, // canvas context unit: 100, // units per size 1 lineWidth: 70, left: 0, top: 0, color: "#000" }; // Initializes phase properties const _init = () => { if (_properties.ctx === null) { console.log("Please supply canvas context"); return; } strokes.properties.ctx = _properties.ctx; strokes.properties.unit = _properties.unit; strokes.properties.lineWidth = _properties.lineWidth; strokes.properties.left = _properties.left; strokes.properties.top = _properties.top; strokes.properties.strokeStyle = _properties.color; }; // Compose a phase const _compose = ({ id, parity, positions }) => { if (typeof positions === "undefined") positions = 4; if (typeof words[id] === "undefined") return false; _init(); let type, offset, _strokes, _stroke, x; for (let position in words[id][parity]) { type = words[id][parity][position][0]; offset = words[id][parity][position][1]; _strokes = elements[type].strokes; for (let key in _strokes) { _stroke = _strokes[key][0]; x = _strokes[key][1]; strokes.draw(_stroke, x + offset + 1, position); } if (position >= positions - 1) break; } }; return { properties: _properties, compose: _compose }; })(); export default suranadiraPhases;