starry_mosaic

Crates.iostarry_mosaic
lib.rsstarry_mosaic
version0.4.0
sourcesrc
created_at2022-06-24 15:53:58.262626
updated_at2022-10-17 19:08:25.41367
descriptionA library for generating colorful mosaic images with various geometrical patterns.
homepagehttps://github.com/OneEyeMaker/starry_mosaic
repositoryhttps://github.com/OneEyeMaker/starry_mosaic
max_upload_size
id612459
size183,548
Alexander Anishin (OneEyeMaker)

documentation

README

Logo

StarryMosaic

Crates.io docs.rs Continuous integration

A library for generating colorful mosaic images with various geometrical patterns.

How to create mosaic image

To create mosaic simply:

  • set size of resulting image;
  • choose shape which mosaic is based on,
  • set its position, rotation and scale
  • and finally build selected type of mosaic.

Then this mosaic can be painted with any color or gradient.

Example

Next code creates logo of this project (the one you can see above).

use palette::LinSrgb;
use starry_mosaic::{coloring_method::RadialGradient, Mosaic, MosaicBuilder, Vector};

let mosaic = MosaicBuilder::default()
    .set_regular_polygon_shape(13)
    .set_image_size(800, 800)
    .set_center(Vector::new(400.0, 400.0))
    .set_uniform_scale(0.75)
    .build_star()
    .unwrap();

let gradient = vec![
    (0.125, LinSrgb::new(1.0f64, 0.0, 0.0)),
    (0.275, LinSrgb::new(1.0f64, 0.5, 0.0)),
    (0.425, LinSrgb::new(1.0f64, 1.0, 0.0)),
    (0.575, LinSrgb::new(0.0f64, 1.0, 0.0)),
    (0.725, LinSrgb::new(0.0f64, 0.75, 1.0)),
    (0.875, LinSrgb::new(0.0f64, 0.0, 1.0)),
];
let mosaic_image = mosaic.draw(RadialGradient::new(
    gradient,
    Vector::new(540.0, 320.0),
    20.0,
    Vector::new(400.0, 400.0),
    360.0,
    0.25
));

let save_result = mosaic_image.save("target/logo.png");
assert!(save_result.is_ok());

More images

To see more images visit images directory in repository of this project.

Commit count: 153

cargo fmt