E. Almqvist 3 years ago
parent a58e8a1b42
commit b683d4e354
  1. 43
      mas/fractals/mandel/src/main.rs
  2. 8
      mas/fractals/mandel/src/mandel.rs

@ -13,8 +13,10 @@ fn main() {
let height: u32 = args[2].parse::<u32>().unwrap(); let height: u32 = args[2].parse::<u32>().unwrap();
println!("{} {}", width, height); println!("{} {}", width, height);
*/ */
let (width, height) = (640, 480); let (width, height) = (640, 640);
let (xr, yr) = ([0, 320], [0, 240]); let (xr, yr) = ([-2.0, 0.47], [-2.12, 2.12]);
let theta = 0.01;
let scale = 100.0;
let depth = 100; let depth = 100;
let (window, ctx, vid_sys) = render::create_window("Mandelbrot set", width, height); let (window, ctx, vid_sys) = render::create_window("Mandelbrot set", width, height);
@ -25,6 +27,7 @@ fn main() {
canvas.present(); canvas.present();
// render stuff // render stuff
/*
println!("Init mandel render"); println!("Init mandel render");
for dx in xr[0]..xr[1] { for dx in xr[0]..xr[1] {
for dy in yr[0]..yr[1] { for dy in yr[0]..yr[1] {
@ -34,6 +37,42 @@ fn main() {
canvas.present(); 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"); println!("Post mandel render");
let mut event_pump = ctx.event_pump().unwrap(); let mut event_pump = ctx.event_pump().unwrap();

@ -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 c = Complex64::new(x.into(), y.into());
let mut z = mandel(depth, c); let mut z = mandel(depth, c);
let mut norm = z.re*z.re + z.im*z.im; 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); return Color::RGB(0, 0, 0);
} else { } else {
return Color::RGB(25, 25, 25); return Color::RGB(250, 250, 250);
} }
} }

Loading…
Cancel
Save