master
E. Almqvist 3 years ago
parent 7af4cc51ed
commit 4a84e41e01
  1. 4
      mas/fractals/mandel/Cargo.toml
  2. 24
      mas/fractals/mandel/src/main.rs
  3. 4
      mas/fractals/mandel/src/mandel.rs
  4. 2
      mas/fractals/mandel/src/render.rs

@ -11,5 +11,5 @@ matrix = "0.22.0"
[dependencies.sdl2] [dependencies.sdl2]
version = "0.35.2" version = "0.35.2"
default-features = false #default-features = false
features = ["ttf"] #features = ["ttf"]

@ -4,7 +4,6 @@ mod render;
use sdl2::pixels::Color; use sdl2::pixels::Color;
use sdl2::event::Event; use sdl2::event::Event;
use sdl2::keyboard::Keycode; use sdl2::keyboard::Keycode;
use std::time::Duration;
fn main() { fn main() {
/* /*
@ -13,14 +12,15 @@ fn main() {
let height: u32 = args[2].parse::<u32>().unwrap(); let height: u32 = args[2].parse::<u32>().unwrap();
println!("{} {}", width, height); println!("{} {}", width, height);
*/ */
let (width, height) = (640, 480); //let (width, height) = (640, 480);
let (mut dx, mut dy) = (0.0, 0.0); let (width, height) = (1600, 900);
let (mut zx, mut zy) = (2.0, 2.0); let (mut dx, mut dy) = (1.0, 0.0);
let mut step = 0.05; let (mut zx, mut zy) = (2.8, 2.0);
let (mut zoom_in, mut zoom_out) = (1.1, 0.9); let step = 0.05;
let (zoom_out, zoom_in) = (1.1, 0.9);
let depth = 1000; let depth = 1000;
let (window, ctx, vid_sys) = render::create_window("Mandelbrot set", width, height); let (window, ctx, _vid_sys) = render::create_window("Mandelbrot set", width, height);
let mut canvas = window.into_canvas().build().unwrap(); let mut canvas = window.into_canvas().build().unwrap();
canvas.set_draw_color(Color::RGB(0, 0, 0)); canvas.set_draw_color(Color::RGB(0, 0, 0));
@ -40,22 +40,22 @@ fn main() {
Event::KeyDown { keycode: Some(Keycode::Left), .. } => { Event::KeyDown { keycode: Some(Keycode::Left), .. } => {
println!("Left"); println!("Left");
render_new = true; render_new = true;
dx -= step; dx -= step * zx;
}, },
Event::KeyDown { keycode: Some(Keycode::Right), .. } => { Event::KeyDown { keycode: Some(Keycode::Right), .. } => {
println!("Right"); println!("Right");
render_new = true; render_new = true;
dx += step; dx += step * zx;
}, },
Event::KeyDown { keycode: Some(Keycode::Up), .. } => { Event::KeyDown { keycode: Some(Keycode::Up), .. } => {
println!("Up"); println!("Up");
render_new = true; render_new = true;
dy += step; dy += step * zy;
}, },
Event::KeyDown { keycode: Some(Keycode::Down), .. } => { Event::KeyDown { keycode: Some(Keycode::Down), .. } => {
println!("Down"); println!("Down");
render_new = true; render_new = true;
dy -= step; dy -= step * zy;
}, },
Event::KeyDown { keycode: Some(Keycode::Space), .. } => { Event::KeyDown { keycode: Some(Keycode::Space), .. } => {
println!("ZOOM+"); println!("ZOOM+");

@ -1,6 +1,4 @@
use crate::render::set_pixel; use crate::render::set_pixel;
use num::complex::Complex64;
use sdl2::pixels::Color; use sdl2::pixels::Color;
use sdl2::render::Canvas; use sdl2::render::Canvas;
@ -8,7 +6,7 @@ pub fn get_col(i: u32, max_iter: u32) -> Color {
if i > max_iter || i == 255 { if i > max_iter || i == 255 {
return Color::RGB(255, 255, 255); return Color::RGB(255, 255, 255);
} else { } else {
return Color::RGB((i as u8), (i as u8), (i as u8)); return Color::RGB(i as u8, i as u8, i as u8);
} }
} }

@ -2,7 +2,7 @@ extern crate sdl2;
use sdl2::pixels::Color; use sdl2::pixels::Color;
use sdl2::rect::Rect; use sdl2::rect::Rect;
use sdl2::render::Canvas; use sdl2::render::Canvas;
use sdl2::ttf::Font; //use sdl2::ttf::Font;
pub fn create_window(title: &str, width: u32, height: u32) pub fn create_window(title: &str, width: u32, height: u32)
-> (sdl2::video::Window, sdl2::Sdl, sdl2::VideoSubsystem) -> (sdl2::video::Window, sdl2::Sdl, sdl2::VideoSubsystem)

Loading…
Cancel
Save