<commit_before>extern crate nannou;

use nannou::{App, Event, Frame, LoopMode, WindowEvent, WindowId, VirtualKeyCode, ElementState};

fn main() {
    nannou::run::<Model, Event>(model, update, draw);
}

struct Model {
    window: nannou::WindowId,
}

fn model(app: &App) -> Model {
    let window = app.new_window().build().unwrap();
    Model { window }
}

fn update(app: &App, model: Model, event: Event) -> Model {
    match event {
        Event::WindowEvent(id, event) => {
            println!("{:?}", event);
            window_event(app, model, id, event)
        },
        Event::Update(update) => {
            println!("{:?}", &update);
            model
        },
        _ => model,
    }
}

fn window_event(app: &App, model: Model, _id: WindowId, event: WindowEvent) -> Model {
    match event {
        WindowEvent::KeyboardInput { input, .. } => match input.state {
            ElementState::Pressed => match input.virtual_keycode {
                Some(VirtualKeyCode::Space) => {
                    match app.loop_mode() {
                        LoopMode::Rate { .. } => app.set_loop_mode(LoopMode::wait(3)),
                        LoopMode::Wait { .. } => app.set_loop_mode(LoopMode::rate_fps(60.0)),
                    }
                    println!("Switched LoopMode to: {:?}", app.loop_mode());
                },
                _ => (),
            },
            ElementState::Released => {},
        },
        _ => (),
    }
    model
}

// Draw the state of your `Model` into the given `Frame` here.
fn draw(_app: &App, model: &Model, frame: Frame) -> Frame {
    {
        // Our app only has one window, so retrieve this part of the `Frame`.
        let mut window_frame = frame.window(model.window).unwrap();
        // Paint it! (red, green, blue, alpha).
        window_frame.clear_color(1.0, 0.0, 0.0, 1.0);
    }
    // Return the drawn frame.
    frame
}
<commit_msg>Simplify loop_mode example a bit<commit_after>extern crate nannou;

use nannou::{App, Event, Frame, LoopMode, WindowEvent, WindowId, VirtualKeyCode as Key, ElementState};

fn main() {
    nannou::run(model, update, draw);
}

struct Model {
    window: nannou::WindowId,
}

fn model(app: &App) -> Model {
    app.set_loop_mode(LoopMode::wait(3));
    let window = app.new_window().build().unwrap();
    Model { window }
}

fn update(app: &App, model: Model, event: Event) -> Model {
    match event {
        Event::WindowEvent(id, event) => {
            println!("{:?}", event);
            match event {
                WindowEvent::KeyboardInput { input, .. } => {
                    if let (ElementState::Pressed, Some(_)) = (input.state, input.virtual_keycode) {
                        match app.loop_mode() {
                            LoopMode::Rate { .. } => app.set_loop_mode(LoopMode::wait(3)),
                            LoopMode::Wait { .. } => app.set_loop_mode(LoopMode::rate_fps(60.0)),
                        }
                    }
                },
                _ => (),
            }
        },
        Event::Update(update) => {
            println!("{:?}", &update);
        },
        _ => (),
    }
    model
}

// Draw the state of your `Model` into the given `Frame` here.
fn draw(_app: &App, model: &Model, frame: Frame) -> Frame {
    frame.window(model.window).unwrap().clear_color(0.1, 0.11, 0.12, 1.0);
    frame
}

{'fraction_non_alphanumeric': 0.1581450653983353, 'fraction_numerical': 0.00802615933412604, 'mean_word_length': 1.9388646288209608, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 29, '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': '771262', 'n_tokens_mistral': 1059, 'n_tokens_neox': 1025, 'n_words': 232}