diff --git a/Cargo.lock b/Cargo.lock index 32a2731..f1a5cda 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -88,6 +88,19 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "time", + "winapi", +] + [[package]] name = "clap" version = "2.33.3" @@ -518,6 +531,7 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" name = "physarum" version = "0.1.0" dependencies = [ + "chrono", "criterion", "image", "indicatif", @@ -832,6 +846,16 @@ dependencies = [ "weezl", ] +[[package]] +name = "time" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "tinytemplate" version = "1.2.0" diff --git a/Cargo.toml b/Cargo.toml index 874a91c..c83a630 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ authors = ["mindv0rtex "] edition = "2018" [dependencies] +chrono = "0.4" image = "0.23" indicatif = "0.15" itertools = "0.10" diff --git a/src/main.rs b/src/main.rs index d645094..e62bbce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,29 +1,36 @@ +use chrono::{DateTime, Utc}; use indicatif::{ProgressBar, ProgressStyle}; use physarum::model; use rand::Rng; fn main() { let n_iterations = 400; - let pb = ProgressBar::new(n_iterations); - pb.set_style( - ProgressStyle::default_bar() - .template( - "{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({eta})", - ) - .progress_chars("#>-"), - ); - let (width, height) = (1024, 1024); let n_particles = 1 << 22; let diffusivity = 1; - let n_populations = 1 + rand::thread_rng().gen_range(1..4); - let mut model = model::Model::new(width, height, n_particles, n_populations, diffusivity); - model.print_configurations(); + let mut rng = rand::thread_rng(); - for i in 0..n_iterations { - model.step(); - pb.set_position(i); + loop { + let pb = ProgressBar::new(n_iterations); + pb.set_style( + ProgressStyle::default_bar() + .template( + "{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({eta})", + ) + .progress_chars("#>-"), + ); + + let n_populations = 1 + rng.gen_range(1..4); + let mut model = model::Model::new(width, height, n_particles, n_populations, diffusivity); + model.print_configurations(); + + for i in 0..n_iterations { + model.step(); + pb.set_position(i); + } + pb.finish(); + + let now: DateTime = Utc::now(); + model.save_to_image(format!("out_{}.png", now.timestamp()).as_str()); } - pb.finish_with_message("Finished!"); - model.save_to_image("out.png"); }