Main executable produces new images indefinitely.
This commit is contained in:
parent
0c2158a408
commit
481665b5e9
24
Cargo.lock
generated
24
Cargo.lock
generated
@ -88,6 +88,19 @@ version = "1.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
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]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "2.33.3"
|
version = "2.33.3"
|
||||||
@ -518,6 +531,7 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"
|
|||||||
name = "physarum"
|
name = "physarum"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
"criterion",
|
"criterion",
|
||||||
"image",
|
"image",
|
||||||
"indicatif",
|
"indicatif",
|
||||||
@ -832,6 +846,16 @@ dependencies = [
|
|||||||
"weezl",
|
"weezl",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time"
|
||||||
|
version = "0.1.43"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tinytemplate"
|
name = "tinytemplate"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
|
|||||||
@ -5,6 +5,7 @@ authors = ["mindv0rtex <mindv0rtex@users.noreply.github.com>"]
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
chrono = "0.4"
|
||||||
image = "0.23"
|
image = "0.23"
|
||||||
indicatif = "0.15"
|
indicatif = "0.15"
|
||||||
itertools = "0.10"
|
itertools = "0.10"
|
||||||
|
|||||||
41
src/main.rs
41
src/main.rs
@ -1,29 +1,36 @@
|
|||||||
|
use chrono::{DateTime, Utc};
|
||||||
use indicatif::{ProgressBar, ProgressStyle};
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
use physarum::model;
|
use physarum::model;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let n_iterations = 400;
|
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 (width, height) = (1024, 1024);
|
||||||
let n_particles = 1 << 22;
|
let n_particles = 1 << 22;
|
||||||
let diffusivity = 1;
|
let diffusivity = 1;
|
||||||
let n_populations = 1 + rand::thread_rng().gen_range(1..4);
|
let mut rng = rand::thread_rng();
|
||||||
let mut model = model::Model::new(width, height, n_particles, n_populations, diffusivity);
|
|
||||||
model.print_configurations();
|
|
||||||
|
|
||||||
for i in 0..n_iterations {
|
loop {
|
||||||
model.step();
|
let pb = ProgressBar::new(n_iterations);
|
||||||
pb.set_position(i);
|
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> = Utc::now();
|
||||||
|
model.save_to_image(format!("out_{}.png", now.timestamp()).as_str());
|
||||||
}
|
}
|
||||||
pb.finish_with_message("Finished!");
|
|
||||||
model.save_to_image("out.png");
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user