Procedurally generate a unique snowflake from a hash.
There will eventually be a post on joshleeb.com explaining how the Snowhash algorithm works. In the mean time there is a demo up at joshleeb.com/projects/snowhash.
$ tree . -L 1
.
├── snowhash // library containing procedural generation logic
├── snowhash_png // binary to generate snowflake as png image
└── snowhash_wasm // wasm library to be used with javascript
$ cargo build && ./target/debug/snowhash_png --help
Snowhash 0.1.0
Josh Leeb-du Toit <[email protected]>
Procedurally generate a unique snowflake from a hash
USAGE:
snowhash_png [OPTIONS] <HASH>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-o, --output <OUTPUT> Output path for the generated PNG
ARGS:
<HASH> Hash to use for generating the snowflake
For example, using the first commit hash from this repo: 1f83a1a1cdfa28cb1eb42a41078be4080051e87d
$ snowhash_png 1f83a1a1cdfa28cb1eb42a41078be4080051e87d
Which will generate 1f83a1a1cdfa28cb1eb42a41078be4080051e87d.png
To build just the snowhash
library:
$ git clone https://github.com/joshleeb/snowhash.git && cd snowhash/snowhash
$ cargo build
To build the snowhash_png
binary:
$ git clone https://github.com/joshleeb/snowhash.git && cd snowhash
$ cargo build
And then to run:
$ ./target/debug/snowhash_png
snowhash_png
uses cairo
to create the PNG of the snowflake. The cairo-rs
crate is a wrapper around the cairo
clib so it must be installed.
To build the snowhash_wasm
library:
$ git clone https://github.com/joshleeb/snowhash.git && cd snowhash/snowhash_wasm
$ ./build.sh
The build.sh
script will compile the snwohash library to target wasm32-unknown-unknown
. To run a development server use webpack-dev-server
and navigate to localhost:8080
in your browser. Or, to create a minified version, just run webpack
which will create the dist/
directory containing the minified js
and wasm
code.
webpack
is required to bundle the compiled wasm
and the js
scripts. And webpack-dev-server
is required to serve the scripts in a development environment.
This project is based on Snowflake by Raph Levein which is "an implementation of procedural generation of snowflakes."