fn view(app: &App, model: &Model, frame: Frame) {
  // the view takes substantially longer to execute than the update, so only draw sometimes
  if frame.nth() % 50 != 0 && frame.nth() < model.loops - 1 {
    return;
  }
  let now = SystemTime::now();
  let win = app.window_rect();

  let xmin = win.x.start;
  let xmax = win.x.end;
  let ymin = win.y.start;
  let ymax = win.y.end;
  let nx = model.nx;
  let ny = model.ny;
  let pixel_width = (xmax - xmin) / nx as f32;
  let pixel_height = (ymax - ymin) / ny as f32;

  // Prepare to draw.
  let draw = app.draw();

  // set background color
  // let bg = Alpha::<Hsl<_, _>, f32>::new(RgbHue::from_degrees(36.0), 0.59, 0.90, 1.0);
  draw.background().color(WHITE);

  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 x = win.x.lerp(i as f32 / nx as f32);
      let y = win.y.lerp(j as f32 / ny as f32);

      // let color = if a_prime > b_prime { color_a } else { color_b };
      let hue = constrain(a - b);
      // let hue = constrain(b - a);
      // let color = nannou::color::hsl(hue, 0.5, 0.5);
      let color = nannou::color::hsl(0., 0.0, hue);
      // let color = nannou::color::rgb(a_prime * hue_a * 255., 0., b_prime * hue_b * 255.);

      draw
        .rect()
        .color(color)
        .x_y(x, y)
        .w_h(pixel_width, pixel_height);
    }
  }

  // Write to the window frame.
  draw.to_frame(app, &frame).unwrap();

  // save image
  if frame.nth() >= model.loops - 1 {
    app
      .main_window()
      .capture_frame_threaded(captured_frame_path(app, &frame));
    capture_model(app, &frame, model);
  }

  match now.elapsed() {
    Ok(elapsed) => {
      let n_updates = model.update_times.len();
      println!(
        "
        Average update time ({} samples): {}
        View time: {}",
        n_updates,
        model.update_times.iter().sum::<u128>() as f32 / n_updates as f32,
        elapsed.as_millis()
      );
    }
    Err(e) => println!("View Error: {:?}", e),
  }
}
// the only thing this should do is draw the model.grid (or maybe model.next)
the only thing this should do is draw the model.grid (or maybe model.next)
the only thing this should do is draw the model . grid ( or maybe model . next )
fn view(app: &App, model: &Model, frame: Frame) {
  // the view takes substantially longer to execute than the update, so only draw sometimes
  if frame.nth() % 50 != 0 && frame.nth() < model.loops - 1 {
    return;
  }
  let now = SystemTime::now();
  let win = app.window_rect();
  let xmin = win.x.start;
  let xmax = win.x.end;
  let ymin = win.y.start;
  let ymax = win.y.end;
  let nx = model.nx;
  let ny = model.ny;
  let pixel_width = (xmax - xmin) / nx as f32;
  let pixel_height = (ymax - ymin) / ny as f32;
  // Prepare to draw.
  let draw = app.draw();
  // set background color
  // let bg = Alpha::<Hsl<_, _>, f32>::new(RgbHue::from_degrees(36.0), 0.59, 0.90, 1.0);
  draw.background().color(WHITE);
  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 x = win.x.lerp(i as f32 / nx as f32);
      let y = win.y.lerp(j as f32 / ny as f32);
      // let color = if a_prime > b_prime { color_a } else { color_b };
      let hue = constrain(a - b);
      // let hue = constrain(b - a);
      // let color = nannou::color::hsl(hue, 0.5, 0.5);
      let color = nannou::color::hsl(0., 0.0, hue);
      // let color = nannou::color::rgb(a_prime * hue_a * 255., 0., b_prime * hue_b * 255.);
      draw
        .rect()
        .color(color)
        .x_y(x, y)
        .w_h(pixel_width, pixel_height);
    }
  }
  // Write to the window frame.
  draw.to_frame(app, &frame).unwrap();
  // save image
  if frame.nth() >= model.loops - 1 {
    app
      .main_window()
      .capture_frame_threaded(captured_frame_path(app, &frame));
    capture_model(app, &frame, model);
  }
  match now.elapsed() {
    Ok(elapsed) => {
      let n_updates = model.update_times.len();
      println!(
        "
        Average update time ({} samples): {}
        View time: {}",
        n_updates,
        model.update_times.iter().sum::<u128>() as f32 / n_updates as f32,
        elapsed.as_millis()
      );
    }
    Err(e) => println!("View Error: {:?}", e),
  }
}
fn view ( app : & App , model : & Model , frame : Frame ) { // the view takes substantially longer to execute than the update, so only draw sometimes if frame . nth ( ) % 50 != 0 && frame . nth ( ) < model . loops - 1 { return ; } let now = SystemTime :: now ( ) ; let win = app . window_rect ( ) ; let xmin = win . x . start ; let xmax = win . x . end ; let ymin = win . y . start ; let ymax = win . y . end ; let nx = model . nx ; let ny = model . ny ; let pixel_width = ( xmax - xmin ) / nx as f32 ; let pixel_height = ( ymax - ymin ) / ny as f32 ; // Prepare to draw. let draw = app . draw ( ) ; // set background color // let bg = Alpha::<Hsl<_, _>, f32>::new(RgbHue::from_degrees(36.0), 0.59, 0.90, 1.0); draw . background ( ) . color ( WHITE ) ; 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 x = win . x . lerp ( i as f32 / nx as f32 ) ; let y = win . y . lerp ( j as f32 / ny as f32 ) ; // let color = if a_prime > b_prime { color_a } else { color_b }; let hue = constrain ( a - b ) ; // let hue = constrain(b - a); // let color = nannou::color::hsl(hue, 0.5, 0.5); let color = nannou :: color :: hsl ( 0. , 0.0 , hue ) ; // let color = nannou::color::rgb(a_prime * hue_a * 255., 0., b_prime * hue_b * 255.); draw . rect ( ) . color ( color ) . x_y ( x , y ) . w_h ( pixel_width , pixel_height ) ; } } // Write to the window frame. draw . to_frame ( app , & frame ) . unwrap ( ) ; // save image if frame . nth ( ) >= model . loops - 1 { app . main_window ( ) . capture_frame_threaded ( captured_frame_path ( app , & frame ) ) ; capture_model ( app , & frame , model ) ; } match now . elapsed ( ) { Ok ( elapsed ) => { let n_updates = model . update_times . len ( ) ; println ! ( " " n_updates model update_times iter ( ) sum u128 ( ) as f32 n_updates as f32 elapsed as_millis ( ) ) ; } Err ( e ) => println ! ( " " e ) , } }
the only thing this should do is draw the model.grid (or maybe model.next)
the only thing this should do is draw the model . grid ( or maybe model . next )
app
&App
model
&Model
frame
Frame