diff --git a/mas/fractals/mandel/src/main.rs b/mas/fractals/mandel/src/main.rs new file mode 100644 index 0000000..c52e9c4 --- /dev/null +++ b/mas/fractals/mandel/src/main.rs @@ -0,0 +1,43 @@ +mod mandel; + +use std::env; +use sfml::window::{Window, Event, Style}; +use sfml::graphics::{Color, Rect}; +use sfml::system::Vector2i; + +fn render_pixel(x: u32, y: u32, col: Color) -> Rect { + return rect; +} + +fn main() { + /* + let args: Vec = env::args().collect(); + let width: u32 = args[1].parse::().unwrap(); + let height: u32 = args[2].parse::().unwrap(); + println!("{} {}", width, height); + */ + let (width, height) = (640, 480); + let (xr, yr) = ([-200, 200], [-200, 200]); + + let mut win = Window::new((width, height), "Mandelbrot set", Style::CLOSE, &Default::default()); + win.set_framerate_limit(20); + win.set_position(Vector2i::new(0, 0)); + + let mut rect = Rect::new(200, 200, 1, 1); + rect.set_fill_color(Color::RED); + + while win.is_open() { + while let Some(ev) = win.poll_event() { + match ev { + Event::Closed => {win.close();}, + _ => {} + } + } + + rect.draw(); + + win.set_active(true); + win.display(); + } +} + diff --git a/mas/fractals/mandel/src/mandel.rs b/mas/fractals/mandel/src/mandel.rs new file mode 100644 index 0000000..68adaab --- /dev/null +++ b/mas/fractals/mandel/src/mandel.rs @@ -0,0 +1,35 @@ +use num::complex::Complex; +use matrix::Matrix; +use sfml::system::Vector2u; +use sfml::window::Window; +use sfml::graphics::Color; + +fn mandel(n: u64, c: Complex) -> Complex { + if n == 0 { + return Complex::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; + } +} + +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 - h/2).into()); + let mut norm = mandel(depth, c).norm(); + + if norm < 2.0 { + return Color::rgb(0, 0, 0); + } else { + return Color::rgb(255, 255, 255); + } +} + +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)); + } + } +}