This repo contains two crates:
- `strandify` crate contains the string art library.
- `strandify-cli` crate provides the command line interface.
And one `npm` package:
- `strandify-wasm` provides the wasm bindings and allows `strandify` to be used in the browser.
## 📦 Installation
## Command line
To use the `strandify` binary to generate string art, install the `strandify-cli` crate:
```sh
cargo install strandify-cli
```
### 📋 Usage
Once installed, you can use the `strandify` binary.
Something like:
```sh
strandify input_img.png output_img.png
```
If in doubt see the help:
```console
$ strandify -h
CLI utility to generate string art
Usage: strandify [OPTIONS] [OUTPUT]
Arguments:
Input image or blueprint json file
[OUTPUT] Output file, either image format, svg or json
Options:
-i, --iterations
Number of iterations [default: 4000]
-t
Transparent background
-c, --yarn-color
Yarn color [default: "0 0 0"]
--project-to-yarn-color
Project image to yarn color
-S, --peg-shape
Peg distribution shape [default: circle] [possible values: circle, square, border]
-n, --peg-number
Number of pegs. Depending on the shape, can be slightly off [default: 288]
-m, --peg-margin
Margin between pegs and image edge [0, 1] [default: 0.05]
-j, --peg-jitter
Add jitter to the peg position
-s, --peg-skip-within
Don't connect pegs within pixel distance
-O, --yarn-opacity
Yarn opacity to use to render the image [0, 1] [default: 0.2]
-W, --yarn-width
Yarn width to use to render the image [default: 1]
-o, --line-opacity
Line opacity to use when computing the path, controls how much to lighten the pixels at each line pass, low values encourage more line overlap [0, 1] [default: 0.1]
-w, --line-width
Line width to use when computing the path [default: 2]
-b, --beam-width
Beam search width, a value of 1 results in a purely greedy algorithm [default: 1]
-e, --early-stop-threshold
If provided, early stop pathing when consecutive path losses are greater than threshold
-E, --early-stop-count
Number of consecutive iterations with path losses above threshold to allow [default: 100]
--output-scale
Output scale [default: 1]
--save-pegs
Write pegs to file
--load-pegs
Read pegs from file
-v, --verbose...
Increase logging verbosity
-q, --quiet...
Decrease logging verbosity
-h, --help
Print help
```
## Library
To use the library as a dependency in your project, add the `strandify` crate:
```sh
cargo add strandify
```
See the [docs](https://docs.rs/strandify) for usage.
## Wasm
To use the `wasm` bindings in your project, add the `strandify-wasm` `npm` package:
```sh
npm add strandify-wasm
```
I would recommend taking a look at the [demo page's source code](https://github.com/loiccoyle/strandify/tree/gh-pages) to see how to use it.
## 👓 Examples
See the [examples](https://github.com/loiccoyle/strandify/tree/main/examples) folder.