Verified Commit e0f48b89 authored by betseg's avatar betseg 🏳🌈

more idiomatic uwu

parent 38d5dbac
......@@ -2,9 +2,22 @@ use mandelbruh::Mandelbrot;
fn main() {
// very big
// let m = Mandelbrot::scaled(-2., 1., -1.2, 1.2, 50.);
// let m = Mandelbrot::new()
// .topleft(1.2, -2.)
// .width(3.)
// .height(2.4)
// .scale(50.);
// println!("{}", m);
// zoomed
// let m = Mandelbrot::scaled(-0.34, -0.19, 0.62, 0.72, 1500.);
// let m = Mandelbrot::new()
// .topleft(0.72, -0.34)
// .width(0.15)
// .height(0.1)
// .scale(1500.);
// println!("{}", m);
// default
let m = Mandelbrot::new();
println!("{}", m);
}
......@@ -7,6 +7,7 @@ use num_complex::Complex64;
use palette::{Hsv, Hue, Pixel, Srgb};
use std::fmt;
#[derive(Debug)]
pub struct Mandelbrot {
xmin: f64,
xmax: f64,
......@@ -15,8 +16,8 @@ pub struct Mandelbrot {
scale: f64,
}
impl Mandelbrot {
pub fn new() -> Self {
impl Default for Mandelbrot {
fn default() -> Self {
Self {
xmin: -2.,
xmax: 1.,
......@@ -25,17 +26,44 @@ impl Mandelbrot {
scale: 10.,
}
}
}
impl Mandelbrot {
#[inline]
pub fn new() -> Self {
Default::default()
}
#[inline]
pub fn topleft(self, top: f64, left: f64) -> Self {
Self {
xmin: left,
ymax: top,
..self
}
}
pub fn scaled(xmin: f64, xmax: f64, ymin: f64, ymax: f64, scale: f64) -> Self {
#[inline]
pub fn width(self, width: f64) -> Self {
Self {
xmin,
xmax,
ymin,
ymax,
scale,
xmax: self.xmin + width,
..self
}
}
#[inline]
pub fn height(self, height: f64) -> Self {
Self {
ymin: self.ymax - height,
..self
}
}
#[inline]
pub fn scale(self, scale: f64) -> Self {
Self { scale, ..self }
}
#[inline]
fn fc(z: Complex64, c: Complex64) -> Complex64 {
z.powu(2) + c
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment