add inherit_last option + pix4 option
All checks were successful
CI / Rust project (push) Successful in 1m7s
All checks were successful
CI / Rust project (push) Successful in 1m7s
This commit is contained in:
parent
b345147719
commit
89ad59a852
BIN
modraw.png
BIN
modraw.png
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 144 KiB |
54
src/main.rs
54
src/main.rs
@ -7,11 +7,11 @@ use rand::Rng;
|
|||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct Args {
|
struct Args {
|
||||||
/// width and height of the image
|
/// width and height of the image
|
||||||
#[arg(short, long, default_value_t = 2000)]
|
#[arg(short, long)]
|
||||||
width: u32,
|
width: Option<u32>,
|
||||||
|
|
||||||
/// The multiplicator
|
/// The multiplicator
|
||||||
#[arg(short, default_value_t = 96)]
|
#[arg(short, default_value_t = 36)]
|
||||||
modulo: u32,
|
modulo: u32,
|
||||||
|
|
||||||
/// Set verbose mode
|
/// Set verbose mode
|
||||||
@ -21,27 +21,57 @@ struct Args {
|
|||||||
/// Optional 4x pixel mode
|
/// Optional 4x pixel mode
|
||||||
#[arg(short, long, default_value_t = false)]
|
#[arg(short, long, default_value_t = false)]
|
||||||
pix4: bool,
|
pix4: bool,
|
||||||
|
|
||||||
|
/// Inherit color from last pixel
|
||||||
|
#[arg(short, long, default_value_t = false)]
|
||||||
|
inherit_last: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
let mut img: ImageBuffer<Rgb<u8>, Vec<u8>> = ImageBuffer::new(args.width, args.width);
|
let mut img: ImageBuffer<Rgb<u8>, Vec<u8>> = ImageBuffer::new(args.width.unwrap_or(args.modulo * 10), args.width.unwrap_or(args.modulo * 10));
|
||||||
let mut colors: Vec<[u8; 3]> = vec![];
|
let mut colors: Vec<[u8; 3]> = vec![];
|
||||||
if args.pix4 {
|
if args.pix4 {
|
||||||
for x in 0..(img.width() / 2) {
|
for x in 0..(img.width() / 2) {
|
||||||
for y in 0..(img.height() / 2) {
|
for y in 0..(img.height() / 2) {
|
||||||
let result: usize = (x * y % args.modulo).try_into().unwrap();
|
let result: usize = (x * y % args.modulo).try_into().unwrap();
|
||||||
|
let mut color;
|
||||||
if colors.get(result).is_some() {
|
if colors.get(result).is_some() {
|
||||||
img.put_pixel(2 * x, 2 * y, Rgb(colors[(x * y % args.modulo) as usize]));
|
color = Rgb(colors[result]);
|
||||||
img.put_pixel(2 * x + 1, 2 * y, Rgb(colors[(x * y % args.modulo) as usize]));
|
if args.inherit_last {
|
||||||
img.put_pixel(2 * x, 2 * y + 1, Rgb(colors[(x * y % args.modulo) as usize]));
|
let color_before;
|
||||||
img.put_pixel(2 * x + 1, 2 * y + 1, Rgb(colors[(x * y % args.modulo) as usize]));
|
// TODO: highly review this
|
||||||
|
// WARN: not usable yet
|
||||||
|
if x == 0 {
|
||||||
|
if y == 0 {
|
||||||
|
color_before = &Rgb([0,0,0]);
|
||||||
|
// } else if y == img.width() {
|
||||||
|
// color_before = img.get_pixel(img.width(), y - 2);
|
||||||
|
} else {
|
||||||
|
color_before = img.get_pixel(x, y - 1);
|
||||||
|
}
|
||||||
|
} else if x == 1 {
|
||||||
|
color_before = img.get_pixel(x - 1, y);
|
||||||
|
} else {
|
||||||
|
color_before = img.get_pixel(x - 2, y);
|
||||||
|
}
|
||||||
|
color = Rgb([
|
||||||
|
color[0] / 2 + color_before[0] / 2,
|
||||||
|
color[1] / 2 + color_before[1] / 2,
|
||||||
|
color[2] / 2 + color_before[2] / 2,
|
||||||
|
])
|
||||||
|
}
|
||||||
|
img.put_pixel(2 * x, 2 * y, color);
|
||||||
|
img.put_pixel(2 * x + 1, 2 * y, color);
|
||||||
|
img.put_pixel(2 * x, 2 * y + 1, color);
|
||||||
|
img.put_pixel(2 * x + 1, 2 * y + 1, color);
|
||||||
} else {
|
} else {
|
||||||
colors.insert(result, [generate_random(0, 255), generate_random(0, 255), generate_random(0, 255)]);
|
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]));
|
color = Rgb(colors[result]);
|
||||||
img.put_pixel(2 * x + 1, 2 * y, Rgb(colors[(x * y % args.modulo) as usize]));
|
img.put_pixel(2 * x, 2 * y, color);
|
||||||
img.put_pixel(2 * x, 2 * y + 1, Rgb(colors[(x * y % args.modulo) as usize]));
|
img.put_pixel(2 * x + 1, 2 * y, color);
|
||||||
img.put_pixel(2 * x + 1, 2 * y + 1, Rgb(colors[(x * y % args.modulo) as usize]));
|
img.put_pixel(2 * x, 2 * y + 1, color);
|
||||||
|
img.put_pixel(2 * x + 1, 2 * y + 1, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user