diff --git a/Cargo.toml b/Cargo.toml index 65ee90d..6d37a80 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,4 @@ edition = "2021" [dependencies] image = "0.24.7" rand = "0.8.5" +num_cpus = "1.16.0" diff --git a/grid_image.png b/grid_image.png index 1fb4db4..f3866bf 100644 Binary files a/grid_image.png and b/grid_image.png differ diff --git a/src/main.rs b/src/main.rs index fdf4bbd..33d5f4c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ #![allow(dead_code)] +use std::env; use rand::Rng; use image::Rgb; use image::RgbImage; @@ -7,31 +8,54 @@ use image::ImageBuffer; fn main() { - let width = 6500; - let height = 6500; + let args: Vec = env::args().collect(); + + let _num_chunks = args.get(1) + .and_then(|arg: &String| arg.parse::().ok()) + .unwrap_or(num_cpus::get()); + + let width = 7000; + let height = 7000; let mut img = get_image(width, height); - // let mut colors= vec![]; - + let mut colors= vec![]; let mut points = vec![]; - for i in 0..=1000 { - points.push(i as f64 / 1000.0); - points.push(-(i as f64 / 1000.0)); + // for i in 0..=10000 { + // points.push(i as f64 / 10000.0); + // // points.push(-(i as f64 / 10000.0)); + // } + + let step = 0.001; // Define the step size + let mut current_value = 0.0; + + while current_value <= 1.8 { + points.push(current_value); + current_value += step; } // funktion = f(x) = 3x^2 // ableitungsquotient = 6a - + let color = [ + generate_random(0, 255), + generate_random(0, 255), + generate_random(0, 255) + ]; + colors.push(color); for point in points { - // let color = [generate_random(0, 255), generate_random(0, 255), generate_random(0, 255)]; - // colors.push(color); - // img.put_pixel((point * 1000.0_f64).round() as u32, (get_point(point as i32) * 1000.0).round() as u32, Rgb(color)); + let x = (point * 1000.0_f64).round() as u32; + let y = (get_point(point) * 1000.0).round() as u32; img.put_pixel( - (point * 1000.0_f64).round() as u32 + (width / 2), - (get_point(point) * 1000.0).round() as u32 + (height / 2), - Rgb([255,255,255]) + x + width / 2, + y + height / 2, + Rgb(color) ); + img.put_pixel( + x + width / 2 - x * 2, + y + height / 2, + Rgb(color) + ); + } @@ -44,7 +68,8 @@ fn get_pitch_quotient() -> u32 { } fn get_point(x: f64) -> f64 { - 3.0 * x.powf(2.0) + // 3.0 * x.powf(2.0) + x.powf(2.0) } @@ -57,7 +82,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_color = Rgb([255, 9, 255]); // Black colo + let grid_color = Rgb([255,9,255]); for x in (0..width).step_by(grid_spacing) { for y in 0..height {