diff --git a/modraw.png b/modraw.png index 1623326..985607b 100644 Binary files a/modraw.png and b/modraw.png differ diff --git a/src/main.rs b/src/main.rs index 7c6757f..95806d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use image::Rgb; use clap::Parser; use rand::Rng; + #[derive(Parser, Debug)] struct Args { /// width and height of the image @@ -15,20 +16,45 @@ struct Args { /// Set verbose mode #[arg(short, long, default_value_t = false)] - verbose: bool + verbose: bool, + + /// Optional 4x pixel mode + #[arg(short, long, default_value_t = false)] + pix4: bool, } fn main() { let args = Args::parse(); let mut img: ImageBuffer, Vec> = ImageBuffer::new(args.width, args.width); let mut colors: Vec<[u8; 3]> = vec![]; - for x in 0..img.width() { - for y in 0..img.height() { - let result: usize = (x * y % args.modulo).try_into().unwrap(); - if colors.get(result).is_some() { - img.put_pixel(x, y, Rgb(colors[(x * y % args.modulo) as usize])); - } else { - colors.insert(result, [generate_random(0, 255), generate_random(0, 255), generate_random(0, 255)]); + if args.pix4 { + for x in 0..(img.width() / 2) { + for y in 0..(img.height() / 2) { + let result: usize = (x * y % args.modulo).try_into().unwrap(); + if colors.get(result).is_some() { + img.put_pixel(2 * x, 2 * y, Rgb(colors[(x * y % args.modulo) as usize])); + img.put_pixel(2 * x + 1, 2 * y, Rgb(colors[(x * y % args.modulo) as usize])); + img.put_pixel(2 * x, 2 * y + 1, Rgb(colors[(x * y % args.modulo) as usize])); + img.put_pixel(2 * x + 1, 2 * y + 1, Rgb(colors[(x * y % args.modulo) as usize])); + } else { + colors.insert(result, [generate_random(0, 255), generate_random(0, 255), generate_random(0, 255)]); + img.put_pixel(2 * x, 2 * y, Rgb(colors[(x * y % args.modulo) as usize])); + img.put_pixel(2 * x + 1, 2 * y, Rgb(colors[(x * y % args.modulo) as usize])); + img.put_pixel(2 * x, 2 * y + 1, Rgb(colors[(x * y % args.modulo) as usize])); + img.put_pixel(2 * x + 1, 2 * y + 1, Rgb(colors[(x * y % args.modulo) as usize])); + } + } + } + } else { + for x in 0..img.width() { + for y in 0..img.height() { + let result: usize = (x * y % args.modulo).try_into().unwrap(); + if colors.get(result).is_some() { + img.put_pixel(x, y, Rgb(colors[(x * y % args.modulo) as usize])); + } else { + colors.insert(result, [generate_random(0, 255), generate_random(0, 255), generate_random(0, 255)]); + img.put_pixel(x, y, Rgb(colors[(x * y % args.modulo) as usize])); + } } } } @@ -41,7 +67,6 @@ fn main() { fn generate_random(start: u8, end: u8) -> u8 { let mut rng = rand::thread_rng(); - // rng.gen_range(std::char::from_u32(start).unwrap()..=std::char::from_u32(end).unwrap()) rng.gen_range(start..=end) }