paints.rs
1.7 kB · rust · 55 lines
1use mrlycore::paint::{self, Config as PaintConfig, Edition, Paint};2use mrlycore::state::seed;3use mrlycore::tile::Tile;4use mrlycore::{json, Image, Json};5use mrlymath::two::tile as tile2d;67const SEED: u64 = 7;89fn tiles() -> tile2d::Config {10 tile2d::Config {11 min_size: 3,12 max_size: 9,13 anti: Some(false),14 ..tile2d::Config::default()15 }16}1718fn row(edition: Edition, tile: &Tile, paint: &Paint, image: &Image) -> Json {19 json!({20 "edition": edition.name(),21 "scheme": paint.scheme.name(),22 "target": paint.target.name(),23 "primary": paint.primary.name(),24 "secondary": paint.secondary.iter().map(|ink| ink.name()).collect::<Vec<_>>(),25 "shades": paint.shades.clone(),26 "size": format!("{}x{}", tile.width, tile.height),27 "group": tile.group.name(),28 "image": image,29 })30}3132fn main() {33 let config = tiles();34 let mut rows = Vec::new();35 for (i, edition) in Edition::all().into_iter().enumerate() {36 seed(SEED + i as u64);37 let tile = tile2d::create(&config).expect("no tile fits the size constraints");38 let mut cell = tile2d::build(&tile).expect("the tile would not build");39 let recipe = PaintConfig {40 editions: Some(vec![edition]),41 ..PaintConfig::default()42 };43 let paint = paint::paint(&mut cell.cell, &recipe, None).expect("the paint would not apply");44 let colors = cell.cell.colors.clone().expect("the paint left no colors");45 let image = Image::from_pixels(cell.width(), cell.height(), &colors);46 rows.push(row(edition, &tile, &paint, &image));47 }48 println!(49 "{}",50 json!({51 "seed": SEED,52 "paints": rows,53 })54 );55}