From 7965d55de90e8c2cc42defd9fe9fffb261942588 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Fri, 26 Mar 2021 15:11:18 +0000 Subject: [PATCH] things --- TODO.md | 2 +- src/main.rs | 9 ++++++--- src/model.rs | 31 ++++++++++--------------------- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/TODO.md b/TODO.md index 66e9d80..6f324fe 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,4 @@ ### Todo: - Auto create a mp4 from generate images - - Instead of using the command `ffmpeg -r 20 -i tmp/out_%d.png -vcodec libx264 -crf 25 test.mp4` maybe use a rust library to do the same (more research needed) + - Instead of using the command `ffmpeg -r 20 -i tmp/out_%d.png -vcodec libx265 -crf 25 -s 512x512 test.mp4` maybe use a rust library to do the same (more research needed) - GPU compute via [ArrayFire-rust](https://github.com/arrayfire/arrayfire-rust) \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 8094a61..3dba6c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,10 +4,13 @@ use physarum::model; use rand::Rng; fn main() { - let n_iterations = 16384; + // let n_iterations = 16384; + let n_iterations = 4096; + // let n_iterations = 10; + // let (width, height) = (512, 512); - // let (width, height) = (1024, 1024); - let (width, height) = (2048, 2048); + let (width, height) = (1024, 1024); + // let (width, height) = (2048, 2048); let n_particles = 1 << 22; println!("n_particles: {}", n_particles); diff --git a/src/model.rs b/src/model.rs index 2f9d8ce..acf41f4 100644 --- a/src/model.rs +++ b/src/model.rs @@ -155,13 +155,11 @@ impl Model { /// Perform a single simulation step. pub fn step(&mut self) { - let save_image: bool = true; - // Combine grids let grids = &mut self.grids; combine(grids, &self.attraction_table); - println!("Starting tick for all agents..."); + // println!("Starting tick for all agents..."); let agents_tick_time = Instant::now(); self.agents.par_iter_mut().for_each(|agent| { let grid = &grids[agent.population_id]; @@ -196,10 +194,11 @@ impl Model { let direction = Model::pick_direction(trail_c, trail_l, trail_r, &mut rng); agent.rotate_and_move(direction, rotation_angle, step_distance, width, height); }); - + /* let agents_tick_elapsed = agents_tick_time.elapsed().as_millis(); let ms_per_agent: f64 = (agents_tick_elapsed as f64) / (self.agents.len() as f64); println!("Finished tick for all agents. took {}ms\nTime peragent: {}ms", agents_tick_time.elapsed().as_millis(), ms_per_agent); + */ // Deposit for agent in self.agents.iter() { @@ -212,17 +211,7 @@ impl Model { grid.diffuse(diffusivity); }); - /* - println!("Saving image..."); - let image_save_time = Instant::now(); - self.save_to_image(format!("./tmp/out_{}.png", self.iteration).as_str()); - println!("Saved image took {}", image_save_time.elapsed().as_millis()); - */ - println!("Saving imgdata..."); - let image_save_time = Instant::now(); self.save_image_data(); - println!("Saved imgdata, took {}", image_save_time.elapsed().as_millis()); - self.iteration += 1; } @@ -237,7 +226,7 @@ impl Model { } pub fn render_all_imgdata(&self) { - if not Path::new("./tmp").exists() { + if !Path::new("./tmp").exists() { std::fs::create_dir("./tmp"); } @@ -246,18 +235,18 @@ impl Model { "{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] ({pos}/{len}, {percent}%, {per_sec})", )); + /* for img in &self.img_data_vec { Self::save_to_image(img.to_owned()); pb.inc(1); } pb.finish(); - - /* - img_data_list.par_iter().progress_with(pb) - .foreach(|&img| { - save_to_image(img); - }); */ + + (&self.img_data_vec).par_iter().progress_with(pb) + .for_each(|img| { + Self::save_to_image(img.to_owned()); + }); } pub fn save_to_image(imgdata: ImgData) {