particle mod
This commit is contained in:
parent
df6dceab70
commit
c113fdaf92
3 changed files with 44 additions and 32 deletions
|
@ -1,3 +1,5 @@
|
|||
use nannou::prelude::*;
|
||||
|
||||
pub(crate) trait Drawable {
|
||||
fn draw(&self, draw: &Draw);
|
||||
}
|
||||
|
|
39
src/main.rs
39
src/main.rs
|
@ -1,41 +1,13 @@
|
|||
mod drawable;
|
||||
mod particle;
|
||||
|
||||
use drawable::Drawable;
|
||||
use nannou::prelude::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Particle {
|
||||
pos: Vec2,
|
||||
radius: f32,
|
||||
}
|
||||
|
||||
impl Particle {
|
||||
fn new(pos: Vec2) -> Self {
|
||||
Self {
|
||||
pos,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Particle {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
pos: Default::default(),
|
||||
radius: 10.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drawable for Particle {
|
||||
fn draw(&self, draw: &Draw) {
|
||||
draw.ellipse().color(RED).radius(self.radius).xy(self.pos);
|
||||
}
|
||||
}
|
||||
use particle::Particle;
|
||||
|
||||
struct Model {
|
||||
// Store the window ID so we can refer to this specific window later if needed.
|
||||
_window: WindowId,
|
||||
particles: Vec<Particle>,
|
||||
}
|
||||
|
||||
fn model(app: &App) -> Model {
|
||||
|
@ -49,7 +21,10 @@ fn model(app: &App) -> Model {
|
|||
.build()
|
||||
.unwrap();
|
||||
|
||||
Model { _window }
|
||||
Model {
|
||||
_window,
|
||||
particles: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
// Handle events related to the window and update the model if necessary
|
||||
|
|
35
src/particle.rs
Normal file
35
src/particle.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
use drawable::Drawable;
|
||||
|
||||
use crate::drawable;
|
||||
|
||||
use nannou::prelude::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Particle {
|
||||
pos: Vec2,
|
||||
radius: f32,
|
||||
}
|
||||
|
||||
impl Particle {
|
||||
pub(crate) fn new(pos: Vec2) -> Self {
|
||||
Self {
|
||||
pos,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Particle {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
pos: Default::default(),
|
||||
radius: 10.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drawable for Particle {
|
||||
fn draw(&self, draw: &Draw) {
|
||||
draw.ellipse().color(RED).radius(self.radius).xy(self.pos);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue