1#![allow(clippy::type_complexity, clippy::uninlined_format_args)] 2 3use image::{ImageBuffer, Rgb}; 4use std::process; 5 6fn main() { 7 let width = 512; 8 let height = 400; 9 let diagrams: [(&str, fn(char) -> bool); 2] = [ 10 ("xid_start.png", unicode_ident::is_xid_start), 11 ("xid_continue.png", unicode_ident::is_xid_continue), 12 ]; 13 for (name, f) in diagrams { 14 let mut imgbuf = ImageBuffer::new(width, height); 15 for (col, row, pixel) in imgbuf.enumerate_pixels_mut() { 16 *pixel = if char::from_u32(row * width + col).map_or(false, f) { 17 Rgb([0u8, 0, 0]) 18 } else { 19 Rgb([255, 255, 255]) 20 }; 21 } 22 if let Err(err) = imgbuf.save(name) { 23 eprintln!("Error: {}", err); 24 process::exit(1); 25 } 26 } 27} 28