fn view(app: &App, model: &Model, frame: Frame) {
  let Model {
    seed,
    noise_scale,
    num_steps,
    default_length,
    ..
  } = *model;
  let win = app.window_rect();
  let perlin = Perlin::new();
  app.set_loop_mode(LoopMode::loop_ntimes(1));

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

  // Set background
  draw.background().color(BLACK);

  let nx = 100;
  let ny = 100;

  let randomize_start = { || (random_f32() * 7.0) - 3.5 };

  // door
  draw
    .polygon()
    .hsla(41. / 360., 1., 0.68, 1.0)
    .points(door(&win));

  // draw the flow lines from the left border
  for _i in 0..nx {
    for j in 0..ny {
      let y_factor = j as f32 / ny as f32;

      let mut x = DOOR_TOP_LEFT[0];
      let mut y = lerp(DOOR_BOTTOM_LEFT[1], DOOR_TOP_LEFT[1], y_factor) + randomize_start();

      let hue = lerp(273. / 360., 170. / 360., y_factor);
      let color = hsla(hue, 0.5, 0.38, 0.03);
      let line_weight = 1.0;

      // TODO: could this method of generating points (opposed to a mutable vector) be the cause of the out of memory issues?
      let mut points = vec![(pt2(x, y), color)];
      (0..num_steps).for_each(|_| {
        let theta = PI * 2. / 3.;

        // noisy weighted gradient pointing away from center
        let noise_factor = 1.0;
        let theta_factor = 1.0;
        let angle = field(&perlin, x / noise_scale, y / noise_scale, seed) * noise_factor
          + theta * theta_factor;

        x = angle.cos() * default_length + x;
        y = angle.sin() * default_length + y;

        points.push((pt2(x, y), color));
      });

      draw
        .polyline()
        .start_cap_round()
        .weight(line_weight)
        .points_colored(points);
    }
  }

  // draw the flow lines from the top border
  //
  // this is such ridiculous duplicate code, but... also it's fine
  for i in 0..nx {
    let x_factor = i as f32 / nx as f32;

    for _j in 0..ny {
      let mut x = lerp(DOOR_TOP_LEFT[0], DOOR_TOP_RIGHT[0], x_factor) + randomize_start();
      let mut y = DOOR_TOP_LEFT[1];

      let hue = lerp(170. / 360., 273. / 360., x_factor);
      let color = hsla(hue, 0.5, 0.38, 0.03);
      let line_weight = 1.0;

      let mut points = vec![(pt2(x, y), color)];
      (0..num_steps).for_each(|_| {
        let theta = PI * 2. / 3.;

        // noisy weighted gradient pointing away from center
        let noise_factor = 1.0;
        let theta_factor = 1.0;
        let angle = field(&perlin, x / noise_scale, y / noise_scale, seed) * noise_factor
          + theta * theta_factor;

        x = angle.cos() * default_length + x;
        y = angle.sin() * default_length + y;

        points.push((pt2(x, y), color));
      });

      draw
        .polyline()
        .start_cap_round()
        .weight(line_weight)
        .points_colored(points);
    }
  }

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

  let file_path = captured_frame_path(app, &frame);
  app.main_window().capture_frame(file_path);
}
// 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) {
  let Model {
    seed,
    noise_scale,
    num_steps,
    default_length,
    ..
  } = *model;
  let win = app.window_rect();
  let perlin = Perlin::new();
  app.set_loop_mode(LoopMode::loop_ntimes(1));
  // Prepare to draw.
  let draw = app.draw();
  // Set background
  draw.background().color(BLACK);
  let nx = 100;
  let ny = 100;
  let randomize_start = { || (random_f32() * 7.0) - 3.5 };
  // door
  draw
    .polygon()
    .hsla(41. / 360., 1., 0.68, 1.0)
    .points(door(&win));
  // draw the flow lines from the left border
  for _i in 0..nx {
    for j in 0..ny {
      let y_factor = j as f32 / ny as f32;
      let mut x = DOOR_TOP_LEFT[0];
      let mut y = lerp(DOOR_BOTTOM_LEFT[1], DOOR_TOP_LEFT[1], y_factor) + randomize_start();
      let hue = lerp(273. / 360., 170. / 360., y_factor);
      let color = hsla(hue, 0.5, 0.38, 0.03);
      let line_weight = 1.0;
      // TODO: could this method of generating points (opposed to a mutable vector) be the cause of the out of memory issues?
      let mut points = vec![(pt2(x, y), color)];
      (0..num_steps).for_each(|_| {
        let theta = PI * 2. / 3.;
        // noisy weighted gradient pointing away from center
        let noise_factor = 1.0;
        let theta_factor = 1.0;
        let angle = field(&perlin, x / noise_scale, y / noise_scale, seed) * noise_factor
          + theta * theta_factor;
        x = angle.cos() * default_length + x;
        y = angle.sin() * default_length + y;
        points.push((pt2(x, y), color));
      });
      draw
        .polyline()
        .start_cap_round()
        .weight(line_weight)
        .points_colored(points);
    }
  }
  // draw the flow lines from the top border
  //
  // this is such ridiculous duplicate code, but... also it's fine
  for i in 0..nx {
    let x_factor = i as f32 / nx as f32;
    for _j in 0..ny {
      let mut x = lerp(DOOR_TOP_LEFT[0], DOOR_TOP_RIGHT[0], x_factor) + randomize_start();
      let mut y = DOOR_TOP_LEFT[1];
      let hue = lerp(170. / 360., 273. / 360., x_factor);
      let color = hsla(hue, 0.5, 0.38, 0.03);
      let line_weight = 1.0;
      let mut points = vec![(pt2(x, y), color)];
      (0..num_steps).for_each(|_| {
        let theta = PI * 2. / 3.;
        // noisy weighted gradient pointing away from center
        let noise_factor = 1.0;
        let theta_factor = 1.0;
        let angle = field(&perlin, x / noise_scale, y / noise_scale, seed) * noise_factor
          + theta * theta_factor;
        x = angle.cos() * default_length + x;
        y = angle.sin() * default_length + y;
        points.push((pt2(x, y), color));
      });
      draw
        .polyline()
        .start_cap_round()
        .weight(line_weight)
        .points_colored(points);
    }
  }
  // Write to the window frame.
  draw.to_frame(app, &frame).unwrap();
  let file_path = captured_frame_path(app, &frame);
  app.main_window().capture_frame(file_path);
}
fn view ( app : & App , model : & Model , frame : Frame ) { let Model { seed , noise_scale , num_steps , default_length , .. } = * model ; let win = app . window_rect ( ) ; let perlin = Perlin :: new ( ) ; app . set_loop_mode ( LoopMode :: loop_ntimes ( 1 ) ) ; // Prepare to draw. let draw = app . draw ( ) ; // Set background draw . background ( ) . color ( BLACK ) ; let nx = 100 ; let ny = 100 ; let randomize_start = { | | ( random_f32 ( ) * 7.0 ) - 3.5 } ; // door draw . polygon ( ) . hsla ( 41. / 360. , 1. , 0.68 , 1.0 ) . points ( door ( & win ) ) ; // draw the flow lines from the left border for _i in 0 .. nx { for j in 0 .. ny { let y_factor = j as f32 / ny as f32 ; let mut x = DOOR_TOP_LEFT [ 0 ] ; let mut y = lerp ( DOOR_BOTTOM_LEFT [ 1 ] , DOOR_TOP_LEFT [ 1 ] , y_factor ) + randomize_start ( ) ; let hue = lerp ( 273. / 360. , 170. / 360. , y_factor ) ; let color = hsla ( hue , 0.5 , 0.38 , 0.03 ) ; let line_weight = 1.0 ; // TODO: could this method of generating points (opposed to a mutable vector) be the cause of the out of memory issues? let mut points = vec ! [ ( pt2 ( x y ) color ) ] ; ( 0 .. num_steps ) . for_each ( | _ | { let theta = PI * 2. / 3. ; // noisy weighted gradient pointing away from center let noise_factor = 1.0 ; let theta_factor = 1.0 ; let angle = field ( & perlin , x / noise_scale , y / noise_scale , seed ) * noise_factor + theta * theta_factor ; x = angle . cos ( ) * default_length + x ; y = angle . sin ( ) * default_length + y ; points . push ( ( pt2 ( x , y ) , color ) ) ; } ) ; draw . polyline ( ) . start_cap_round ( ) . weight ( line_weight ) . points_colored ( points ) ; } } // draw the flow lines from the top border // // this is such ridiculous duplicate code, but... also it's fine for i in 0 .. nx { let x_factor = i as f32 / nx as f32 ; for _j in 0 .. ny { let mut x = lerp ( DOOR_TOP_LEFT [ 0 ] , DOOR_TOP_RIGHT [ 0 ] , x_factor ) + randomize_start ( ) ; let mut y = DOOR_TOP_LEFT [ 1 ] ; let hue = lerp ( 170. / 360. , 273. / 360. , x_factor ) ; let color = hsla ( hue , 0.5 , 0.38 , 0.03 ) ; let line_weight = 1.0 ; let mut points = vec ! [ ( pt2 ( x y ) color ) ] ; ( 0 .. num_steps ) . for_each ( | _ | { let theta = PI * 2. / 3. ; // noisy weighted gradient pointing away from center let noise_factor = 1.0 ; let theta_factor = 1.0 ; let angle = field ( & perlin , x / noise_scale , y / noise_scale , seed ) * noise_factor + theta * theta_factor ; x = angle . cos ( ) * default_length + x ; y = angle . sin ( ) * default_length + y ; points . push ( ( pt2 ( x , y ) , color ) ) ; } ) ; draw . polyline ( ) . start_cap_round ( ) . weight ( line_weight ) . points_colored ( points ) ; } } // Write to the window frame. draw . to_frame ( app , & frame ) . unwrap ( ) ; let file_path = captured_frame_path ( app , & frame ) ; app . main_window ( ) . capture_frame ( file_path ) ; }
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