Skip to content

Instantly share code, notes, and snippets.

@arskiy
Created November 27, 2022 20:44
Show Gist options
  • Save arskiy/27131e7b2cf69dfa1a070018f89c39fa to your computer and use it in GitHub Desktop.
Save arskiy/27131e7b2cf69dfa1a070018f89c39fa to your computer and use it in GitHub Desktop.
ffmpeg -framerate 25 -pattern_type glob -i '*.png' -c:v libx264 -pix_fmt yuv420p out.mp4
extern crate image;
extern crate num;
extern crate rayon;
use num::complex::Complex;
use std::path::Path;
use rayon::prelude::*;
const WIDTH: usize = 1920;
const HEIGHT: usize = 1080;
fn gen_fractal(zoom: f64, origin: (f64, f64), n: u32) {
let c = Complex::new(-0.7, 0.27015);
// let zoom: f64 = 10.0;
// let origin = (0.0, 0.0);
let max_iter = 255;
let mut img = image::RgbImage::new(WIDTH as u32, HEIGHT as u32);
for w in 0..WIDTH {
for h in 0..HEIGHT {
let re = 1.5 * (w as f64 - 1920.0 / 2.) / (0.5 * zoom * 1920.0) + origin.0;
let im = (h as f64 - 1080.0 / 2.) / (0.5 * zoom * 1080.0) + origin.1;
/* Mandelbrot
let c = Complex::new(re, im);
let mut z = Complex::new(0.0, 0.0);
*/
let mut z = Complex::new(re, im);
let mut last_i = max_iter;
for i in 0..max_iter {
z = (z * z) + c;
if z.norm() > 10. {
last_i = i as u8;
break;
}
}
// println!("Width: {}, Height: {}, i: {}", w, h, last_i);
img.put_pixel(w as u32, h as u32, image::Rgb([last_i, last_i, last_i]));
}
}
let res = img.save(Path::new(&format!("./imgs/fractal{:0>5}.png", n)));
println!("Wrote: imgs/fractal{:0>5}.png", n)
}
fn main() {
// gen_fractal((20000 as f64) / 4., (0., 0.028), 1);
(0..500).into_par_iter().for_each(|i| {
let mut x = i as f64;
x = (10. / 400. * x).exp();
gen_fractal(x, (0.0161, 0.028), i);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment