fix little bug + add pix4 option
All checks were successful
CI / Rust project (push) Successful in -2m56s
All checks were successful
CI / Rust project (push) Successful in -2m56s
This commit is contained in:
parent
dcde63552a
commit
b345147719
BIN
modraw.png
BIN
modraw.png
Binary file not shown.
|
Before Width: | Height: | Size: 11 MiB After Width: | Height: | Size: 1.1 MiB |
43
src/main.rs
43
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<Rgb<u8>, Vec<u8>> = 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)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user