Some UI!
This commit is contained in:
parent
95e328ea1f
commit
4f96be8fa6
3285
Cargo.lock
generated
3285
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
13
Cargo.toml
13
Cargo.toml
@ -5,9 +5,18 @@ edition = "2021"
|
|||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "model"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "ui"
|
||||||
|
path = "src/ui.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "4.1.8"
|
clap = { version = "4.1.8", features = ["derive"] }
|
||||||
#bevy = { version = "0.9.1", features = ["dynamic"] }
|
bevy = { version = "0.9.1", features = ["dynamic"] }
|
||||||
nd_array = "0.1.0"
|
nd_array = "0.1.0"
|
||||||
num-integer = "0.1.45"
|
num-integer = "0.1.45"
|
||||||
rand = { version = "0.8.5", features = ["default", "small_rng"] }
|
rand = { version = "0.8.5", features = ["default", "small_rng"] }
|
||||||
|
csv = "1.1"
|
||||||
|
|||||||
22
src/main.rs
22
src/main.rs
@ -15,13 +15,29 @@ use rand::rngs::SmallRng;
|
|||||||
use crate::system::{DIM, Position};
|
use crate::system::{DIM, Position};
|
||||||
use crate::system::model::DLASystem;
|
use crate::system::model::DLASystem;
|
||||||
|
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
struct Cli {
|
||||||
|
seed: u64,
|
||||||
|
max_particles: usize,
|
||||||
|
stick_probability: f32,
|
||||||
|
csv_path: String,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
use rand::{SeedableRng, thread_rng};
|
let cli = Cli::parse();
|
||||||
let mut sys = DLASystem::<SmallRng, VectorStorage, LocalRandomWalker>::new(1, 1000, 1.0);
|
|
||||||
|
let mut sys = DLASystem::<SmallRng, VectorStorage, LocalRandomWalker>::new(
|
||||||
|
cli.seed,
|
||||||
|
cli.max_particles,
|
||||||
|
cli.stick_probability
|
||||||
|
);
|
||||||
|
|
||||||
while sys.running {
|
while sys.running {
|
||||||
sys.update();
|
sys.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
sys.export_data();
|
sys.export_data()
|
||||||
|
.expect("Failed to write");
|
||||||
}
|
}
|
||||||
|
|||||||
71
src/ui.rs
Normal file
71
src/ui.rs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
use std::default::Default;
|
||||||
|
use std::error::Error;
|
||||||
|
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
|
||||||
|
use csv::{Position, Reader, ReaderBuilder};
|
||||||
|
|
||||||
|
struct Position2D(i32, i32);
|
||||||
|
|
||||||
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
App::new()
|
||||||
|
.add_plugins(DefaultPlugins)
|
||||||
|
.add_startup_system(setup_ui)
|
||||||
|
.add_startup_system(read_csv)
|
||||||
|
.run();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_csv(
|
||||||
|
mut commands: Commands
|
||||||
|
) {
|
||||||
|
let csv_path = "/Users/joshuacoles/Developer/checkouts/jc3091/CompB DLA/data-analysis/data/stick-probability/0.6/1.csv";
|
||||||
|
let mut reader = ReaderBuilder::new()
|
||||||
|
.has_headers(true)
|
||||||
|
.from_path(csv_path)
|
||||||
|
.expect("Failed to read csv");
|
||||||
|
|
||||||
|
let headers = reader.headers()
|
||||||
|
.expect("Failed to read headers");
|
||||||
|
|
||||||
|
dbg!(headers);
|
||||||
|
|
||||||
|
let x_column = headers.iter().position(|name| name.trim() == "x")
|
||||||
|
.expect("Failed to find x column");
|
||||||
|
|
||||||
|
let y_column = headers.iter().position(|name| name.trim() == "y")
|
||||||
|
.expect("Failed to find x column");
|
||||||
|
|
||||||
|
let positions = reader
|
||||||
|
.records()
|
||||||
|
.map(|record| {
|
||||||
|
let record = record.expect("Failed to read position");
|
||||||
|
let x: i32 = record[x_column].trim().parse::<i32>().expect("Failed to read x");
|
||||||
|
let y: i32 = record[y_column].trim().parse::<i32>().expect("Failed to read y");
|
||||||
|
|
||||||
|
Position2D(x, y)
|
||||||
|
});
|
||||||
|
|
||||||
|
for Position2D(x, y) in positions {
|
||||||
|
// Rectangle
|
||||||
|
let rect_size = 10.0;
|
||||||
|
println!("{} {}", x, y);
|
||||||
|
|
||||||
|
commands.spawn(SpriteBundle {
|
||||||
|
sprite: Sprite {
|
||||||
|
color: Color::rgb(0.25, 0.25, 0.75),
|
||||||
|
custom_size: Some(Vec2::new(rect_size, rect_size)),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
transform: Transform::from_translation(Vec3::new((x as f32) * rect_size, (y as f32) * rect_size, 0.)),
|
||||||
|
..default()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_ui(
|
||||||
|
mut commands: Commands,
|
||||||
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
|
) {
|
||||||
|
commands.spawn(Camera2dBundle::default());
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user