This commit is contained in:
parent
f9eff313b5
commit
6bcbad7a96
@ -6,3 +6,6 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
image = "0.24.7"
|
||||||
|
clap = { version = "4.4.8", features = ["derive"] }
|
||||||
|
rand = "0.8.5"
|
||||||
|
|||||||
BIN
modraw.png
Normal file
BIN
modraw.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
42
src/main.rs
42
src/main.rs
@ -1,3 +1,41 @@
|
|||||||
fn main() {
|
use image::ImageBuffer;
|
||||||
println!("Hello, world!");
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user