use std::path::Path;
use tilezz::cyclotomic::ZZ12;
use tilezz::geom::snake::{Snake, Turtle};
use tilezz::geom::tiles::spectre;
use tilezz::vis::draw::TileStyle;
use tilezz::vis::plotutils::P64;
use tilezz::vis::raster;
use tilezz::vis::scene::{Color, Fill, Scene, Stroke, Viewport};
fn main() {
let snake: Snake<ZZ12> = spectre();
let polyline: Vec<P64> = snake.to_polyline_f64(Turtle::default());
let (mut min_x, mut min_y) = (f64::INFINITY, f64::INFINITY);
let (mut max_x, mut max_y) = (f64::NEG_INFINITY, f64::NEG_INFINITY);
for &(x, y) in &polyline {
min_x = min_x.min(x);
max_x = max_x.max(x);
min_y = min_y.min(y);
max_y = max_y.max(y);
}
let cx = (min_x + max_x) / 2.0;
let cy = (min_y + max_y) / 2.0;
let half = ((max_x - min_x).max(max_y - min_y) / 2.0) * 1.12;
let bounds = ((cx - half, cy - half), (cx + half, cy + half));
let stroke_w = 0.05 * half;
let build_scene = || {
let style = TileStyle::filled(
Fill::solid(Color::YELLOW.with_alpha(96)),
Stroke::solid(Color::BLACK, stroke_w),
);
let mut scene = Scene::new().with_background(Color::WHITE);
scene.draw_tile(&polyline, &style);
scene
};
let out = Path::new("web/ratdb");
let svg_vp = Viewport::square_for(64, bounds, 2);
let svg = build_scene().to_svg(&svg_vp);
std::fs::write(out.join("favicon.svg"), &svg).expect("write favicon.svg");
for (side, pad, name) in [
(32u32, 1u32, "favicon-32.png"),
(180, 6, "apple-touch-icon.png"),
] {
let vp = Viewport::square_for(side, bounds, pad);
let png = raster::to_png(&build_scene(), &vp).expect("rasterize png");
std::fs::write(out.join(name), &png).expect("write png");
}
println!("wrote favicon.svg, favicon-32.png, apple-touch-icon.png to web/ratdb/");
}