| Crates.io | strandify |
| lib.rs | strandify |
| version | 0.4.3 |
| created_at | 2024-08-15 22:34:16.722121+00 |
| updated_at | 2024-09-19 17:17:12.153373+00 |
| description | A string art generation library. |
| homepage | |
| repository | https://github.com/loiccoyle/strandify |
| max_upload_size | |
| id | 1339685 |
| size | 105,574 |

A string art generation library.
# Main StructsPatherThe Pather struct is responsible for computing the path between pegs and generates a Blueprint. The pathing algorithm is configured with the PatherConfig.
PatherConfigThe PatherConfig struct contains configuration parameters for computing the string path.
BlueprintThe Blueprint struct represents computed string path between the pegs. It contains the peg order and provides method to render it to file.
YarnThe Yarn struct is used to control how to render the image, and it is also used to influence the pathing algorithm.
PegThe Peg struct represents a peg in the yarn pattern.
strandify provides a few function which could come in handy.
To help with handling alpha channels use open_img_transparency_to_white.
strandify provides a few helpful function to help position Pegs in various shapes:
Provided is a snippet showcasing some basis usage.
use strandify::blueprint;
use strandify::peg;
use strandify::pather;
use strandify::utils;
let input_file = "tests/input.jpg";
let output_file = "tests/output.png";
// Open the input image and convert it to grayscale
let img_rgb = utils::open_img_transparency_to_white(input_file).unwrap();
let img = image::imageops::grayscale(&img_rgb);
// Define the pegs for the pathing
let (width, height) = img_rgb.dimensions();
let min_dim = std::cmp::min(width, height);
let margin = (min_dim as f64 * 0.02).round() as u32; // 2% margin
let center = (width / 2, height / 2);
// We'll be using a circle
let pegs = peg::shape::circle(center, (min_dim - 2 * margin) / 2, 100);
// Set up the configuration for the Pather
let config = pather::PatherConfig::default();
// Generate the yarn pattern
let mut string_pather = pather::Pather::new(img, pegs, config);
let bp = string_pather.compute().unwrap();
// Save the generated blueprint
bp.render(&output_file, &peg::Yarn::default()).unwrap();