From b683d4e3547382b82b8ff984ac3ab7f243ee69ad Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 12 May 2022 09:49:23 +0200 Subject: [PATCH] NaN --- mas/fractals/mandel/src/main.rs | 43 +++++++++++++++++++++++++++++-- mas/fractals/mandel/src/mandel.rs | 8 +++--- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/mas/fractals/mandel/src/main.rs b/mas/fractals/mandel/src/main.rs index 1c8000b..959d7dc 100644 --- a/mas/fractals/mandel/src/main.rs +++ b/mas/fractals/mandel/src/main.rs @@ -13,8 +13,10 @@ fn main() { let height: u32 = args[2].parse::().unwrap(); println!("{} {}", width, height); */ - let (width, height) = (640, 480); - let (xr, yr) = ([0, 320], [0, 240]); + let (width, height) = (640, 640); + let (xr, yr) = ([-2.0, 0.47], [-2.12, 2.12]); + let theta = 0.01; + let scale = 100.0; let depth = 100; let (window, ctx, vid_sys) = render::create_window("Mandelbrot set", width, height); @@ -25,6 +27,7 @@ fn main() { canvas.present(); // render stuff + /* println!("Init mandel render"); for dx in xr[0]..xr[1] { for dy in yr[0]..yr[1] { @@ -34,6 +37,42 @@ fn main() { canvas.present(); } } + */ + let (mut dx, mut dy) = (xr[0], yr[0]); + let (mut x, mut y) = (0.0, 0.0); + let mut tempx = 0.0; + let col: Color; // color buffer + while dx <= xr[1] { + dy = yr[0]; + while dy <= yr[1] { + let col: Color = mandel::get_point_color(dx, dy, depth); + /* + xtemp := x*x - y*y + x0 + y := 2*x*y + y0 + x := xtemp + */ + + tempx = x*x - y*y + xr[0]; + y = 2.0*x*y + yr[0]; + x = tempx; + + // scale coords and apply offsets + /* + x = dx as f64 * scale; + x += (width as f64)/2.0; + + y = dy as f64 * scale; + y += (height as f64)/2.0; + */ + + // render pixel + render::set_pixel(&mut canvas, x as i32, y as i32, col); + println!("({dx} {dy}) - {x} {y}: {col:?}"); + dy += theta; + } + dx += theta; + 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 124a57f..248550b 100644 --- a/mas/fractals/mandel/src/mandel.rs +++ b/mas/fractals/mandel/src/mandel.rs @@ -24,16 +24,16 @@ fn mandel(n: u64, c: Complex64) -> Complex64 { } } -pub fn get_point_color(x: i32, y: i32, depth: u64) -> Color { +pub fn get_point_color(x: f32, y: f32, depth: u64) -> Color { let c = Complex64::new(x.into(), y.into()); let mut z = mandel(depth, c); let mut norm = z.re*z.re + z.im*z.im; - println!("{:?} {:?} < 2?", z, norm); + //println!("{:?} {:?} < 2?", z, norm); - if norm < 4.0 { + if norm < 2.0 { return Color::RGB(0, 0, 0); } else { - return Color::RGB(25, 25, 25); + return Color::RGB(250, 250, 250); } }