10 unstable releases (3 breaking)

0.4.3 Sep 19, 2024
0.4.2 Sep 9, 2024
0.4.0 Aug 26, 2024
0.3.0 Aug 26, 2024
0.1.0 Aug 15, 2024

#3 in #generative-art

Download history 400/week @ 2024-08-12 38/week @ 2024-08-19 330/week @ 2024-08-26 139/week @ 2024-09-02 115/week @ 2024-09-09 137/week @ 2024-09-16 28/week @ 2024-09-23

431 downloads per month
Used in strandify-cli

MIT license

60KB
1K SLoC

A string art generation library.

# Main Structs

Pather

The Pather struct is responsible for computing the path between pegs and generates a Blueprint. The pathing algorithm is configured with the PatherConfig.

PatherConfig

The PatherConfig struct contains configuration parameters for computing the string path.

Blueprint

The Blueprint struct represents computed string path between the pegs. It contains the peg order and provides method to render it to file.

Yarn

The Yarn struct is used to control how to render the image, and it is also used to influence the pathing algorithm.

Peg

The Peg struct represents a peg in the yarn pattern.

Helpful functions

strandify provides a few function which could come in handy.

Opening images

To help with handling alpha channels use open_img_transparency_to_white.

Peg shapes

strandify provides a few helpful function to help position Pegs in various shapes:

Usage

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();

Dependencies

~10–18MB
~262K SLoC