<commit_before>extern crate nannou;

use nannou::prelude::*;

fn main() {
    nannou::view(view);
}

fn view(app: &App, frame: Frame) -> Frame {
    // Begin drawing 
    let draw = app.draw();

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

    let win = app.window_rect();
    let t = app.time;

    // Decide on a number of points and a thickness.
    let n_points = 10;
    let half_thickness = 4.0;
    let hz = ((app.mouse.x + win.right()) / win.w()).powi(4) * 1000.0;

    // Create an iterator for each point in the polyline.
    let points = (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)
        });

    // Get the miter vertices for the polyline and colour them.
    let vs = geom::line::join::miter::vertices(points, half_thickness)
        .enumerate()
        .flat_map(|(i, [nl, nr])| {
            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);
            Some(geom::vertex::Rgba(nr, rgba))
                .into_iter()
                .chain(Some(geom::vertex::Rgba(nl, rgba)))
        });

    // Get the indices for triangulating the polyline.
    let is = geom::line::join::miter::triangle_indices(n_points);

    // Draw the polyline using a mesh.
    draw.mesh().indexed(vs, is);

    // Write the result of our drawing to the window's OpenGL frame.
    draw.to_frame(app, &frame).unwrap();

    // Return the drawn frame.
    frame
}<commit_msg>Update simple_polyline example to use polyline draw API<commit_after>extern crate nannou;

use nannou::prelude::*;

fn main() {
    nannou::view(view);
}

fn view(app: &App, frame: Frame) -> Frame {
    // Begin drawing 
    let draw = app.draw();

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

    let win = app.window_rect();
    let t = app.time;

    // Decide on a number of points and a thickness.
    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)
        // A sine wave mapped to the range of the window.
        .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()
        // Colour each vertex uniquely based on its index.
        .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 the polyline.
    draw.polyline().vertices(half_thickness, vertices);

    // Write the result of our drawing to the window's OpenGL frame.
    draw.to_frame(app, &frame).unwrap();

    // Return the drawn frame.
    frame
}
{'fraction_non_alphanumeric': 0.15532286212914484, 'fraction_numerical': 0.025596276905177427, 'mean_word_length': 1.926808510638298, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6583404', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1190, 'n_words': 355}