diff options
-rw-r--r-- | CHANGELOG.md | 5 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | source/benoit/benoit/application.rs | 19 | ||||
-rw-r--r-- | source/benoit/benoit/application/animate.rs | 10 | ||||
-rw-r--r-- | source/benoit/benoit/application/colour.rs | 12 | ||||
-rw-r--r-- | source/benoit/benoit/application/draw.rs | 41 | ||||
-rw-r--r-- | source/benoit/benoit/application/handle_keys.rs | 14 | ||||
-rw-r--r-- | source/benoit/benoit/application/initialise.rs | 4 | ||||
-rw-r--r-- | source/benoit/benoit/application/loop.rs | 20 | ||||
-rw-r--r-- | source/benoit/benoit/application/render.rs | 4 | ||||
-rw-r--r-- | source/benoit/benoit/application/render_row_julia.rs | 20 | ||||
-rw-r--r-- | source/benoit/benoit/application/render_row_normal.rs | 20 | ||||
-rw-r--r-- | source/benoit/benoit/configuration.rs | 8 | ||||
-rw-r--r-- | source/benoit/benoit/configuration/default.rs | 8 | ||||
-rw-r--r-- | source/benoit/benoit/configuration/load.rs | 6 | ||||
-rw-r--r-- | source/benoit/benoit/render_data.rs | 12 | ||||
-rw-r--r-- | source/benoit/benoit/render_data/new.rs | 18 | ||||
-rw-r--r-- | source/benoit/benoit/render_data/slice.rs | 6 |
18 files changed, 139 insertions, 90 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f7cd193..371ce47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 28 + +* Draw positional feedback before renders (does not currently support offsets) +* Rename objects (allow some abbreviations) + # 27 * Bring back Julia sets (using row renderers) @@ -1,6 +1,6 @@ [package] name = "benoit" -version = "0.31.0" +version = "0.32.0" authors = ["Gabriel Bjørnager Jensen"] edition = "2021" description = "Mandelbrot renderer." diff --git a/source/benoit/benoit/application.rs b/source/benoit/benoit/application.rs index 1830721..574179c 100644 --- a/source/benoit/benoit/application.rs +++ b/source/benoit/benoit/application.rs @@ -48,10 +48,13 @@ pub mod run; pub type RowRenderer = fn(Arc<RenderData>, u32, IteratorFunction); +// We pass this struct to draw the offset feedback. +// Currently unused, however. +#[allow(dead_code)] pub struct PreviousPosition { - real: Float, - imaginary: Float, - zoom: Float, + centre_real: Float, + centre_imag: Float, + zoom: Float, } pub struct Application { @@ -65,17 +68,17 @@ pub struct Application { scale: u32, frame_count: u32, - centre_real: Float, - centre_imaginary: Float, - zoom: Float, - maximum_iteration_count: u32, + centre_real: Float, + centre_imag: Float, + zoom: Float, + max_iter_count: u32, dump_path: String, video: Option<Video>, interactive: bool, - do_render: bool, + do_render: bool, do_dump: bool, row_renderer: RowRenderer, diff --git a/source/benoit/benoit/application/animate.rs b/source/benoit/benoit/application/animate.rs index 3c9aaab..632099d 100644 --- a/source/benoit/benoit/application/animate.rs +++ b/source/benoit/benoit/application/animate.rs @@ -66,19 +66,19 @@ impl Application { factor }; - eprintln!("animating {} frames at {}{:+}i to {:.3} (fac.: {:.3})", self.frame_count, self.centre_real.to_f64(), self.centre_imaginary.to_f64(), zoom_stop.to_f64(), zoom_factor.to_f64()); + eprintln!("animating {} frames at {}{:+}i to {:.3} (fac.: {:.3})", self.frame_count, self.centre_real.to_f64(), self.centre_imag.to_f64(), zoom_stop.to_f64(), zoom_factor.to_f64()); let canvas_size = self.canvas_height as usize * self.canvas_width as usize; - let mut iteration_count_buffer: Vec::<u32> = vec![0x0; canvas_size]; - let mut square_distance_buffer: Vec::<f32> = vec![0.0; canvas_size]; + let mut iter_count_buffer: Vec::<u32> = vec![0x0; canvas_size]; + let mut square_dist_buffer: Vec::<f32> = vec![0.0; canvas_size]; let mut image: Vec::<u8> = vec![0x0; canvas_size * 0x3]; for frame in 0x0..self.frame_count { eprint!("{frame:010}: "); - self.render(&mut iteration_count_buffer[..], &mut square_distance_buffer[..], &self.centre_real, &self.centre_imaginary, &zoom, self.maximum_iteration_count); - self.colour(&mut image[..], &mut iteration_count_buffer[..], &mut square_distance_buffer[..]); + self.render(&mut iter_count_buffer[..], &mut square_dist_buffer[..], &self.centre_real, &self.centre_imag, &zoom, self.max_iter_count); + self.colour(&mut image[..], &mut iter_count_buffer[..], &mut square_dist_buffer[..]); self.dump(format!("{}/frame{frame:010}.webp", self.dump_path), &image, self.canvas_width, self.canvas_height); diff --git a/source/benoit/benoit/application/colour.rs b/source/benoit/benoit/application/colour.rs index d734f65..7139828 100644 --- a/source/benoit/benoit/application/colour.rs +++ b/source/benoit/benoit/application/colour.rs @@ -24,18 +24,18 @@ use crate::benoit::application::Application; impl Application { - pub fn colour(&self, buffer: &mut [u8], iteration_count_buffer: &[u32], square_distance_buffer: &[f32]) { + pub fn colour(&self, buffer: &mut [u8], iter_count_buffer: &[u32], square_dist_buffer: &[f32]) { let canvas_size = self.canvas_height * self.canvas_width; for pixel in 0x0..canvas_size { - let iteration_count = iteration_count_buffer[pixel as usize]; + let iter_count = iter_count_buffer[pixel as usize]; - let (red, green, blue) = if iteration_count != self.maximum_iteration_count { - let distance = square_distance_buffer[pixel as usize].sqrt(); + let (red, green, blue) = if iter_count != self.max_iter_count { + let distance = square_dist_buffer[pixel as usize].sqrt(); - let factor_range = 16.0_f32.min(self.maximum_iteration_count as f32); + let factor_range = 16.0_f32.min(self.max_iter_count as f32); - let mut factor = (iteration_count as f32 + 1.0 - distance.log2().log2()) / factor_range % 1.0; + let mut factor = (iter_count as f32 + 1.0 - distance.log2().log2()) / factor_range % 1.0; factor = (if factor >= 1.0 / 2.0 { 1.0 - factor diff --git a/source/benoit/benoit/application/draw.rs b/source/benoit/benoit/application/draw.rs index ae936ba..fdce93e 100644 --- a/source/benoit/benoit/application/draw.rs +++ b/source/benoit/benoit/application/draw.rs @@ -58,6 +58,47 @@ impl Application { self.video.as_mut().unwrap().canvas.fill_rects(&[rectangle]).unwrap(); } + if !self.julia { + let viewport_colour = Color::RGB(0xFF, 0x0, 0x0); + + let canvas_width = { + let mut canvas_width = Float::with_val(PRECISION, self.canvas_width); + canvas_width *= self.scale; + + canvas_width + }; + + let viewport = { + let ((offset_x, offset_y), width) = { + let zoom_ratio = Float::with_val(PRECISION, &self.zoom / &previous_position.zoom); + + let mut width = Float::with_val(PRECISION, 1.0 / &zoom_ratio); + + let mut offset_x = Float::with_val(PRECISION, 1.0 - &width); + let mut offset_y = Float::with_val(PRECISION, 1.0 - &width); + + offset_x /= 2.0; + offset_y /= 2.0; + + offset_x *= &canvas_width; + offset_y *= &canvas_width; + width *= &canvas_width; + + ((offset_x.to_f32().round() as i32, offset_y.to_f32().round() as i32), width.to_f32().round() as u32) + }; + + Rect::new( + offset_x, + offset_y, + width, + width, + ) + }; + + self.video.as_mut().unwrap().canvas.set_draw_color(viewport_colour); + self.video.as_mut().unwrap().canvas.draw_rects(&[viewport]).unwrap(); + } + self.video.as_mut().unwrap().canvas.present(); } } diff --git a/source/benoit/benoit/application/handle_keys.rs b/source/benoit/benoit/application/handle_keys.rs index 4b2c09c..3d45f1d 100644 --- a/source/benoit/benoit/application/handle_keys.rs +++ b/source/benoit/benoit/application/handle_keys.rs @@ -67,7 +67,7 @@ impl Application { Scancode::C => self.do_render = true, Scancode::Tab => (self.julia, self.row_renderer) = toggle_julia(self.julia), Scancode::X => self.do_dump = true, - Scancode::Z => eprintln!("c = {}{:+}i -- {}x @ {} iter.", &self.centre_real, &self.centre_imaginary, &self.zoom, self.maximum_iteration_count), + Scancode::Z => eprintln!("c = {}{:+}i -- {}x @ {} iter.", &self.centre_real, &self.centre_imag, &self.zoom, self.max_iter_count), _ => {}, } @@ -92,15 +92,15 @@ impl Application { }; match scan_code { - Scancode::S => self.centre_imaginary += &translate_ammount, - Scancode::W => self.centre_imaginary -= &translate_ammount, + Scancode::S => self.centre_imag += &translate_ammount, + Scancode::W => self.centre_imag -= &translate_ammount, _ => {}, }; - self.maximum_iteration_count = match scan_code { - Scancode::F => self.maximum_iteration_count * 0x2, - Scancode::R => self.maximum_iteration_count / 0x2, - _ => self.maximum_iteration_count, + self.max_iter_count = match scan_code { + Scancode::F => self.max_iter_count * 0x2, + Scancode::R => self.max_iter_count / 0x2, + _ => self.max_iter_count, }; return false; diff --git a/source/benoit/benoit/application/initialise.rs b/source/benoit/benoit/application/initialise.rs index e46347c..1a24367 100644 --- a/source/benoit/benoit/application/initialise.rs +++ b/source/benoit/benoit/application/initialise.rs @@ -73,9 +73,9 @@ impl Application { frame_count: configuration.frame_count, centre_real: Float::with_val(PRECISION, configuration.centre_real), - centre_imaginary: Float::with_val(PRECISION, configuration.centre_imaginary), + centre_imag: Float::with_val(PRECISION, configuration.centre_imag), zoom: Float::with_val(PRECISION, configuration.zoom), - maximum_iteration_count: configuration.maximum_iteration_count, + max_iter_count: configuration.max_iter_count, dump_path: configuration.dump_path, diff --git a/source/benoit/benoit/application/loop.rs b/source/benoit/benoit/application/loop.rs index 2621556..67de1dd 100644 --- a/source/benoit/benoit/application/loop.rs +++ b/source/benoit/benoit/application/loop.rs @@ -52,28 +52,28 @@ impl Application { let canvas_size = self.canvas_height as usize * self.canvas_width as usize; - let mut iteration_count_buffer: Vec::<u32> = vec![0x0; canvas_size]; - let mut square_distance_buffer: Vec::<f32> = vec![0.0; canvas_size]; + let mut iter_count_buffer: Vec::<u32> = vec![0x0; canvas_size]; + let mut square_dist_buffer: Vec::<f32> = vec![0.0; canvas_size]; let mut image: Vec::<u8> = vec![0x0; canvas_size * 0x3]; let mut previous_position = PreviousPosition { - real: self.centre_real.clone(), - imaginary: self.centre_imaginary.clone(), - zoom: self.zoom.clone(), + centre_real: self.centre_real.clone(), + centre_imag: self.centre_imag.clone(), + zoom: self.zoom.clone(), }; loop { if self.poll_events(&mut event_pump) { break } if self.do_render { - self.render(&mut iteration_count_buffer[..], &mut square_distance_buffer[..], &self.centre_real, &self.centre_imaginary, &self.zoom, self.maximum_iteration_count); - self.colour(&mut image[..], &iteration_count_buffer[..], &square_distance_buffer[..]); + self.render(&mut iter_count_buffer[..], &mut square_dist_buffer[..], &self.centre_real, &self.centre_imag, &self.zoom, self.max_iter_count); + self.colour(&mut image[..], &iter_count_buffer[..], &square_dist_buffer[..]); previous_position = PreviousPosition { - real: self.centre_real.clone(), - imaginary: self.centre_imaginary.clone(), - zoom: self.zoom.clone(), + centre_real: self.centre_real.clone(), + centre_imag: self.centre_imag.clone(), + zoom: self.zoom.clone(), }; self.do_render = false; diff --git a/source/benoit/benoit/application/render.rs b/source/benoit/benoit/application/render.rs index 3063d6f..495f54b 100644 --- a/source/benoit/benoit/application/render.rs +++ b/source/benoit/benoit/application/render.rs @@ -33,7 +33,7 @@ use std::sync::Arc; use std::time::Instant; impl Application { - pub fn render(&self, iteration_count_buffer: &mut [u32], square_distance_buffer: &mut [f32], centre_real: &Float, centre_imaginary: &Float, zoom: &Float, maximum_iteration_count: u32) { + pub fn render(&self, iter_count_buffer: &mut [u32], square_dist_buffer: &mut [f32], centre_real: &Float, centre_imag: &Float, zoom: &Float, max_iter_count: u32) { eprint!("rendering..."); let time_start = Instant::now(); @@ -41,7 +41,7 @@ impl Application { let row_renderer = self.row_renderer; let iterator = self.iterator_function; - let data = Arc::new(RenderData::new(iteration_count_buffer, square_distance_buffer, self.canvas_width, self.canvas_height, centre_real.clone(), centre_imaginary.clone(), zoom.clone(), maximum_iteration_count)); + let data = Arc::new(RenderData::new(iter_count_buffer, square_dist_buffer, self.canvas_width, self.canvas_height, centre_real.clone(), centre_imag.clone(), zoom.clone(), max_iter_count)); (0x0..self.canvas_height).into_par_iter().for_each(|row| { row_renderer(data.clone(), row, iterator); diff --git a/source/benoit/benoit/application/render_row_julia.rs b/source/benoit/benoit/application/render_row_julia.rs index ba46afa..e9f2aa3 100644 --- a/source/benoit/benoit/application/render_row_julia.rs +++ b/source/benoit/benoit/application/render_row_julia.rs @@ -33,7 +33,7 @@ use std::sync::Arc; impl Application { pub fn render_row_julia(data: Arc<RenderData>, y: u32, iterator: IteratorFunction) { - let (iteration_count_buffer, square_distance_buffer) = unsafe { data.slice(y) }; + let (iter_count_buffer, square_dist_buffer) = unsafe { data.slice(y) }; for x in 0x0..data.canvas_width { let canvas_width = Float::with_val(PRECISION, data.canvas_width); @@ -44,8 +44,8 @@ impl Application { // For more information, see render_row_normal. - let ca = &data.real; - let cb = &data.imaginary; + let ca = &data.centre_real; + let cb = &data.centre_imag; // When rendering the Julia fractals, the value of // (c) remains constant throughout the entire @@ -72,20 +72,20 @@ impl Application { zb }; - let mut iteration_count: u32 = 0x0; - let mut square_distance; + let mut iter_count: u32 = 0x0; + let mut square_dist; while { - square_distance = Float::with_val(PRECISION, &za * &za + &zb * &zb).to_f32(); - square_distance <= 256.0 && iteration_count < data.maximum_iteration_count + square_dist = Float::with_val(PRECISION, &za * &za + &zb * &zb).to_f32(); + square_dist <= 256.0 && iter_count < data.max_iter_count } { iterator(&mut za, &mut zb, ca, cb); - iteration_count += 0x1; + iter_count += 0x1; } unsafe { - *iteration_count_buffer.get_unchecked_mut(x as usize) = iteration_count; - *square_distance_buffer.get_unchecked_mut(x as usize) = square_distance; + *iter_count_buffer.get_unchecked_mut( x as usize) = iter_count; + *square_dist_buffer.get_unchecked_mut(x as usize) = square_dist; } } } diff --git a/source/benoit/benoit/application/render_row_normal.rs b/source/benoit/benoit/application/render_row_normal.rs index 570f9d4..4dbb4f5 100644 --- a/source/benoit/benoit/application/render_row_normal.rs +++ b/source/benoit/benoit/application/render_row_normal.rs @@ -33,7 +33,7 @@ use std::sync::Arc; impl Application { pub fn render_row_normal(data: Arc<RenderData>, y: u32, iterator: IteratorFunction) { - let (iteration_count_buffer, square_distance_buffer) = unsafe { data.slice(y) }; + let (iter_count_buffer, square_dist_buffer) = unsafe { data.slice(y) }; for x in 0x0..data.canvas_width { let canvas_width = Float::with_val(PRECISION, data.canvas_width); @@ -49,7 +49,7 @@ impl Application { ca *= 4.0; ca /= &canvas_width; ca /= &data.zoom; - ca += &data.real; + ca += &data.centre_real; ca }; @@ -61,7 +61,7 @@ impl Application { cb *= 4.0; cb /= &canvas_height; cb /= &data.zoom; - cb += &data.imaginary; + cb += &data.centre_imag; cb }; @@ -69,22 +69,22 @@ impl Application { let mut za = Float::with_val(PRECISION, &ca); let mut zb = Float::with_val(PRECISION, &cb); - let mut iteration_count: u32 = 0x0; - let mut square_distance; + let mut iter_count: u32 = 0x0; + let mut square_dist; while { - square_distance = Float::with_val(PRECISION, &za * &za + &zb * &zb).to_f32(); + square_dist = Float::with_val(PRECISION, &za * &za + &zb * &zb).to_f32(); // Having a larger escape radius gives better // results with regard to smoothing. - square_distance <= 256.0 && iteration_count < data.maximum_iteration_count + square_dist <= 256.0 && iter_count < data.max_iter_count } { iterator(&mut za, &mut zb, &ca, &cb); - iteration_count += 0x1; + iter_count += 0x1; } unsafe { - *iteration_count_buffer.get_unchecked_mut(x as usize) = iteration_count; - *square_distance_buffer.get_unchecked_mut(x as usize) = square_distance; + *iter_count_buffer.get_unchecked_mut( x as usize) = iter_count; + *square_dist_buffer.get_unchecked_mut(x as usize) = square_dist; } } } diff --git a/source/benoit/benoit/configuration.rs b/source/benoit/benoit/configuration.rs index 730835a..d777d2d 100644 --- a/source/benoit/benoit/configuration.rs +++ b/source/benoit/benoit/configuration.rs @@ -41,10 +41,10 @@ pub struct Configuration { pub scale: u32, pub frame_count: u32, - pub centre_real: Float, - pub centre_imaginary: Float, - pub zoom: Float, - pub maximum_iteration_count: u32, + pub centre_real: Float, + pub centre_imag: Float, + pub zoom: Float, + pub max_iter_count: u32, pub dump_path: String, diff --git a/source/benoit/benoit/configuration/default.rs b/source/benoit/benoit/configuration/default.rs index c992951..222a9e4 100644 --- a/source/benoit/benoit/configuration/default.rs +++ b/source/benoit/benoit/configuration/default.rs @@ -42,10 +42,10 @@ impl Configuration { scale: 0x2, frame_count: 0x10, - centre_real: Float::with_val(PRECISION, 0.0), - centre_imaginary: Float::with_val(PRECISION, 0.0), - zoom: Float::with_val(PRECISION, 1.0), - maximum_iteration_count: 0x100, + centre_real: Float::with_val(PRECISION, 0.0), + centre_imag: Float::with_val(PRECISION, 0.0), + zoom: Float::with_val(PRECISION, 1.0), + max_iter_count: 0x100, dump_path: "./render/".to_string(), diff --git a/source/benoit/benoit/configuration/load.rs b/source/benoit/benoit/configuration/load.rs index a4ac83c..b61189a 100644 --- a/source/benoit/benoit/configuration/load.rs +++ b/source/benoit/benoit/configuration/load.rs @@ -89,7 +89,7 @@ impl Configuration { match name.as_str() { "burningship" => Fractal::BurningShip, "mandelbrot" => Fractal::Mandelbrot, - "tricorn" => Fractal::Tricorn, + "tricorn" => Fractal::Tricorn, name => panic!("invalid fractal name {name}"), } } else { @@ -102,9 +102,9 @@ impl Configuration { get_integer(&mut configuration.frame_count, &configuration_table, "frame_count"); get_float( &mut configuration.centre_real, &configuration_table, "real"); - get_float( &mut configuration.centre_imaginary, &configuration_table, "imaginary"); + get_float( &mut configuration.centre_imag, &configuration_table, "imaginary"); get_float( &mut configuration.zoom, &configuration_table, "zoom"); - get_integer(&mut configuration.maximum_iteration_count, &configuration_table, "maximum_iteration_count"); + get_integer(&mut configuration.max_iter_count, &configuration_table, "max_iter_count"); return configuration; } diff --git a/source/benoit/benoit/render_data.rs b/source/benoit/benoit/render_data.rs index a849cfd..9b93d33 100644 --- a/source/benoit/benoit/render_data.rs +++ b/source/benoit/benoit/render_data.rs @@ -34,12 +34,12 @@ pub struct RenderData { pub canvas_width: u32, pub canvas_height: u32, - pub real: Float, - pub imaginary: Float, - pub zoom: Float, + pub centre_real: Float, + pub centre_imag: Float, + pub zoom: Float, - pub maximum_iteration_count: u32, + pub max_iter_count: u32, - iteration_count_buffer: *mut u32, - square_distance_buffer: *mut f32, + iter_count_buffer: *mut u32, + square_dist_buffer: *mut f32, } diff --git a/source/benoit/benoit/render_data/new.rs b/source/benoit/benoit/render_data/new.rs index 6e801a0..e779700 100644 --- a/source/benoit/benoit/render_data/new.rs +++ b/source/benoit/benoit/render_data/new.rs @@ -28,22 +28,22 @@ extern crate rug; use rug::Float; impl RenderData { - pub fn new(iteration_count_buffer: &mut [u32], square_distance_buffer: &mut [f32], canvas_width: u32, canvas_height: u32, real: Float, imaginary: Float, zoom: Float, maximum_iteration_count: u32) -> RenderData { - let iteration_count_buffer_pointer = iteration_count_buffer.as_mut_ptr(); - let square_distance_buffer_pointer = square_distance_buffer.as_mut_ptr(); + pub fn new(iter_count_buffer: &mut [u32], square_dist_buffer: &mut [f32], canvas_width: u32, canvas_height: u32, centre_real: Float, centre_imag: Float, zoom: Float, max_iter_count: u32) -> RenderData { + let iter_count_buffer_pointer = iter_count_buffer.as_mut_ptr(); + let square_dist_buffer_pointer = square_dist_buffer.as_mut_ptr(); return RenderData { canvas_width: canvas_width, canvas_height: canvas_height, - real: real, - imaginary: imaginary, - zoom: zoom, + centre_real: centre_real, + centre_imag: centre_imag, + zoom: zoom, - maximum_iteration_count: maximum_iteration_count, + max_iter_count: max_iter_count, - iteration_count_buffer: iteration_count_buffer_pointer, - square_distance_buffer: square_distance_buffer_pointer, + iter_count_buffer: iter_count_buffer_pointer, + square_dist_buffer: square_dist_buffer_pointer, }; } } diff --git a/source/benoit/benoit/render_data/slice.rs b/source/benoit/benoit/render_data/slice.rs index 4f6b486..ab12d4f 100644 --- a/source/benoit/benoit/render_data/slice.rs +++ b/source/benoit/benoit/render_data/slice.rs @@ -28,9 +28,9 @@ use std::slice::from_raw_parts_mut; impl RenderData { pub unsafe fn slice(&self, row: u32) -> (&mut [u32], &mut [f32]) { let offset = row as isize * self.canvas_width as isize; - let iteration_count = from_raw_parts_mut(self.iteration_count_buffer.offset(offset), self.canvas_width as usize); - let distance = from_raw_parts_mut(self.square_distance_buffer.offset(offset), self.canvas_width as usize); + let iter_count = from_raw_parts_mut(self.iter_count_buffer.offset(offset), self.canvas_width as usize); + let distance = from_raw_parts_mut(self.square_dist_buffer.offset(offset), self.canvas_width as usize); - return (iteration_count, distance); + return (iter_count, distance); } } |