From: Greg Burri Date: Tue, 18 Apr 2023 21:51:01 +0000 (+0200) Subject: Move the parameters to the main module X-Git-Url: http://git.euphorik.ch/?a=commitdiff_plain;h=06bb73cac56ac19b46e6d9de1bd3dad6a22ea5d3;p=rust_concurrent.git Move the parameters to the main module --- diff --git a/.gitignore b/.gitignore index ea8c4bf..e39cff4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +*.png \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 15aa600..ca724fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,19 @@ use std::thread; +use num::Complex; + mod rayon; fn main() { // spawn_and_join(); - rayon::mandelbrot(); + + rayon::mandelbrot( + 1920, + 1080, + Complex { re: -1.2, im: 0.35 }, + Complex { re: -1.0, im: 0.2 }, + "output.png", + ); } // Page 500. diff --git a/src/rayon.rs b/src/rayon.rs index 7d3e259..9ef6fc3 100644 --- a/src/rayon.rs +++ b/src/rayon.rs @@ -1,18 +1,19 @@ -use std::fs::File; +use std::{fs::File, ops::DerefMut}; use image::{codecs::png::PngEncoder, ColorType, ImageEncoder}; use num::Complex; use rayon::prelude::{IntoParallelIterator, ParallelIterator}; // Page 508. -pub fn mandelbrot() { +pub fn mandelbrot( + width: usize, + height: usize, + upper_left: Complex, + lower_right: Complex, + filename: &str, +) { println!("===== rayon ====="); - let width = 1920; - let height = 1080; - let upper_left = Complex { re: -1.2, im: 0.35 }; - let lower_right = Complex { re: -1.0, im: 0.2 }; - let mut pixels = vec![0; width * height]; let bands: Vec<(usize, &mut [u8])> = pixels.chunks_mut(width).enumerate().collect(); @@ -25,7 +26,7 @@ pub fn mandelbrot() { render(band, band_bounds, band_upper_left, band_lower_right); }); - write_image("output.png", &pixels, (width, height)).unwrap(); + write_image(filename, &pixels, (width, height)).unwrap(); } // page 32.