A simple Javascript-based entropy-to-graphic harness.
Try it at https://gavofyork.github.io/entropretty/.
npm install
npm run bundle
npm start
- Create a new
.js
file with a unique name, for examplemydesign.js
. - Define a
draw
function in it which places a unique design onto a canvas for any given 4-byte seed, e.g.:
function draw(ctx, seed) {
ctx.font = '25px serif';
seed.forEach((n, i) => ctx.fillText(n, 50, i * 25 + 25, 100));
}
- Export your new design as
schema
with a line like:
export const schema = { draw, name: "My Cool Design", artist: "myartistname" };
- Include your file in the
const DESIGNS
array ofartist.js
.
Draw functions take two arguments; the context and the seed. The context is a Javascript canvas 2D drawing context with width and height each 100 px.
It may be assumed to be initialized thus:
ctx.lineWidth = 1;
ctx.lineCap = 'butt';
ctx.lineJoin = 'miter';
ctx.strokeStyle = 'black';
ctx.fillStyle = 'black';
ctx.textAlign = 'center';
ctx.textBaseline = 'bottom';
A seed represents the entropy of a figure and is just an array of four bytes (numbers between 0 and 255 inclusive). The reason for four bytes rather than a single 32-bit integer is Javascript's habit of turning such large integers into negative values whenever it feels like it.
There are several functions provided for operating on seeds:
-
bit(seed, n)
: Get then
th bit from theseed
, indexed from0
. Returns either0
or1
. -
bits(seed, from, to)
: Get a number built from the bits ofseed
of the given spanfrom
andto
. -
bits(seed)
: Get a number built from all bits of the seed, somewhere between 0 and 2**32 - 1 inclusive. -
split(seed, parts)
: Return an array of numbers,parts
in length, each using approximately the same number of bits from theseed
. -
randomGenerator(seed)
: Return a function which itself takes no arguments and returns a stream of random numbers between 0 and 1. This uses the Prando algorithm. There is alsocheapRandomGenerator
(using SFC32) andsecureRandomGenerator
(using SHA-256).