fn magnetic_field(
  id: WindowId,
  app: &App,
  frame: Frame,
  field: fn(f32, f32) -> f32,
  char_id: char,
  color_range_1: [f32; 2],
  color_range_2: [f32; 2],
) {
  let win = match app.window(id) {
    Some(window) => window.rect(),
    None => return,
  };

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

  let pi2 = PI * 2.0;
  // number of vertices in each polyline
  let num_steps = 500;
  // distance between each vertex in polyline
  let default_length = 1.0;
  // number of points in our "grid" of starting points
  let resolution = 105;

  // Clear the background to black.
  draw.background().color(BLACK);

  let num_circles = 40;
  for i in 0..num_circles {
    let radius_factor = i as f32 / num_circles as f32;
    let start_radius = Interp::exp(10.0, 800.0, radius_factor);

    for j in 0..resolution {
      let factor = j as f32 / resolution as f32;

      // slightly randomize starting position
      let randomize_start = { || (random_f32() * 7.0) - 3.5 };
      let mut current_x = start_radius * (factor * pi2).cos() + randomize_start();
      let mut current_y = start_radius * (factor * pi2).sin() + randomize_start();

      let mut points = Vec::new();
      let radius = (current_x.powi(2) + current_y.powi(2)).sqrt();

      let factor = if current_y < -1.0 * current_x {
        Interp::lin(color_range_1[0], color_range_1[1], radius / win.w())
      } else {
        Interp::lin(color_range_2[0], color_range_2[1], radius / win.w())
      };

      let hue = RgbHue::from_radians(factor * pi2);
      let color = Alpha::<Hsl<_, _>, f32>::new(hue, 0.5, 0.38, 0.3);
      let line_weight = 1.0;
      points.push((pt2(current_x, current_y), color));

      for _n in 0..num_steps {
        let angle = field(current_x, current_y);

        let new_x = angle.cos() * default_length + current_x;
        let new_y = angle.sin() * default_length + current_y;

        points.push((pt2(new_x, new_y), color));
        current_x = new_x;
        current_y = new_y;
      }

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

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

  // credit: https://github.com/nannou-org/nannou/blob/6dd78a5a7c966d46f25a4f56aeedfc3f4e54c7f5/examples/simple_capture.rs
  let file_path = captured_frame_path_multi(app, &frame, char_id, String::from(""));
  app.window(id).unwrap().capture_frame_threaded(file_path);
}
// char_id is only useful for frame capturing, no other utility
char_id is only useful for frame capturing, no other utility
char_id is only useful for frame capturing no other utility
fn magnetic_field(
  id: WindowId,
  app: &App,
  frame: Frame,
  field: fn(f32, f32) -> f32,
  char_id: char,
  color_range_1: [f32; 2],
  color_range_2: [f32; 2],
) {
  let win = match app.window(id) {
    Some(window) => window.rect(),
    None => return,
  };
  // Prepare to draw.
  let draw = app.draw();
  let pi2 = PI * 2.0;
  // number of vertices in each polyline
  let num_steps = 500;
  // distance between each vertex in polyline
  let default_length = 1.0;
  // number of points in our "grid" of starting points
  let resolution = 105;
  // Clear the background to black.
  draw.background().color(BLACK);
  let num_circles = 40;
  for i in 0..num_circles {
    let radius_factor = i as f32 / num_circles as f32;
    let start_radius = Interp::exp(10.0, 800.0, radius_factor);
    for j in 0..resolution {
      let factor = j as f32 / resolution as f32;
      // slightly randomize starting position
      let randomize_start = { || (random_f32() * 7.0) - 3.5 };
      let mut current_x = start_radius * (factor * pi2).cos() + randomize_start();
      let mut current_y = start_radius * (factor * pi2).sin() + randomize_start();
      let mut points = Vec::new();
      let radius = (current_x.powi(2) + current_y.powi(2)).sqrt();
      let factor = if current_y < -1.0 * current_x {
        Interp::lin(color_range_1[0], color_range_1[1], radius / win.w())
      } else {
        Interp::lin(color_range_2[0], color_range_2[1], radius / win.w())
      };
      let hue = RgbHue::from_radians(factor * pi2);
      let color = Alpha::<Hsl<_, _>, f32>::new(hue, 0.5, 0.38, 0.3);
      let line_weight = 1.0;
      points.push((pt2(current_x, current_y), color));
      for _n in 0..num_steps {
        let angle = field(current_x, current_y);
        let new_x = angle.cos() * default_length + current_x;
        let new_y = angle.sin() * default_length + current_y;
        points.push((pt2(new_x, new_y), color));
        current_x = new_x;
        current_y = new_y;
      }
      draw
        .polyline()
        .start_cap_round()
        .weight(line_weight)
        .points_colored(points);
    }
  }
  // Write to the window frame.
  draw.to_frame(app, &frame).unwrap();
  // credit: https://github.com/nannou-org/nannou/blob/6dd78a5a7c966d46f25a4f56aeedfc3f4e54c7f5/examples/simple_capture.rs
  let file_path = captured_frame_path_multi(app, &frame, char_id, String::from(""));
  app.window(id).unwrap().capture_frame_threaded(file_path);
}
fn magnetic_field ( id : WindowId , app : & App , frame : Frame , field : fn ( f32 , f32 ) -> f32 , char_id : char , color_range_1 : [ f32 ; 2 ] , color_range_2 : [ f32 ; 2 ] , ) { let win = match app . window ( id ) { Some ( window ) => window . rect ( ) , None => return , } ; // Prepare to draw. let draw = app . draw ( ) ; let pi2 = PI * 2.0 ; // number of vertices in each polyline let num_steps = 500 ; // distance between each vertex in polyline let default_length = 1.0 ; // number of points in our "grid" of starting points let resolution = 105 ; // Clear the background to black. draw . background ( ) . color ( BLACK ) ; let num_circles = 40 ; for i in 0 .. num_circles { let radius_factor = i as f32 / num_circles as f32 ; let start_radius = Interp :: exp ( 10.0 , 800.0 , radius_factor ) ; for j in 0 .. resolution { let factor = j as f32 / resolution as f32 ; // slightly randomize starting position let randomize_start = { | | ( random_f32 ( ) * 7.0 ) - 3.5 } ; let mut current_x = start_radius * ( factor * pi2 ) . cos ( ) + randomize_start ( ) ; let mut current_y = start_radius * ( factor * pi2 ) . sin ( ) + randomize_start ( ) ; let mut points = Vec :: new ( ) ; let radius = ( current_x . powi ( 2 ) + current_y . powi ( 2 ) ) . sqrt ( ) ; let factor = if current_y < - 1.0 * current_x { Interp :: lin ( color_range_1 [ 0 ] , color_range_1 [ 1 ] , radius / win . w ( ) ) } else { Interp :: lin ( color_range_2 [ 0 ] , color_range_2 [ 1 ] , radius / win . w ( ) ) } ; let hue = RgbHue :: from_radians ( factor * pi2 ) ; let color = Alpha :: < Hsl < _ , _ > , f32 > :: new ( hue , 0.5 , 0.38 , 0.3 ) ; let line_weight = 1.0 ; points . push ( ( pt2 ( current_x , current_y ) , color ) ) ; for _n in 0 .. num_steps { let angle = field ( current_x , current_y ) ; let new_x = angle . cos ( ) * default_length + current_x ; let new_y = angle . sin ( ) * default_length + current_y ; points . push ( ( pt2 ( new_x , new_y ) , color ) ) ; current_x = new_x ; current_y = new_y ; } draw . polyline ( ) . start_cap_round ( ) . weight ( line_weight ) . points_colored ( points ) ; } } // Write to the window frame. draw . to_frame ( app , & frame ) . unwrap ( ) ; // credit: https://github.com/nannou-org/nannou/blob/6dd78a5a7c966d46f25a4f56aeedfc3f4e54c7f5/examples/simple_capture.rs let file_path = captured_frame_path_multi ( app , & frame , char_id , String :: from ( " " ) ) ; app . window ( id ) . unwrap ( ) . capture_frame_threaded ( file_path ) ; }
char_id is only useful for frame capturing, no other utility
char_id is only useful for frame capturing no other utility
id
WindowId
app
&App
frame
Frame
field
fn(f32, f32) -> f32
char_id
char
color_range_1
[f32; 2]
color_range_2
[f32; 2]