use nannou::prelude::*;
fn main() {
nannou::sketch(view);
}
fn view(app: &App, frame: Frame) -> Frame {
let draw = app.draw();
draw.background().color(BLACK);
let win = app.window_rect();
let t = app.time;
let n_points = 10;
let half_thickness = 4.0;
let hz = ((app.mouse.x + win.right()) / win.w()).powi(4) * 1000.0;
let vertices = (0..n_points)
.map(|i| {
let x = map_range(i, 0, n_points - 1, win.left(), win.right());
let fract = i as f32 / n_points as f32;
let amp = (t + fract * hz * TAU).sin();
let y = map_range(amp, -1.0, 1.0, win.bottom() * 0.75, win.top() * 0.75);
pt2(x, y)
})
.enumerate()
.map(|(i, p)| {
let fract = i as f32 / n_points as f32;
let r = (t + fract) % 1.0;
let g = (t + 1.0 - fract) % 1.0;
let b = (t + 0.5 + fract) % 1.0;
let rgba = nannou::color::Rgba::new(r, g, b, 1.0);
geom::vertex::Rgba(p, rgba)
});
draw.polyline().vertices(half_thickness, vertices);
draw.to_frame(app, &frame).unwrap();
frame
}