add option to invert render

This commit is contained in:
Crispy 2023-07-26 15:51:44 +02:00
parent 0052bd1686
commit 1eb3c04c7f
3 changed files with 17 additions and 10 deletions

View file

@ -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"

View file

@ -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<u8> {
pub fn color_iteration(iter: u16, color: (u8, u8, u8), invert: bool) -> Rgb<u8> {
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

View file

@ -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;
}