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.
-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<f64>,
+ lower_right: Complex<f64>,
+ 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();
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.