GitXplorerGitXplorer
g

entropretty

public
11 stars
7 forks
0 issues

Commits

List of commits on branch main.
Verified
49484e920227e8ef7a4afb2538e2d1d449645476

Merge pull request #14 from peetzweg/pz-fix-roman

ggavofyork committed 5 months ago
Verified
4b148760643eefb9c1cba615f074c9d6cb0afeeb

translate before drawing roman numerals

ppeetzweg committed 5 months ago
Unverified
d3dfe8c755de9b4bb27fe88d7d2ad9280edbc9b8

Fix

ggavofyork committed 5 months ago
Verified
c76e60a1f8275e82b41cf20577c1007cce5ef119

Merge pull request #13 from gavofyork/gav-star

ggavofyork committed 5 months ago
Unverified
87440bf0d923d854541771fd0c6a8470d7266874

Update gitignore

ggavofyork committed 5 months ago
Unverified
f8525d6f7c4ad73f3b87a27bbaef49ac56fd266d

Move to new API

ggavofyork committed 5 months ago

README

The README file for this repository.

Entropretty

A simple Javascript-based entropy-to-graphic harness.

Try it at https://gavofyork.github.io/entropretty/.

image

Usage

npm install
npm run bundle
npm start

Playing around

  1. Create a new .js file with a unique name, for example mydesign.js.
  2. 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));
}
  1. Export your new design as schema with a line like:
export const schema = { draw, name: "My Cool Design", artist: "myartistname" };
  1. Include your file in the const DESIGNS array of artist.js.

The Draw Function

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';

Seeds

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 the nth bit from the seed, indexed from 0. Returns either 0 or 1.
  • bits(seed, from, to): Get a number built from the bits of seed of the given span from and to.
  • 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 the seed.
  • 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 also cheapRandomGenerator (using SFC32) and secureRandomGenerator (using SHA-256).