diff --git a/Cargo.toml b/Cargo.toml index fa06f0a..34b86e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,10 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -eframe = { version = "0.22.0", default-features = false, features = [ - "glow", - "default_fonts", -] } +eframe = { version = "0.22.0", default-features = false, features = ["glow", "default_fonts"] } image = { version = "0.24.6", default-features = false, features = ["png"] } native-dialog = "0.6.4" rand = "0.8.5" diff --git a/src/generate.rs b/src/generate.rs index 616e786..6c632ae 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -13,6 +13,8 @@ pub struct RenderOptions { pub cx: f64, pub cy: f64, pub fill_style: FillStyle, + #[serde(default)] + pub invert: bool, } #[derive(Clone, PartialEq, Serialize, Deserialize)] @@ -31,6 +33,7 @@ impl Default for RenderOptions { cx: 0.4, cy: -0.2, fill_style: FillStyle::Bright, + invert: false, } } } @@ -58,13 +61,18 @@ pub fn render_c(q: &RenderOptions, mut image: RgbImage) -> RgbImage { image } -pub fn color_iteration(iter: u16, color: (u8, u8, u8)) -> Rgb { +pub fn color_iteration(iter: u16, color: (u8, u8, u8), invert: bool) -> Rgb { let i = iter.min(255) as u8; - Rgb([ + let (r, g, b) = ( i.saturating_mul(color.0), i.saturating_mul(color.1), i.saturating_mul(color.2), - ]) + ); + if invert { + Rgb([255 - r, 255 - g, 255 - b]) + } else { + Rgb([r, g, b]) + } } pub fn render_julia(q: &RenderOptions, color: (u8, u8, u8)) -> RgbImage { @@ -75,8 +83,8 @@ pub fn render_julia(q: &RenderOptions, color: (u8, u8, u8)) -> RgbImage { let ppu = width / q.unit_width; let fill = match q.fill_style { - FillStyle::Black => Rgb([0; 3]), - FillStyle::Bright => color_iteration(q.max_iter, color), + FillStyle::Black => Rgb([q.invert as u8 * 255; 3]), + FillStyle::Bright => color_iteration(q.max_iter, color, q.invert), }; (0..q.height) @@ -91,7 +99,7 @@ pub fn render_julia(q: &RenderOptions, color: (u8, u8, u8)) -> RgbImage { if i == q.max_iter { row.push(fill); } else { - row.push(color_iteration(i, color)); + row.push(color_iteration(i, color, q.invert)); } } row diff --git a/src/main.rs b/src/main.rs index 3039ff4..24709fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -250,6 +250,7 @@ impl eframe::App for JuliaGUI { .radio_value(&mut self.settings.fill_style, FillStyle::Bright, "Bright") .changed(); }); + let set_invert = ui.checkbox(&mut self.settings.invert, "invert"); ui.horizontal(|ui| { ui.label("Colour (RGB)"); @@ -389,6 +390,7 @@ impl eframe::App for JuliaGUI { || set_red.changed() || set_green.changed() || set_blue.changed() || set_point_vis.changed() + || set_invert.changed() { self.settings_changed = true; }