Render tesseracts as text
npm install ascii-hypercubeonline on this webpage。
sh
npm install ascii-hypercube
`
Use in your code:
`js
const { renderHypercube } = require('ascii-hypercube')
const dimensions = [
{ length: 4, xPerGlyph: 2, yPerGlyph: 0, text: "CUBIC" },
{ length: 4, xPerGlyph: 0, yPerGlyph: 1, text: "CUBIC" },
{ length: 2, xPerGlyph: -2, yPerGlyph: 1, text: "/" },
];
const { text, numOverlaps, overlaps } = renderHypercube(dimensions);
console.log(text);
`
If you want to use the browser version, you can include the script in your HTML:
`html
`
and it will define a global renderHypercube function.
API
$3
- dimensions is an array of objects with the following properties:
- length is the number of steps between the first and last glyph along the dimension. It should be one less than the number of glyphs to be plotted.
- xPerGlyph is the number of characters to move right for each plotted glyph
- yPerGlyph is the number of characters to move down for each plotted glyph
- text is the text to render along edges of the dimension. It is repeated if length is greater than or equal to the length of the text.
- glyphs is an alternative to text if you have already split the text into graphemes. Exactly one of text or glyphs should be provided.
- splitter is an optional GraphemeSplitter object with a splitGraphemes method.
- When loaded in a browser, the library will try to use the global GraphemeSplitter if available.
- In Node.js, grapheme-splitter is included as a dependency and will be used automatically.
- If you want to use a different library or a custom implementation, you can pass it in here.
- Returns an object with the following properties:
- text is the rendered hypercube as a string
- numOverlaps is the number of times a glyph was plotted that didn't match the glyph that was already there
- overlaps is an object that gives statistics about the overlaps.
- Each key is a glyph that was overwritten, and each value is an object with keys being overriding glyphs and values being the number of times that overlap occurred.
CLI
You can also use the command-line interface. If you have Node.js installed, you can simply use npx to run it:
`sh
npx ascii-hypercube -d 2,0 3 'TEST' -d 0,1 3 'TEXT' -d -1,1 4 '///'
`
To install as a global command:
`sh
npm install -g ascii-hypercube
`
Then you can run it without npx.
`HELP_OUTPUT
usage: ascii-hypercube [-h] [-d TRAVEL LENGTH TEXT] [-s]
CLI to render hypercubes with text along an arbitrary number of dimensions
optional arguments:
-h, --help show this help message and exit
-d TRAVEL LENGTH TEXT, --dimension TRAVEL LENGTH TEXT
Define a dimension, with travel per glyph, length of
edges along the dimension, and text. Can be specified
multiple times. Travel must be given as a pair of
numbers with no spaces, e.g. "-1,0" or "(-1,0)"
-s, --stats Print statistics about the overlaps
Example: ascii-hypercube -d 2,0 11 'RATHER HYPER' -d 0,1 11 'RATHER HYPER' -d
1,1 4 '\\' -d 3,1 8 '\~' -d -1,1 3 '\/'
`
Development
This project is written in CoffeeScript.
$3
Add tests to src/test.js and run them with:
`sh
npm test
`
$3
Any static file server will do. One that auto-reloads is nice:
`sh
npx live-server .
`
$3
Update help in this readme with:
`sh
npm run update-cli-docs
``