diff --git a/mas/fractals/mandel/src/main.rs b/mas/fractals/mandel/src/main.rs index 7a714ac..1c8000b 100644 --- a/mas/fractals/mandel/src/main.rs +++ b/mas/fractals/mandel/src/main.rs @@ -14,8 +14,8 @@ fn main() { println!("{} {}", width, height); */ let (width, height) = (640, 480); - let (xr, yr) = ([-320, 320], [-240, 240]); - let depth = 500; + let (xr, yr) = ([0, 320], [0, 240]); + let depth = 100; let (window, ctx, vid_sys) = render::create_window("Mandelbrot set", width, height); @@ -28,14 +28,12 @@ fn main() { println!("Init mandel render"); for dx in xr[0]..xr[1] { for dy in yr[0]..yr[1] { - let col: Color = mandel::get_point_color(width.try_into().unwrap(), - height.try_into().unwrap(), - dx, dy, depth); + let col: Color = mandel::get_point_color(dx, dy, depth); //println!("{}:{} {:?}", dx, dy, col); render::set_pixel(&mut canvas, dx, dy, col); + canvas.present(); } } - canvas.present(); println!("Post mandel render"); let mut event_pump = ctx.event_pump().unwrap(); diff --git a/mas/fractals/mandel/src/mandel.rs b/mas/fractals/mandel/src/mandel.rs index 76feb76..124a57f 100644 --- a/mas/fractals/mandel/src/mandel.rs +++ b/mas/fractals/mandel/src/mandel.rs @@ -1,4 +1,4 @@ -use num::complex::Complex; +use num::complex::Complex64; use sdl2::pixels::Color; /* @@ -16,34 +16,24 @@ impl Color { } */ -fn mandel(n: u64, c: Complex) -> Complex { +fn mandel(n: u64, c: Complex64) -> Complex64 { if n == 0 { - return Complex::new(0.0, 0.0); + return Complex64::new(0.0, 0.0); } else { - let mut new_z = mandel(n-1, c); - new_z = new_z.powu(2); - new_z += c; - return new_z; + return mandel(n-1, c).norm() + c; } } -pub fn get_point_color(w: i32, h: i32, x: i32, y: i32, depth: u64) -> Color { - let c = Complex::::new((x + w/2).into(), (y + w/2).into()); +pub fn get_point_color(x: i32, y: i32, depth: u64) -> Color { + let c = Complex64::new(x.into(), y.into()); let mut z = mandel(depth, c); - let mut norm = z.norm(); - println!("\rNorm: {:?}", norm); + let mut norm = z.re*z.re + z.im*z.im; + + println!("{:?} {:?} < 2?", z, norm); - if norm < 2.0 { + if norm < 4.0 { return Color::RGB(0, 0, 0); } else { - return Color::RGB(255, 25, 25); - } -} - -pub fn generate_points(from_x: i32, to_x: i32, from_y: i32, to_y: i32, depth: u64) { - for x in from_x..to_x { - for y in from_y..to_y { - println!("{:?}", get_point_color(200, 200, x, y, depth)); - } + return Color::RGB(25, 25, 25); } }