particle mod

This commit is contained in:
Zynh0722 2024-02-14 21:41:23 -08:00
parent df6dceab70
commit c113fdaf92
3 changed files with 44 additions and 32 deletions

View file

@ -1,3 +1,5 @@
use nannou::prelude::*;
pub(crate) trait Drawable {
fn draw(&self, draw: &Draw);
}

View file

@ -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
View 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);
}
}