wiggly circles
still getting used to nannou, also stalling on rapier
This commit is contained in:
parent
e3a429cfa2
commit
a600ec9147
2 changed files with 19 additions and 5 deletions
11
src/main.rs
11
src/main.rs
|
@ -28,6 +28,10 @@ fn fill_particles(app: &App, particles: &mut Vec<Particle>) {
|
|||
}
|
||||
|
||||
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.
|
||||
let _window = app
|
||||
.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`.
|
||||
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.
|
||||
fn view(app: &App, model: &Model, frame: Frame) {
|
||||
|
|
|
@ -4,15 +4,18 @@ use crate::PARTICLE_SIZE;
|
|||
use nannou::prelude::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Particle {
|
||||
pos: Vec2,
|
||||
radius: f32,
|
||||
pub struct Particle {
|
||||
pub pos: Vec2,
|
||||
pub start_pos: Vec2,
|
||||
pub radius: f32,
|
||||
pub time_offset: f32,
|
||||
}
|
||||
|
||||
impl Particle {
|
||||
pub(crate) fn new(pos: Vec2) -> Self {
|
||||
pub fn new(pos: Vec2) -> Self {
|
||||
Self {
|
||||
pos,
|
||||
start_pos: pos,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +26,8 @@ impl Default for Particle {
|
|||
Self {
|
||||
pos: Default::default(),
|
||||
radius: PARTICLE_SIZE,
|
||||
start_pos: Default::default(),
|
||||
time_offset: random_range(-PI, PI),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue