use std::path::Path; use image::GrayImage; use svg::node::element::Group; use truchet::{image::Image, vec2::Vec2, svg::node::element::SVG, to_svg::ToSVG}; struct ImageAdapter { image: GrayImage } impl ImageAdapter { fn new(image: GrayImage) -> Self { Self { image } } } impl Image for ImageAdapter { fn size(&self) -> Vec2 { return Vec2::new(self.image.dimensions().0 as usize, self.image.dimensions().1 as usize); } fn get_pixel_brightness(&self, pos: Vec2) -> f32 { return self.image.get_pixel(pos.x() as u32, pos.y() as u32).0[0] as f32 / 255.0; } } fn main() { // Read image from fs let dog_path = Path::new(".") .join("examples") .join("dog.jpg"); let image = image::open(dog_path).unwrap(); let grayscale_image = ImageAdapter::new(image.into_luma8()); // Generate "tiles" image let truchet = truchet::truchet_image::generate(&grayscale_image, truchet::generator::fan(Vec2::new(8, 8))); // Convert to svg and save to fs let svg = truchet.to_svg_node(); let g = Group::new() .set("transform", "scale(10 10)") .add(svg); let svg_doc = SVG::new() .add(g) .set("height", "10000px") .set("width", "10000px"); truchet::svg::save("./examples/dog_truchet.svg", &svg_doc).expect("Should save to file"); }