diff --git a/Cargo.toml b/Cargo.toml index 6d37a80..c26932a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,4 @@ edition = "2021" image = "0.24.7" rand = "0.8.5" num_cpus = "1.16.0" +clap = { version = "4.4.8", features = ["derive"]} diff --git a/grid_image.png b/grid_image.png index f3866bf..79f4b39 100644 Binary files a/grid_image.png and b/grid_image.png differ diff --git a/src/main.rs b/src/main.rs index 33d5f4c..b6ea47d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,18 +1,27 @@ #![allow(dead_code)] -use std::env; +use clap::Parser; use rand::Rng; use image::Rgb; use image::RgbImage; use image::ImageBuffer; -fn main() { - let args: Vec = env::args().collect(); +#[derive(Parser)] +struct Args { + /// Optimization level + #[arg(short, default_value_t = 3)] + opt_level: u8, - let _num_chunks = args.get(1) - .and_then(|arg: &String| arg.parse::().ok()) - .unwrap_or(num_cpus::get()); + /// Number of cores [default: max] + #[arg(short, value_name = "CORES")] + core: Option +} + + +fn main() { + + let args = Args::parse(); let width = 7000; let height = 7000; @@ -24,10 +33,14 @@ fn main() { // points.push(i as f64 / 10000.0); // // points.push(-(i as f64 / 10000.0)); // } - - let step = 0.001; // Define the step size + + let mut step = "0.".to_string(); + for _ in 0..args.opt_level { + step.push('0') + } + step.push('1'); + let step: f64 = step.parse().unwrap(); let mut current_value = 0.0; - while current_value <= 1.8 { points.push(current_value); current_value += step; @@ -43,16 +56,17 @@ fn main() { ]; colors.push(color); for point in points { - let x = (point * 1000.0_f64).round() as u32; - let y = (get_point(point) * 1000.0).round() as u32; + // NOTE: convert later to u32 because deviding may change actual value + let x = point * 1000.0_f64; + let y = get_point(point) * 1000.0; img.put_pixel( - x + width / 2, - y + height / 2, + (width as f64 / 2.0 + x).round() as u32, + (height as f64 / 2.0 + y) as u32, Rgb(color) ); img.put_pixel( - x + width / 2 - x * 2, - y + height / 2, + (width as f64 / 2.0 - x).round() as u32, + (height as f64 / 2.0 + y).round() as u32, Rgb(color) ); @@ -81,7 +95,7 @@ fn generate_random(start: u8, end: u8) -> u8 { fn get_image(width: u32, height: u32) -> ImageBuffer, Vec> { let mut img = RgbImage::new(width, height); - let grid_spacing = 50; + let grid_spacing = 100; let grid_color = Rgb([255,9,255]); for x in (0..width).step_by(grid_spacing) {