60 lines
1.4 KiB
Rust
60 lines
1.4 KiB
Rust
use physarum::{
|
|
imgdata::{ImgData, ThinGridData},
|
|
model,
|
|
};
|
|
use std::io::Write;
|
|
|
|
fn main() {
|
|
let n_iterations = 1024;
|
|
let (width, height) = (1024, 1024);
|
|
let n_particles = 1 << 22;
|
|
let diffusivity = 1;
|
|
let n_populations = 3;
|
|
|
|
let mut model = model::Model::new(width, height, n_particles, n_populations, diffusivity);
|
|
model.print_configurations();
|
|
|
|
// Setup ffmpeg
|
|
let mut ffmpeg = std::process::Command::new("ffmpeg")
|
|
.args([
|
|
"-y",
|
|
"-f",
|
|
"rawvideo",
|
|
"-pix_fmt",
|
|
"rgb24",
|
|
"-s",
|
|
&format!("{}x{}", width, height),
|
|
"-r",
|
|
"30",
|
|
"-i",
|
|
"-",
|
|
"-c:v",
|
|
"libx264",
|
|
"-preset",
|
|
"fast",
|
|
"output.mp4",
|
|
])
|
|
.stdin(std::process::Stdio::piped())
|
|
.spawn()
|
|
.expect("Failed to start ffmpeg");
|
|
let mut stdin = ffmpeg.stdin.take().unwrap();
|
|
|
|
for _ in 0..n_iterations {
|
|
model.step();
|
|
|
|
// Generate image
|
|
let grids = ThinGridData::new_from_grid_vec(model.population_grids());
|
|
let img_data = ImgData::new(grids, model.palette());
|
|
let img = img_data.to_image();
|
|
let raw_data = img.into_raw();
|
|
|
|
// Write to ffmpeg
|
|
stdin.write_all(&raw_data).unwrap();
|
|
}
|
|
|
|
// Cleanup
|
|
drop(stdin);
|
|
ffmpeg.wait().unwrap();
|
|
println!("Done!");
|
|
}
|