summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md5
-rw-r--r--source/benoit/benoit/application.rs9
-rw-r--r--source/benoit/benoit/application/initialise.rs16
-rw-r--r--source/benoit/benoit/application/poll_events.rs8
-rw-r--r--source/benoit/benoit/application/render.rs29
5 files changed, 41 insertions, 26 deletions
diff --git a/changelog.md b/changelog.md
index 907cb79..aac0e81 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,3 +1,8 @@
+# 13
+
+* Update render message
+* Add scaling setting
+
# 12
* Render and draw in different passes
diff --git a/source/benoit/benoit/application.rs b/source/benoit/benoit/application.rs
index 6f85bef..144191e 100644
--- a/source/benoit/benoit/application.rs
+++ b/source/benoit/benoit/application.rs
@@ -38,11 +38,12 @@ pub struct Application {
canvas_width: u32,
canvas_height: u32,
+ scale: u32,
- position_x: f64,
- position_y: f64,
- zoom: f64,
- max_iteration_count: u32,
+ position_x: f64,
+ position_y: f64,
+ zoom: f64,
+ maximum_iteration_count: u32,
do_render: bool,
}
diff --git a/source/benoit/benoit/application/initialise.rs b/source/benoit/benoit/application/initialise.rs
index 012e1b0..9c9cec2 100644
--- a/source/benoit/benoit/application/initialise.rs
+++ b/source/benoit/benoit/application/initialise.rs
@@ -25,13 +25,14 @@ use crate::benoit::application::Application;
impl Application {
pub fn initialise() -> Application {
- let canvas_width = 0x200;
- let canvas_height = 0x200;
+ let canvas_width: u32 = 0x400;
+ let canvas_height: u32 = 0x400;
+ let scale: u32 = 0x1;
let sdl = sdl2::init().expect("unable to initialise sdl2");
let sdl_video = sdl.video().expect("unable to initialise video");
- let window = sdl_video.window("Benoit", canvas_width, canvas_height).position_centered().build().expect("unable to open window");
+ let window = sdl_video.window("Benoit", canvas_width * scale, canvas_height * scale).position_centered().build().expect("unable to open window");
let canvas = window.into_canvas().build().expect("unable to create canvas");
@@ -42,11 +43,12 @@ impl Application {
canvas_width: canvas_width,
canvas_height: canvas_height,
+ scale: scale,
- position_x: 0.0,
- position_y: 0.0,
- zoom: 1.0,
- max_iteration_count: 0x100,
+ position_x: 0.0,
+ position_y: 0.0,
+ zoom: 1.0,
+ maximum_iteration_count: 0x100,
do_render: true,
};
diff --git a/source/benoit/benoit/application/poll_events.rs b/source/benoit/benoit/application/poll_events.rs
index 5057054..a83678d 100644
--- a/source/benoit/benoit/application/poll_events.rs
+++ b/source/benoit/benoit/application/poll_events.rs
@@ -68,10 +68,10 @@ impl Application {
_ => 0.0,
};
- self.max_iteration_count = match scancode {
- Scancode::F => self.max_iteration_count * 0x2,
- Scancode::R => self.max_iteration_count / 0x2,
- _ => self.max_iteration_count,
+ self.maximum_iteration_count = match scancode {
+ Scancode::F => self.maximum_iteration_count * 0x2,
+ Scancode::R => self.maximum_iteration_count / 0x2,
+ _ => self.maximum_iteration_count,
};
self.do_render = match scancode {
diff --git a/source/benoit/benoit/application/render.rs b/source/benoit/benoit/application/render.rs
index eca2fe6..cc5b9ce 100644
--- a/source/benoit/benoit/application/render.rs
+++ b/source/benoit/benoit/application/render.rs
@@ -26,16 +26,16 @@ use crate::benoit::application::Application;
extern crate sdl2;
use sdl2::pixels::Color;
-use sdl2::rect::Point;
+use sdl2::rect::Rect;
use std::time::Instant;
impl Application {
pub fn render(&mut self) {
- eprintln!("rendering: {} + {}i @ {}", self.position_x, self.position_y, self.zoom);
+ eprintln!("rendering: {}{:+}i ({}x) @ ({})", self.position_x, self.position_y, self.zoom, self.maximum_iteration_count);
- let canvas_size = self.canvas_height* self.canvas_width;
+ let canvas_size = self.canvas_height * self.canvas_width;
- let mut data: Vec<u32> = Vec::with_capacity(self.canvas_height as usize * self.canvas_width as usize);
+ let mut data = Vec::<u32>::with_capacity(canvas_size as usize);
let time_start = Instant::now();
@@ -51,7 +51,7 @@ impl Application {
let mut zb: f64 = 0.0;
let mut iteration_count: u32 = 0x0;
- while iteration_count < self.max_iteration_count {
+ while iteration_count < self.maximum_iteration_count {
let square_distance = (za * za + zb * zb).sqrt();
if square_distance > 2.0 * 2.0 { break }
@@ -77,21 +77,28 @@ impl Application {
let duration = time_start.elapsed();
for pixel in 0x0..canvas_size {
- let y = pixel / self.canvas_width;
- let x = pixel - y * self.canvas_width;
+ let y = pixel as u32 / self.canvas_width;
+ let x = pixel as u32 - y * self.canvas_width;
let iteration_count = data[pixel as usize];
- let value: u8 = if iteration_count != self.max_iteration_count {
- (iteration_count as f32 / 64.0 % 1.0 * 255.0).round() as u8
+ let factor = iteration_count as f32 / 64.0 % 1.0;
+
+ let value: u8 = if iteration_count != self.maximum_iteration_count {
+ (factor * 255.0).round() as u8
} else {
0x0
};
let colour = Color::RGB(value, value, value);
self.canvas.set_draw_color(colour);
- let point = Point::new(x as i32, y as i32);
- self.canvas.draw_point(point).unwrap();
+ let rectangle = Rect::new(
+ (x * self.scale) as i32,
+ (y * self.scale) as i32,
+ self.scale,
+ self.scale
+ );
+ self.canvas.fill_rects(&[rectangle]).unwrap();
}
self.canvas.present();