#mosaic #image #starry #generate #graphics

starry_mosaic

A library for generating colorful mosaic images with various geometrical patterns

4 releases (breaking)

0.4.0 Oct 17, 2022
0.3.0 Sep 10, 2022
0.2.0 Jul 6, 2022
0.1.0 Jun 24, 2022

#802 in Images

MIT license

180KB
3K SLoC

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.

Dependencies

~9MB
~138K SLoC