master
E. Almqvist 3 years ago
parent b683d4e354
commit d0faf22f66
  1. 210801
      mas/fractals/mandel/log
  2. 40
      mas/fractals/mandel/src/main.rs
  3. 32
      mas/fractals/mandel/src/mandel.rs

File diff suppressed because it is too large Load Diff

@ -13,11 +13,11 @@ fn main() {
let height: u32 = args[2].parse::<u32>().unwrap();
println!("{} {}", width, height);
*/
let (width, height) = (640, 640);
let (width, height) = (640, 480);
let (xr, yr) = ([-2.0, 0.47], [-2.12, 2.12]);
let theta = 0.01;
let scale = 100.0;
let depth = 100;
let depth = 400;
let (window, ctx, vid_sys) = render::create_window("Mandelbrot set", width, height);
@ -26,44 +26,16 @@ 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(dx, dy, depth);
//println!("{}:{} {:?}", dx, dy, col);
render::set_pixel(&mut canvas, dx, dy, col);
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;
*/
y = dy*scale + (height as f32)/2.0;
x = dx*scale + (width as f32)/2.0;
// render pixel
render::set_pixel(&mut canvas, x as i32, y as i32, col);
@ -89,5 +61,7 @@ fn main() {
}
::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60));
let mut coltest: Color = mandel::get_point_color(0.0, 1.0, depth);
println!("{coltest:?}");
}

@ -27,13 +27,41 @@ fn mandel(n: u64, c: Complex64) -> Complex64 {
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;
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(250, 250, 250);
}
}
pub fn mandelbrot(w: u32, h: u32) -> Canvas {
/*
for each pixel (Px, Py) on the screen do
x0 := scaled x coordinate of pixel (scaled to lie in the Mandelbrot X scale (-2.00, 0.47))
y0 := scaled y coordinate of pixel (scaled to lie in the Mandelbrot Y scale (-1.12, 1.12))
x := 0.0
y := 0.0
iteration := 0
max_iteration := 1000
while (x*x + y*y 2*2 AND iteration < max_iteration) do
xtemp := x*x - y*y + x0
y := 2*x*y + y0
x := xtemp
iteration := iteration + 1
color := palette[iteration]
plot(Px, Py, color)
*/
for dx in 0..w {
for dy in 0..h {
}
}
}

Loading…
Cancel
Save