From 9105c2adcf1da0531366480a98710ede30686345 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 14 May 2022 22:57:03 +0200 Subject: [PATCH] Depth binds & rust things --- mas/fractals/mandel/src/main.rs | 22 ++++++++++++++++------ mas/fractals/mandel/src/render.rs | 6 +++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/mas/fractals/mandel/src/main.rs b/mas/fractals/mandel/src/main.rs index 3f6d74b..14eb5f0 100644 --- a/mas/fractals/mandel/src/main.rs +++ b/mas/fractals/mandel/src/main.rs @@ -77,18 +77,28 @@ fn main() { zy *= zoom_out; zx *= zoom_out; }, + Event::KeyDown { keycode: Some(Keycode::W), .. } => { + println!("(+) DEPTH= {depth}"); + render_new = true; + depth *= 2; + }, + Event::KeyDown { keycode: Some(Keycode::S), .. } => { + println!("(-) DEPTH= {depth}"); + render_new = true; + depth /= 2; + }, _ => {} } } if render_new { - let mut maps = &mut Vec::new(); + let maps = &mut Vec::new(); for thread_id in 0..threads { - thread::spawn(|| { // do cool threads for performance - let mut pixmap = render::prerender_mandelbrot( - width, height, depth, - zx, zy, dx, dy, - thread_id, threads, w_sector_size, h_sector_size); + thread::spawn(|| { + let pixmap = render::prerender_mandelbrot( + &width, &height, &depth, + &zx, &zy, &dx, &dy, + &thread_id, &threads, &w_sector_size, &h_sector_size); maps.push(pixmap); }); } diff --git a/mas/fractals/mandel/src/render.rs b/mas/fractals/mandel/src/render.rs index 11c66f0..8cb6a10 100644 --- a/mas/fractals/mandel/src/render.rs +++ b/mas/fractals/mandel/src/render.rs @@ -66,10 +66,10 @@ pub fn set_pixel(canvas: &mut Canvas, x: i32, y: i32, color canvas.fill_rect(Rect::new(x, y, 1, 1)); } -pub fn prerender_mandelbrot(w: u32, h: u32, depth: u32, xzoom: f32, yzoom: f32, xoffset: f32, yoffset: f32, thread_id: u32, threads: u32, w_sector_size: u32, h_sector_size: u32) -> PixelMap { +pub fn prerender_mandelbrot(w: &u32, h: &u32, depth: &u32, xzoom: &f32, yzoom: &f32, xoffset: &f32, yoffset: &f32, thread_id: &u32, threads: &u32, w_sector_size: &u32, h_sector_size: &u32) -> PixelMap { println!("Rendering..."); - let mut pixmap = PixelMap::new(w, h, thread_id * w_sector_size, thread_id * h_sector_size); - mandelbrot(&mut pixmap, w, h, depth, xzoom, yzoom, xoffset, yoffset); + let mut pixmap = PixelMap::new(*w, *h, thread_id * w_sector_size, thread_id * h_sector_size); + mandelbrot(&mut pixmap, *w, *h, *depth, *xzoom, *yzoom, *xoffset, *yoffset); println!("Post mandel render"); return pixmap;