Advertisement
jhaand

Nannou with overlapping circles

Feb 18th, 2022
1,519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.69 KB | None | 0 0
  1. use nannou::prelude::*;
  2.  
  3. fn main() {
  4.     nannou::sketch(view).run();
  5. }
  6.  
  7. fn view(app: &App, frame: Frame) {
  8.     let columns = 5.0;
  9.     let rows    = 4.0;
  10.     let draw = app.draw();
  11.     let win = app.window_rect();
  12.     let x_step = (win.w() / columns) as usize;
  13.     let y_step = (win.h() / rows) as usize;
  14.     let stroke_w = win.w() / 50.0;
  15.     let x_min = win.left() as isize;
  16.     let x_max = win.right() as isize;
  17.     let y_min = win.top() as isize;
  18.     let y_max = win.bottom() as isize;
  19.     app.set_loop_mode(LoopMode::rate_fps(60.0));
  20. //    draw.background().color(rgba(0.0, 0.0, 0.0, 0.0));
  21.     draw.rect().rgba(0.0, 0.0, 0.0, 0.25).w(win.w()).h(win.h());
  22.  
  23.     let radius = (app.time / 5.0).sin().abs() * 300.0 ;
  24.     let color_yellow = rgba(1.0, 1.0, 0.0, 0.25);
  25.     let color_cyan = rgba(0.0, 1.0, 1.0, 0.25);
  26.     let color_magenta= rgba(1.0, 0.0, 1.0, 0.25);
  27.     for x in (x_min..=x_max).step_by(x_step) {
  28.         for y in (y_max..=y_min).step_by(y_step) {
  29.  
  30.             draw.ellipse()
  31.                 .x_y(x as f32, y as f32)
  32.                 .radius(radius )
  33.                 .stroke(color_yellow)
  34.                 .stroke_weight(stroke_w)
  35.                 .no_fill();
  36.        
  37.             draw.ellipse()
  38.                 .x_y(x as f32, y as f32)
  39.                 .radius(radius * 2.0 )
  40.                 .stroke(color_cyan)
  41.                 .stroke_weight(stroke_w)
  42.                 .no_fill();
  43.        
  44.             draw.ellipse()
  45.                 .x_y(x as f32, y as f32)
  46.                 .radius(radius * 4.0 )
  47.                 .stroke(color_magenta)
  48.                 .stroke_weight(stroke_w)
  49.                 .no_fill();
  50.             }
  51.     }
  52.     draw.to_frame(app, &frame).unwrap()
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement