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