fn update(_app: &App, model: &mut Model, _update: Update) {
  let now = SystemTime::now();
  let Model {
    d_a, d_b, f, k, dt, ..
  } = *model;

  let nx = model.nx;
  let ny = model.nx;

  for i in 0..nx {
    for j in 0..ny {
      let a = model.grid.current_at(i, j, 0);
      let b = model.grid.current_at(i, j, 1);

      let source = f * (1.0 - a);
      let sink = (k + f) * b;
      let reaction = a * b.powi(2);

      // apply convolution
      let diffusion_a = d_a * laplace(i, j, &model.grid, 0, nx, ny);
      let diffusion_b = d_b * laplace(i, j, &model.grid, 1, nx, ny);

      let a_prime = a + (diffusion_a - reaction + source) * dt;
      let b_prime = b + (diffusion_b + reaction - sink) * dt;

      model
        .grid
        .set_next(i, j, constrain(a_prime), constrain(b_prime));
    }
  }

  // swap next and grid
  model.grid.swap();
  match now.elapsed() {
    Ok(elapsed) => model.update_times.push(elapsed.as_millis()),
    Err(e) => println!("Update Error: {:?}", e),
  }
}
// all calculations and grid updates and next/grid swaps should happen here
all calculations and grid updates and next/grid swaps should happen here
all calculations and grid updates and next / grid swaps should happen here
fn update(_app: &App, model: &mut Model, _update: Update) {
  let now = SystemTime::now();
  let Model {
    d_a, d_b, f, k, dt, ..
  } = *model;
  let nx = model.nx;
  let ny = model.nx;
  for i in 0..nx {
    for j in 0..ny {
      let a = model.grid.current_at(i, j, 0);
      let b = model.grid.current_at(i, j, 1);
      let source = f * (1.0 - a);
      let sink = (k + f) * b;
      let reaction = a * b.powi(2);
      // apply convolution
      let diffusion_a = d_a * laplace(i, j, &model.grid, 0, nx, ny);
      let diffusion_b = d_b * laplace(i, j, &model.grid, 1, nx, ny);
      let a_prime = a + (diffusion_a - reaction + source) * dt;
      let b_prime = b + (diffusion_b + reaction - sink) * dt;
      model
        .grid
        .set_next(i, j, constrain(a_prime), constrain(b_prime));
    }
  }
  // swap next and grid
  model.grid.swap();
  match now.elapsed() {
    Ok(elapsed) => model.update_times.push(elapsed.as_millis()),
    Err(e) => println!("Update Error: {:?}", e),
  }
}
fn update ( _app : & App , model : & mut Model , _update : Update ) { let now = SystemTime :: now ( ) ; let Model { d_a , d_b , f , k , dt , .. } = * model ; let nx = model . nx ; let ny = model . nx ; for i in 0 .. nx { for j in 0 .. ny { let a = model . grid . current_at ( i , j , 0 ) ; let b = model . grid . current_at ( i , j , 1 ) ; let source = f * ( 1.0 - a ) ; let sink = ( k + f ) * b ; let reaction = a * b . powi ( 2 ) ; // apply convolution let diffusion_a = d_a * laplace ( i , j , & model . grid , 0 , nx , ny ) ; let diffusion_b = d_b * laplace ( i , j , & model . grid , 1 , nx , ny ) ; let a_prime = a + ( diffusion_a - reaction + source ) * dt ; let b_prime = b + ( diffusion_b + reaction - sink ) * dt ; model . grid . set_next ( i , j , constrain ( a_prime ) , constrain ( b_prime ) ) ; } } // swap next and grid model . grid . swap ( ) ; match now . elapsed ( ) { Ok ( elapsed ) => model . update_times . push ( elapsed . as_millis ( ) ) , Err ( e ) => println ! ( " " e ) , } }
all calculations and grid updates and next/grid swaps should happen here
all calculations and grid updates and next / grid swaps should happen here
_app
&App
model
&mut Model
_update
Update