use svg_filters::{
    codegen::SvgDocument,
    types::nodes::{
        primitives::{
            blend::BlendMode,
            color_matrix::ColorMatrixType,
            component_transfer::TransferFn,
            displacement_map::Channel,
            turbulence::{NoiseType, StitchTiles},
        },
        standard_input::StandardInput,
    },
};

fn main() {
    let mut doc = SvgDocument::new();

    let f = doc.create_filter("cmyk-chromabb");

    let noise = f.turbulence(0., 0.1, 2, 0, StitchTiles::Stitch, NoiseType::FractalNoise);
    let noise = f.component_transfer_rgba(
        noise,
        TransferFn::Discrete {
            table_values: vec![0., 0.2, 0.4, 0.6, 0.8, 1.],
        },
        TransferFn::Discrete {
            table_values: vec![0., 0.2, 0.4, 0.6, 0.8, 1.],
        },
        TransferFn::Discrete {
            table_values: vec![0., 0.2, 0.4, 0.6, 0.8, 1.],
        },
        TransferFn::Linear {
            slope: 0.,
            intercept: 0.5,
        },
    );

    let cyan = f.color_matrix(
        StandardInput::SourceGraphic,
        ColorMatrixType::Matrix(Box::new([
            0., 0., 0., 0., 0., //
            0., 1., 0., 0., 0., //
            0., 0., 1., 0., 0., //
            0., 0., 0., 1., 0.,
        ])),
    );
    let cyan = f.offset(cyan, 25., 0.);
    let cyan = f.displacement_map(cyan, noise, 50., Channel::R, Channel::A);

    let magenta = f.color_matrix(
        StandardInput::SourceGraphic,
        ColorMatrixType::Matrix(Box::new([
            1., 0., 0., 0., 0., //
            0., 0., 0., 0., 0., //
            0., 0., 1., 0., 0., //
            0., 0., 0., 1., 0.,
        ])),
    );
    let magenta = f.displacement_map(magenta, noise, 50., Channel::R, Channel::A);
    let magenta = f.offset(magenta, -25., 0.);

    f.blend(cyan, magenta, BlendMode::Screen);

    println!("{}", doc.generate_svg_pretty());
}
