Complex numbers thing

master
E. Almqvist 3 years ago
parent 047eae1d9e
commit e0e8a69a9b
  1. 25
      mas/fractals/mandel/src/main.rs
  2. 4
      mas/fractals/mandel/src/mandel.rs

@ -14,7 +14,7 @@ fn main() {
println!("{} {}", width, height);
*/
let (width, height) = (640, 480);
let (xr, yr) = ([-200, 200], [-200, 200]);
let (xr, yr) = ([-320, 320], [-240, 240]);
let depth = 500;
let (window, ctx, vid_sys) = render::create_window("Mandelbrot set", width, height);
@ -24,6 +24,20 @@ fn main() {
canvas.clear();
canvas.present();
// render stuff
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);
//println!("{}:{} {:?}", dx, dy, col);
render::set_pixel(&mut canvas, dx, dy, col);
}
}
canvas.present();
println!("Post mandel render");
let mut event_pump = ctx.event_pump().unwrap();
'running: loop {
for event in event_pump.poll_iter() {
@ -36,15 +50,6 @@ fn main() {
}
}
// render stuff
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);
println!("{}:{} {:?}", dx, dy, col);
render::set_pixel(&mut canvas, dx, dy, col);
}
}
canvas.present();
}
::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60));
}

@ -29,7 +29,9 @@ fn mandel(n: u64, c: Complex<f64>) -> Complex<f64> {
pub fn get_point_color(w: i32, h: i32, x: i32, y: i32, depth: u64) -> Color {
let c = Complex::<f64>::new((x + w/2).into(), (y + w/2).into());
let mut norm = mandel(depth, c).norm();
let mut z = mandel(depth, c);
let mut norm = z.norm();
println!("\rNorm: {:?}", norm);
if norm < 2.0 {
return Color::RGB(0, 0, 0);

Loading…
Cancel
Save