| 2 | use std::path::PathBuf; |
| 3 | |
| 4 | fn julia() { |
| 5 | let imgx = 800; |
| 6 | let imgy = 800; |
| 7 | |
| 8 | let scalex = 3.0 / imgx as f32; |
| 9 | let scaley = 3.0 / imgy as f32; |
| 10 | |
| 11 | let mut imgbuf = image::ImageBuffer::new(imgx, imgy); |
| 12 | |
| 13 | for (x, y, pixel) in imgbuf.enumerate_pixels_mut() { |
| 14 | let r = (0.3 * x as f32) as u8; |
| 15 | let b = (0.3 * y as f32) as u8; |
| 16 | let cx = y as f32 * scalex - 1.5; |
| 17 | let cy = x as f32 * scaley - 1.5; |
| 18 | |
| 19 | let c = num_complex::Complex::new(-0.4, 0.6); |
| 20 | let mut z = num_complex::Complex::new(cx, cy); |
| 21 | |
| 22 | let mut g = 0; |
| 23 | while g < 255 && z.norm() <= 2.0 { |
| 24 | z = z * z + c; |
| 25 | g += 1; |
| 26 | } |
| 27 | *pixel = image::Rgb([r, g, b]); |
| 28 | } |
| 29 | |
| 30 | imgbuf.save("fractal.png").unwrap(); |
| 31 | } |
| 32 | |
| 33 | fn main() { |
| 34 | julia(); |