finish
All checks were successful
CI / Rust project (push) Successful in 1m9s

This commit is contained in:
fabolous005 2023-11-27 14:31:35 +01:00
parent f9eff313b5
commit 6bcbad7a96
3 changed files with 43 additions and 2 deletions

View File

@ -6,3 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
image = "0.24.7"
clap = { version = "4.4.8", features = ["derive"] }
rand = "0.8.5"

BIN
modraw.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -1,3 +1,41 @@
fn main() {
println!("Hello, world!");
use image::ImageBuffer;
use image::Rgb;
use clap::Parser;
use rand::Rng;
#[derive(Parser, Debug)]
struct Args {
/// width and height of the image
#[arg(short, long, default_value_t = 2000)]
width: u32,
/// The multiplicator
#[arg(short, default_value_t = 96)]
modulo: u32
}
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)]);
}
}
}
img.save("modraw.png").expect("Failed to save image");
println!("{colors:?}");
println!("{:?}", colors.len());
}
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)
}