Skip to main content

Crate kanoko

Crate kanoko 

Source
Expand description

A Rust library for generative art (initially) based off of a traditional Japanese tie-dye pattern.

§Description

Define a Canvas with a PointSet. Then add Shapes to be drawn on each point in the PointSet.

Each point in the PointSet has an associated Index. This gets passed to the Shape so that you can control if and how the shape gets rendered depending on its Index.

§Example

use kanoko::{Canvas, point_set::lattice::Lattice, shape::Polygon};

/// An example with minimal randomization, based on the traditional Japanese tie-dye pattern
fn main() {
    let background_color = "#002e4e".try_into().unwrap();
    let mut canvas_builder = Canvas::builder()
        .size(2560.0, 1440.0)
        .background_color(background_color)
        .points(
            Lattice::diamond_builder()
                .grid_size(19, 16)
                .len_a(90.0)
                .build(),
        );

    canvas_builder.add_shape(
        Polygon::builder()
            .sides(4)
            .size(70.0)
            .color("#f5f5fa".try_into().unwrap())
            .build(),
    );
    canvas_builder.add_shape(
        Polygon::builder()
            .sides(4)
            .size(35.0)
            .color(background_color)
            .build(),
    );

    let canvas = canvas_builder.build();
    let document = canvas.render(|_| true);
    svg::save("examples/kanoko.svg", &document).unwrap();
}

Re-exports§

pub use canvas::Canvas;

Modules§

canvas
geometry
point_set
shape

Structs§

Color
A color and opacity