nannou-org / nannou

A Creative Coding Framework for Rust.
https://nannou.cc/
6.03k stars 304 forks source link

Ellipse is calculating the stroke tolerance using the draw 'size' rather than the pixel size #857

Open cianoc opened 2 years ago

cianoc commented 2 years ago
use nannou::{prelude::*, lyon::{geom::euclid::num::Round, lyon_tessellation::LineCap}};
use nannou::rand::rngs::StdRng;
use nannou::rand::{Rng, SeedableRng};

fn main() {
    println!("{}", vec2(3.0, 3.0)/vec2(2.0, 4.0));
    nannou::sketch(view).run();
}

struct Model{
    act_random_seed: u64,
    stroke_cap: LineCap,
    mouse_pos: Point2,
}

fn view(app: &App, frame: Frame){
    let mut draw = app.draw();
    draw = draw.scale_axes((app.window_rect().wh()).extend(1.0));
    draw.background().color(WHITE);

    draw.ellipse().wh(vec2(1.0, 1.0)).no_fill().stroke_weight(0.1).stroke_color(BLACK);

    draw.to_frame(app, &frame).unwrap();
}

This code produces a hexagon rather than a circle.

cianoc commented 2 years ago

The reason for this is that I've changed the draw coordinates so that that they extend from -1.0 to +1.0 in both directions.