Switched to SDL2

master
E. Almqvist 3 years ago
parent 09c9bef16d
commit 06d2976347
  1. 32
      mas/fractals/mandel/src/main.rs
  2. 23
      mas/fractals/mandel/src/mandel.rs
  3. 17
      mas/fractals/mandel/src/render.rs

@ -1,13 +1,9 @@
mod mandel;
mod render;
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;
}
use sdl2::pixels::Color;
fn main() {
/*
@ -19,25 +15,11 @@ fn main() {
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();
let (window, ctx, vid_sys) = render::create_window("Mandelbrot set", width, height);
let mut can = window.into_canvas().unwrap();
win.set_active(true);
win.display();
}
can.set_draw_color(Color::RGB(0, 0, 0));
can.clear();
can.present();
}

@ -1,8 +1,21 @@
use num::complex::Complex;
use matrix::Matrix;
use sfml::system::Vector2u;
use sfml::window::Window;
use sfml::graphics::Color;
use sdl2::pixels::Color;
/*
#[derive(Debug)]
pub struct Color {
r: u8,
g: u8,
b: u8
}
impl Color {
pub fn rgb(r: u8, g: u8, b: u8) -> Self {
Self { r, g, b }
}
}
*/
fn mandel(n: u64, c: Complex<f64>) -> Complex<f64> {
if n == 0 {
@ -20,9 +33,9 @@ pub fn get_point_color(w: i32, h: i32, x: i32, y: i32, depth: u64) -> Color {
let mut norm = mandel(depth, c).norm();
if norm < 2.0 {
return Color::rgb(0, 0, 0);
return Color::RGB(0, 0, 0);
} else {
return Color::rgb(255, 255, 255);
return Color::RGB(255, 255, 255);
}
}

@ -0,0 +1,17 @@
extern crate sdl2;
use sdl2::pixels::Color;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use std::time::Duration;
pub fn create_window(title: &str, width: u32, height: u32) -> (sdl2::video::Window, sdl2::Sdl, sdl2::VideoSubsystem) {
let ctx = sdl2::init().unwrap();
let vid_sys = ctx.video().unwrap();
let window = vid_sys.window(title, width, height)
.position_centered()
.build()
.unwrap();
return (window, ctx, vid_sys);
}
Loading…
Cancel
Save