Module: draw block frac - uhop/console-toolkit GitHub Wiki
The draw-block-frac.js module draws a block with fractional dimensions: either width or height. The "real" dimension is drawn using 1/8th blocks.
drawRealWidthBlock()
Function drawRealWidthBlock(realWidth, height, drawEmptyBorder = false)
draws a block with the specified
dimensions. height
is an integer value. realWidth
is a float value, which will be interpreted
using 1/8th steps (0.125).
drawEmptyBorder
is a boolean value that specifies whether the block should end with an empty
block (space character), if the width has a fractional part, which is close to 0 but not 0:
import {drawRealWidthBlock} from 'console-toolkit/draw-block-frac.js';
const box1 = drawRealWidthBlock(3.5, 1);
box1.width === 4;
const box2 = drawRealWidthBlock(3.1, 1);
box2.width === 4;
const box3 = drawRealWidthBlock(3.01, 1);
box3.width === 3;
const box4 = drawRealWidthBlock(3.01, 1, true);
box4.width === 4;
const box5 = drawRealWidthBlock(3, 1, true);
box5.width === 3;
The return values is a Box
object. The integer part is fill with full blocks
and the optional fractional part is on the right.
drawRealHeightBlock()
Function drawRealHeightBlock(width, realHeight, drawEmptyBorder = false)
draws a block with the specified
dimensions. width
is an integer value. realHeight
is a float value, which will be interpreted
using 1/8th steps (0.125).
This function is similar to drawRealWidthBlock()
. The difference is that it draws a block oriented
vertically with the optional fractional part on the top.
Exports
The drawRealWidthBlock()
and drawRealHeightBlock()
functions are exported by name.