From c113fdaf9224fefe9067aa71ac1fa69d1fef52e4 Mon Sep 17 00:00:00 2001 From: Zynh0722 Date: Wed, 14 Feb 2024 21:41:23 -0800 Subject: [PATCH] particle mod --- src/drawable.rs | 2 ++ src/main.rs | 39 +++++++-------------------------------- src/particle.rs | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 32 deletions(-) create mode 100644 src/particle.rs diff --git a/src/drawable.rs b/src/drawable.rs index 4cf9271..b23970a 100644 --- a/src/drawable.rs +++ b/src/drawable.rs @@ -1,3 +1,5 @@ +use nannou::prelude::*; + pub(crate) trait Drawable { fn draw(&self, draw: &Draw); } diff --git a/src/main.rs b/src/main.rs index a3b9c2c..3c80352 100644 --- a/src/main.rs +++ b/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, } 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 diff --git a/src/particle.rs b/src/particle.rs new file mode 100644 index 0000000..9964a85 --- /dev/null +++ b/src/particle.rs @@ -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); + } +}