mirror of https://github.com/E-Almqvist/hsf
parent
698ff3c9f6
commit
836b515390
@ -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<i32> { |
||||
return rect; |
||||
} |
||||
|
||||
fn main() { |
||||
/* |
||||
let args: Vec<String> = env::args().collect(); |
||||
let width: u32 = args[1].parse::<u32>().unwrap(); |
||||
let height: u32 = args[2].parse::<u32>().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(); |
||||
} |
||||
} |
||||
|
@ -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<f64>) -> Complex<f64> { |
||||
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::<f64>::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)); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue