Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polyline flashing with weird shapes #281

Closed
tqwewe opened this issue Mar 20, 2019 · 1 comment · Fixed by #375
Closed

Polyline flashing with weird shapes #281

tqwewe opened this issue Mar 20, 2019 · 1 comment · Fixed by #375

Comments

@tqwewe
Copy link

tqwewe commented Mar 20, 2019

I am trying to learn nannou, and I attempted to make a line that follows the y position of your mouse.

The line flickers as seen in the gif below:

Flicker

I came up with the following source code:

extern crate nannou;

use nannou::prelude::*;

fn main() {
    nannou::run(model, event, view);
}

struct Model {
    y_positions: Vec<f32>,
}

fn model(app: &App) -> Model {
    // Start in `Wait` mode. In other words, don't keep looping, just wait for events.
    app.set_loop_mode(LoopMode::rate_fps(60.0));
    // Set a window title.
    app.main_window().set_title("`LoopMode` Demonstration");
    Model {
        y_positions: Vec::new(),
    }
}

fn event(app: &App, mut model: Model, event: Event) -> Model {
    match event {
        Event::Update(update) => {
            model.y_positions.push(app.mouse.y);
            if model.y_positions.len() > 300 / 5 {
                model.y_positions.remove(0);
            }
        }
        _ => (),
    }
    model
}

// Draw the state of your `Model` into the given `Frame` here.
fn view(app: &App, model: &Model, frame: Frame) -> Frame {
    let window = app.window_rect();
    let draw = app.draw();

    draw.background().color(BLUE);

    if model.y_positions.len() > 1 {
        let half_thickness = 0.5;
        let vertices = (0..model.y_positions.len())
            .map(|i| pt2(((i as f32) * 5.0) - window.w() / 2.0, model.y_positions[i]))
            .enumerate()
            .map(|(i, p)| {
                let r = 1.0;
                let g = 0.0;
                let b = 0.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
}

Is this something I am doing wrong, or a bug with nannou?

@mitchmindtree
Copy link
Member

mitchmindtree commented Mar 21, 2019

Hey @acidic9 thanks for the issue!

You are doing nothing wrong at all, this is entirely nannou's fault! We're aware of this bug #185 however rather than spending time on fixing it, we have a plan to switch to using the lyon crate under the hood to solve this and a whole suite of other issues related to 2D graphics. Lyon is an extremely impressive crate with high quality tools for tesselating all kinds of 2D geometry like curves, lines with interesting joins, etc including support for GPU tesselation. See #253. This will be a top priority for us after we land 0.9 in the coming weeks (see #240).

I hope this helps and that this isn't causing you too many problems!

mitchmindtree added a commit to mitchmindtree/nannou that referenced this issue Aug 3, 2019
This is a working WIP that replaces the old polyline implementation with
lyon's polyline tessellation.

The following commits will continue to replace the tessellation
approaches of all 2D shapes in favour of lyon tessellation.

Closes nannou-org#185.
Closes nannou-org#281.
Closes nannou-org#335.
mitchmindtree added a commit to mitchmindtree/nannou that referenced this issue Aug 6, 2019
This is a working WIP that replaces the old polyline implementation with
lyon's polyline tessellation.

The following commits will continue to replace the tessellation
approaches of all 2D shapes in favour of lyon tessellation.

Closes nannou-org#185.
Closes nannou-org#281.
Closes nannou-org#335.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants