summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml2
-rw-r--r--Makefile91
-rw-r--r--changelog.md6
-rw-r--r--source/benoit/benoit/application/initialise.rs6
-rw-r--r--source/benoit/benoit/application/poll_events.rs8
-rw-r--r--source/benoit/benoit/application/render.rs57
6 files changed, 54 insertions, 116 deletions
diff --git a/Cargo.toml b/Cargo.toml
index e4671c0..286bf07 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "benoit"
-version = "0.13.0"
+version = "0.14.0"
authors = ["Gabriel Bjørnager Jensen"]
edition = "2021"
description = "Mandelbrot renderer."
diff --git a/Makefile b/Makefile
deleted file mode 100644
index a3384a0..0000000
--- a/Makefile
+++ /dev/null
@@ -1,91 +0,0 @@
-CXX=g++
-CXXFLAGS=-Iinclude -D_ATFILE_SOURCE -D_FORTIFY_SOURCE=0x2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_ISOC99_SOURCE -D_ISOC11_SOURCE -D_ISOC2X_SOURCE -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED -D__STDC_WANT_IEC_60559_BFP_EXT__ -D__STDC_WANT_IEC_60559_DFP_EXT__ -D__STDC_WANT_IEC_60559_FUNCS_EXT__ -D__STDC_WANT_IEC_60559_TYPES_EXT__ -D__STDC_WANT_LIB_EXT2__=0x1
-ifneq ($(debug),true)
-CXXFLAGS += -DNDEBUG -g
-endif
-CXXFLAGS += -std=c++20 -Wall -Wextra -Wpedantic
-CXXFLAGS += -march=native -mtune=native -O3
-LDFLAGS = -lfmt -lpng -lpthread -lwebp
-HDRS_CXX = \
- include/benoit/archstr.hh \
- include/benoit/arghandl.hh \
- include/benoit/crtcfg.hh \
- include/benoit/d/alpha.hh \
- include/benoit/d/arch.hh \
- include/benoit/d/cfg.hh \
- include/benoit/d/debug.hh \
- include/benoit/d/dobt.hh \
- include/benoit/d/imgfmt.hh \
- include/benoit/d/kernel.hh \
- include/benoit/d/logdoprint.hh \
- include/benoit/d/maxiter.hh \
- include/benoit/d/numthrds.hh \
- include/benoit/d/outimg.hh \
- include/benoit/d/pos.hh \
- include/benoit/d/printdolog.hh \
- include/benoit/d/resx.hh \
- include/benoit/d/resy.hh \
- include/benoit/d/thelog.hh \
- include/benoit/d/ver.hh \
- include/benoit/err/clsfil.hh \
- include/benoit/err/wrttofil.hh \
- include/benoit/exit.hh \
- include/benoit/helpscrn.hh \
- include/benoit/kernelstr.hh \
- include/benoit/loadcfg.hh \
- include/benoit/log.hh \
- include/benoit/logfunc.hh \
- include/benoit/logfuncret.hh \
- include/benoit/main.hh \
- include/benoit/plotmandelbrot.hh \
- include/benoit/print.hh \
- include/benoit/t/arch.hh \
- include/benoit/t/imgfmt.hh \
- include/benoit/t/kernel.hh \
- include/benoit/t/pos.hh \
- include/benoit/t/rgba.hh \
- include/benoit/t/thrddat.hh \
- include/benoit/wrtimg.hh
-SRCS_CXX = \
- src/benoit/archstr.cc \
- src/benoit/arghandl.cc \
- src/benoit/crtcfg.cc \
- src/benoit/d/alpha.cc \
- src/benoit/d/cfg.cc \
- src/benoit/d/dobt.cc \
- src/benoit/d/imgfmt.cc \
- src/benoit/d/logdoprint.cc \
- src/benoit/d/maxiter.cc \
- src/benoit/d/numthrds.cc \
- src/benoit/d/outimg.cc \
- src/benoit/d/pos.cc \
- src/benoit/d/printdolog.cc \
- src/benoit/d/resx.cc \
- src/benoit/d/resy.cc \
- src/benoit/d/thelog.cc \
- src/benoit/err/clsfil.cc \
- src/benoit/err/wrttofil.cc \
- src/benoit/exit.cc \
- src/benoit/helpscrn.cc \
- src/benoit/kernelstr.cc \
- src/benoit/loadcfg.cc \
- src/benoit/log.cc \
- src/benoit/logfunc.cc \
- src/benoit/logfuncret.cc \
- src/benoit/main.cc \
- src/benoit/plotmandelbrot.cc \
- src/benoit/print.cc \
- src/benoit/t/pos/pos.cc \
- src/benoit/wrtimg.cc \
- src/main.cc
-OBJS_CXX=$(SRCS_CXX:.cc=.o)
-OBJS=$(OBJS_CXX)
-benoit: Makefile $(OBJS)
- $(CXX) $(LDFLAGS) -o $@ $(OBJS)
-$(OBJS_CXX): Makefile $(HDRS_CXX)
-.PHONY: clean
-clean:
- rm $(OBJS)
-.PHONY: purge
-purge:
- rm benoit $(OBJS)
diff --git a/changelog.md b/changelog.md
index 5735e25..907cb79 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,3 +1,9 @@
+# 12
+
+* Render and draw in different passes
+* Update colouring
+* Actually remove old makefile
+
# 11
* Remove old makefile
diff --git a/source/benoit/benoit/application/initialise.rs b/source/benoit/benoit/application/initialise.rs
index beddf54..012e1b0 100644
--- a/source/benoit/benoit/application/initialise.rs
+++ b/source/benoit/benoit/application/initialise.rs
@@ -25,8 +25,8 @@ use crate::benoit::application::Application;
impl Application {
pub fn initialise() -> Application {
- let canvas_width = 0x400;
- let canvas_height = 0x400;
+ let canvas_width = 0x200;
+ let canvas_height = 0x200;
let sdl = sdl2::init().expect("unable to initialise sdl2");
let sdl_video = sdl.video().expect("unable to initialise video");
@@ -46,7 +46,7 @@ impl Application {
position_x: 0.0,
position_y: 0.0,
zoom: 1.0,
- max_iteration_count: 0xFF,
+ max_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 3936f60..5057054 100644
--- a/source/benoit/benoit/application/poll_events.rs
+++ b/source/benoit/benoit/application/poll_events.rs
@@ -68,11 +68,19 @@ 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.do_render = match scancode {
Scancode::A => true,
Scancode::D => true,
Scancode::E => true,
+ Scancode::F => true,
Scancode::Q => true,
+ Scancode::R => true,
Scancode::S => true,
Scancode::W => true,
_ => false,
diff --git a/source/benoit/benoit/application/render.rs b/source/benoit/benoit/application/render.rs
index 5334d26..eca2fe6 100644
--- a/source/benoit/benoit/application/render.rs
+++ b/source/benoit/benoit/application/render.rs
@@ -26,37 +26,42 @@ use crate::benoit::application::Application;
extern crate sdl2;
use sdl2::pixels::Color;
-use sdl2::rect::Rect;
+use sdl2::rect::Point;
+use std::time::Instant;
impl Application {
pub fn render(&mut self) {
eprintln!("rendering: {} + {}i @ {}", self.position_x, self.position_y, self.zoom);
- //let mut data: [i8; 0x100] = [0; 0x100];
+ let canvas_size = self.canvas_height* self.canvas_width;
- for y in 0x0..self.canvas_width {
- for x in 0x0..self.canvas_height {
- let pixel = y * 0xFF + x;
+ let mut data: Vec<u32> = Vec::with_capacity(self.canvas_height as usize * self.canvas_width as usize);
+ let time_start = Instant::now();
+
+ for y in 0x0..self.canvas_height {
+ for x in 0x0..self.canvas_width {
let canvas_width = self.canvas_width as f64;
let canvas_height = self.canvas_height as f64;
- let ca = (x as f64 - canvas_width / 2.0) / (canvas_width / 4.0 * self.zoom) + self.position_x;
- let cb = (y as f64 - canvas_height / 2.0) / (canvas_height / 4.0 * self.zoom) + self.position_y;
+ let ca = (x as f64 - canvas_width / 2.0) / canvas_width * 4.0 / self.zoom + self.position_x;
+ let cb = (y as f64 - canvas_height / 2.0) / canvas_height * 4.0 / self.zoom + self.position_y;
let mut za: f64 = 0.0;
let mut zb: f64 = 0.0;
- let mut iteration_count = 0x0u32;
+ let mut iteration_count: u32 = 0x0;
while iteration_count < self.max_iteration_count {
let square_distance = (za * za + zb * zb).sqrt();
if square_distance > 2.0 * 2.0 { break }
- // z = z^2 + c
{
+ // z = z^2 + c
+
// Complex square:
// a = a^2 - b^2
// b = 2abi
+
let za_temporary = za;
za = za * za - zb * zb + ca;
zb = za_temporary * zb * 2.0 + cb;
@@ -65,22 +70,32 @@ impl Application {
iteration_count += 0x1;
}
- let value = (iteration_count as f32 / self.max_iteration_count as f32 * 255.0).round() as u8;
- let colour = Color::RGB(value, value, value);
- self.canvas.set_draw_color(colour);
-
- let square = Rect::new(
- x as i32,
- y as i32,
- 0x1,
- 0x1,
- );
- self.canvas.fill_rects(&[square]).unwrap();
+ data.push(iteration_count);
}
}
+ 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 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
+ } 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();
+ }
+
self.canvas.present();
- eprintln!("done");
+ eprintln!("done ({}ms)", duration.as_millis());
}
}