particle mod

bevy-rapier
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 { pub(crate) trait Drawable {
fn draw(&self, draw: &Draw); fn draw(&self, draw: &Draw);
} }

View File

@ -1,41 +1,13 @@
mod drawable; mod drawable;
mod particle;
use drawable::Drawable;
use nannou::prelude::*; use nannou::prelude::*;
use particle::Particle;
#[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);
}
}
struct Model { struct Model {
// Store the window ID so we can refer to this specific window later if needed. // Store the window ID so we can refer to this specific window later if needed.
_window: WindowId, _window: WindowId,
particles: Vec<Particle>,
} }
fn model(app: &App) -> Model { fn model(app: &App) -> Model {
@ -49,7 +21,10 @@ fn model(app: &App) -> Model {
.build() .build()
.unwrap(); .unwrap();
Model { _window } Model {
_window,
particles: Vec::new(),
}
} }
// Handle events related to the window and update the model if necessary // 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);
}
}