The.
This commit is contained in:
parent
e445814c18
commit
7729b2234b
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
|
imgs/*
|
||||||
|
*.mp4
|
||||||
|
3
Makefile
Normal file
3
Makefile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
default:
|
||||||
|
cargo r
|
||||||
|
ffmpeg -framerate 25 -i imgs/%d.png -crf 20 -pix_fmt yuv420p output.mp4
|
75
src/main.rs
75
src/main.rs
@ -2,48 +2,61 @@ use image::{ImageBuffer, Rgb};
|
|||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
// Image size.
|
// Image size.
|
||||||
const IMGW: u32 = 1000;
|
const IMGW: u32 = 1024;
|
||||||
const IMGH: u32 = 1000;
|
const IMGH: u32 = 1024;
|
||||||
|
|
||||||
// Fractal settings.
|
// Fractal settings.
|
||||||
const MAXITER: u32 = 600;
|
const MAXITER: u32 = IMGW;
|
||||||
|
const MAXITER_F64: f64 = MAXITER as f64;
|
||||||
const ESCRAD: f64 = 2.4;
|
const ESCRAD: f64 = 2.4;
|
||||||
|
|
||||||
// Fractal bounds.
|
|
||||||
const XMIN: f64 = 2.0;
|
|
||||||
const XMAX: f64 = -2.0;
|
|
||||||
const YMIN: f64 = 2.0;
|
|
||||||
const YMAX: f64 = -2.0;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let w = IMGW as f64;
|
let w = IMGW as f64;
|
||||||
let h = IMGH as f64;
|
let h = IMGH as f64;
|
||||||
|
|
||||||
let pxs: Vec<u8> = (0..IMGH)
|
// Fractal bounds.
|
||||||
.into_par_iter()
|
let mut width: f64 = 2.0; // Initial frame width
|
||||||
.flat_map(|y| {
|
let mut xmin: f64 = -1.0;
|
||||||
let fy = y as f64;
|
let mut ymin: f64 = -1.0;
|
||||||
(0..IMGW)
|
|
||||||
.into_par_iter()
|
|
||||||
.flat_map(move |x| {
|
|
||||||
let cx = map_range(x as f64, 0.0, w, XMIN, XMAX);
|
|
||||||
let cy = map_range(fy, 0.0, h, YMIN, YMAX);
|
|
||||||
let c = num_complex::Complex::new(cx, cy);
|
|
||||||
|
|
||||||
// Compute color for each pixel.
|
let target_x = -0.4638686756;
|
||||||
col_map(esc_time(c)).to_vec()
|
let target_y = 0.0723647;
|
||||||
})
|
|
||||||
.collect::<Vec<u8>>()
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// Create the image from the pixel buffer.
|
let zoom_factor = 1.2;
|
||||||
let img = ImageBuffer::<Rgb<u8>, _>::from_raw(IMGW, IMGH, pxs).unwrap();
|
|
||||||
|
|
||||||
img.save("h.png").unwrap();
|
for i in 1..200 {
|
||||||
println!("Done.");
|
let pxs: Vec<u8> = (0..IMGH)
|
||||||
|
.into_par_iter()
|
||||||
|
.flat_map(|y| {
|
||||||
|
let fy = y as f64;
|
||||||
|
(0..IMGW)
|
||||||
|
.into_par_iter()
|
||||||
|
.flat_map(move |x| {
|
||||||
|
let cx = map_range(x as f64, 0.0, w, xmin, xmin + width);
|
||||||
|
let cy = map_range(fy, 0.0, h, ymin, ymin + width);
|
||||||
|
let c = num_complex::Complex::new(cx, cy);
|
||||||
|
|
||||||
|
// Compute color for each pixel.
|
||||||
|
col_map(esc_time(c)).to_vec()
|
||||||
|
})
|
||||||
|
.collect::<Vec<u8>>()
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// Create the image from the pixel buffer.
|
||||||
|
let img = ImageBuffer::<Rgb<u8>, _>::from_raw(IMGW, IMGH, pxs).unwrap();
|
||||||
|
|
||||||
|
img.save(format!("imgs/{i}.png")).unwrap();
|
||||||
|
println!("#{i} done.");
|
||||||
|
|
||||||
|
// Adjust bounds for the next zoom level
|
||||||
|
xmin = target_x - width / 2.0;
|
||||||
|
ymin = target_y - width / 2.0;
|
||||||
|
width /= zoom_factor; // Zoom in by reducing width
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Maps a value from one range to another.
|
// Maps a value from one range to another.
|
||||||
fn map_range(val: f64, imin: f64, imax: f64, omin: f64, omax: f64) -> f64 {
|
fn map_range(val: f64, imin: f64, imax: f64, omin: f64, omax: f64) -> f64 {
|
||||||
omin + (val - imin) * (omax - omin) / (imax - imin)
|
omin + (val - imin) * (omax - omin) / (imax - imin)
|
||||||
@ -66,8 +79,8 @@ fn col_map(iter: u32) -> [u8; 3] {
|
|||||||
if iter == MAXITER {
|
if iter == MAXITER {
|
||||||
[0, 0, 0] // Black for points that never escape.
|
[0, 0, 0] // Black for points that never escape.
|
||||||
} else {
|
} else {
|
||||||
let t = iter as f64 / MAXITER as f64;
|
let t = iter as f64 / MAXITER_F64;
|
||||||
let c = (t * 700.0) as u8;
|
let c = (t * MAXITER_F64) as u8;
|
||||||
[c, c, c]
|
[c, c, c]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user