diff --git a/src/drawable.rs b/src/drawable.rs index b23970a..b919a54 100644 --- a/src/drawable.rs +++ b/src/drawable.rs @@ -12,3 +12,19 @@ where self.iter().for_each(|s| s.draw(draw)) } } + +pub(crate) trait DrawShape +where + T: Drawable, +{ + fn draw(&self, drawable: &T); +} + +impl DrawShape for Draw +where + T: Drawable, +{ + fn draw(&self, drawable: &T) { + drawable.draw(self); + } +} diff --git a/src/main.rs b/src/main.rs index d6db168..2ad186b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,13 @@ mod drawable; mod particle; -use drawable::Drawable; +use drawable::{DrawShape, Drawable}; use nannou::prelude::*; use particle::Particle; +const PARTICLE_COUNT: u32 = 200; +const PARTICLE_SIZE: f32 = 10.0; + struct Model { // Store the window ID so we can refer to this specific window later if needed. _window: WindowId, @@ -14,7 +17,7 @@ struct Model { fn fill_particles(app: &App, particles: &mut Vec) { let boundary = app.window_rect(); - for _ in 0..200 { + for _ in 0..PARTICLE_COUNT { let x = random_range(boundary.left(), boundary.right()); let y = random_range(boundary.top(), boundary.bottom()); @@ -59,13 +62,13 @@ fn event(app: &App, model: &mut Model, event: WindowEvent) { // Draw the state of your `Model` into the given `Frame` here. fn view(app: &App, model: &Model, frame: Frame) { - let draw = app.draw(); - draw.background().color(CORNFLOWERBLUE); + let canvas = app.draw(); + canvas.background().color(CORNFLOWERBLUE); - model.particles.draw(&draw); + canvas.draw(&model.particles); // I don't think there is even a fail condition in this function, but it returns a result? - draw.to_frame(app, &frame).unwrap(); + canvas.to_frame(app, &frame).unwrap(); } fn main() { diff --git a/src/particle.rs b/src/particle.rs index 0fce676..f34d181 100644 --- a/src/particle.rs +++ b/src/particle.rs @@ -1,6 +1,5 @@ -use drawable::Drawable; - -use crate::drawable; +use crate::drawable::Drawable; +use crate::PARTICLE_SIZE; use nannou::prelude::*; @@ -23,7 +22,7 @@ impl Default for Particle { fn default() -> Self { Self { pos: Default::default(), - radius: 10.0, + radius: PARTICLE_SIZE, } } }