fn update(_app: &App, model: &mut Model, _update: Update) {
  let now = SystemTime::now();
  // diffusivity (D) of quantity "A" and "B"
  let d_a = 1.0;
  let d_b = 0.5;
  // the "feed" or "source" rate of quantity "A"
  let f = 0.055;
  // the "kill" or "sink" rate of quantity "B"
  let k = 0.062;
  // "delta t" - time differential between steps
  let dt = 1.0;

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

  for i in 0..nx {
    for j in 0..ny {
      let a = model.grid[i][j].current[0];
      let b = model.grid[i][j].current[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[i][j].next(constrain(a_prime), constrain(b_prime));
    }
  }

  // swap next and grid
  model.grid = model
    .grid
    .iter()
    .map(|row| row.iter().map(|pixel| pixel.swap()).collect())
    .collect();
  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();
  // diffusivity (D) of quantity "A" and "B"
  let d_a = 1.0;
  let d_b = 0.5;
  // the "feed" or "source" rate of quantity "A"
  let f = 0.055;
  // the "kill" or "sink" rate of quantity "B"
  let k = 0.062;
  // "delta t" - time differential between steps
  let dt = 1.0;
  let nx = model.nx;
  let ny = model.nx;
  for i in 0..nx {
    for j in 0..ny {
      let a = model.grid[i][j].current[0];
      let b = model.grid[i][j].current[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[i][j].next(constrain(a_prime), constrain(b_prime));
    }
  }
  // swap next and grid
  model.grid = model
    .grid
    .iter()
    .map(|row| row.iter().map(|pixel| pixel.swap()).collect())
    .collect();
  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 ( ) ; // diffusivity (D) of quantity "A" and "B" let d_a = 1.0 ; let d_b = 0.5 ; // the "feed" or "source" rate of quantity "A" let f = 0.055 ; // the "kill" or "sink" rate of quantity "B" let k = 0.062 ; // "delta t" - time differential between steps let dt = 1.0 ; let nx = model . nx ; let ny = model . nx ; for i in 0 .. nx { for j in 0 .. ny { let a = model . grid [ i ] [ j ] . current [ 0 ] ; let b = model . grid [ i ] [ j ] . current [ 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 [ i ] [ j ] . next ( constrain ( a_prime ) , constrain ( b_prime ) ) ; } } // swap next and grid model . grid = model . grid . iter ( ) . map ( | row | row . iter ( ) . map ( | pixel | pixel . swap ( ) ) . collect ( ) ) . collect ( ) ; 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