wiggly circles

still getting used to nannou, also stalling on rapier
bevy-rapier
Zynh0722 2024-02-16 04:34:30 -08:00
parent e3a429cfa2
commit a600ec9147
2 changed files with 19 additions and 5 deletions

View File

@ -28,6 +28,10 @@ fn fill_particles(app: &App, particles: &mut Vec<Particle>) {
} }
fn model(app: &App) -> Model { fn model(app: &App) -> Model {
// One thing that tripped me up when begginning nannou was realizing
// that view and event methods are per window, and update functions are
// per app
// Create a new window! Store the ID so we can refer to it later. // Create a new window! Store the ID so we can refer to it later.
let _window = app let _window = app
.new_window() .new_window()
@ -61,7 +65,12 @@ fn event(app: &App, model: &mut Model, event: WindowEvent) {
} }
// Update the state of your application here. By default, this gets called right before `view`. // Update the state of your application here. By default, this gets called right before `view`.
fn update(_app: &App, _model: &mut Model, _update: Update) {} fn update(_app: &App, _model: &mut Model, _update: Update) {
_model.particles.iter_mut().for_each(|particle| {
let offset = (_app.time + particle.time_offset).sin() * 100.0;
particle.pos.x = particle.start_pos.x + offset
});
}
// Draw the state of your `Model` into the given `Frame` here. // Draw the state of your `Model` into the given `Frame` here.
fn view(app: &App, model: &Model, frame: Frame) { fn view(app: &App, model: &Model, frame: Frame) {

View File

@ -4,15 +4,18 @@ use crate::PARTICLE_SIZE;
use nannou::prelude::*; use nannou::prelude::*;
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct Particle { pub struct Particle {
pos: Vec2, pub pos: Vec2,
radius: f32, pub start_pos: Vec2,
pub radius: f32,
pub time_offset: f32,
} }
impl Particle { impl Particle {
pub(crate) fn new(pos: Vec2) -> Self { pub fn new(pos: Vec2) -> Self {
Self { Self {
pos, pos,
start_pos: pos,
..Default::default() ..Default::default()
} }
} }
@ -23,6 +26,8 @@ impl Default for Particle {
Self { Self {
pos: Default::default(), pos: Default::default(),
radius: PARTICLE_SIZE, radius: PARTICLE_SIZE,
start_pos: Default::default(),
time_offset: random_range(-PI, PI),
} }
} }
} }