Nannou-如何画馅饼(椭圆的一部分)?

发布于 2025-02-09 05:19:57 字数 430 浏览 3 评论 0 原文

我是Rust Library Nannou的新手,我正在尝试绘制饼图。 我知道在JavaScript中,您可以通过以下方式指定椭圆的数量:

ctx.ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise);

但是我找不到Nannou中的类似的东西:

draw.ellipse().angle(PI);

I'm new to the rust library Nannou and I'm trying to draw pie chart.
I know that in javascript you can specify the amount of the ellipse via:

ctx.ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise);

I couldn't however find anything similar in Nannou like:

draw.ellipse().angle(PI);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

数理化全能战士 2025-02-16 05:19:57

nannou :: :椭圆::椭圆 不支持各节。

但是,您可以使用 > 来自

这是一个简单的例子:

use nannou::{
    geom::{Ellipse, Tri},
    prelude::*,
};

fn main() {
    nannou::sketch(view).run()
}

fn view(app: &App, frame: Frame) {
    let draw = app.draw();
    let win = app.window_rect();

    draw.background().color(CORNFLOWERBLUE);

    let t = app.time;

    let radius = if win.h() < win.w() {
        win.w() / 3f32
    } else {
        win.h() / 3f32
    };

    let section = Ellipse::new(Rect::from_x_y_w_h(0f32, 0f32, radius, radius), 120f32)
        .section(0f32, t.sin() * 2f32 * std::f32::consts::PI);

    let triangles = section.trangles();
    let mut tris = Vec::new();
    for t in triangles {
        tris.push(Tri([
            [t.0[0][0], t.0[0][1], 0f32],
            [t.0[1][0], t.0[1][1], 0f32],
            [t.0[2][0], t.0[2][1], 0f32],
        ]));
    }

    draw.mesh().tris(tris.into_iter()).color(RED);

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

The nannou::draw::primitive::ellipse::Ellipse does not support sections.

However you can use the Section from nannou::geom::Ellipse.

Here is a simple example:

use nannou::{
    geom::{Ellipse, Tri},
    prelude::*,
};

fn main() {
    nannou::sketch(view).run()
}

fn view(app: &App, frame: Frame) {
    let draw = app.draw();
    let win = app.window_rect();

    draw.background().color(CORNFLOWERBLUE);

    let t = app.time;

    let radius = if win.h() < win.w() {
        win.w() / 3f32
    } else {
        win.h() / 3f32
    };

    let section = Ellipse::new(Rect::from_x_y_w_h(0f32, 0f32, radius, radius), 120f32)
        .section(0f32, t.sin() * 2f32 * std::f32::consts::PI);

    let triangles = section.trangles();
    let mut tris = Vec::new();
    for t in triangles {
        tris.push(Tri([
            [t.0[0][0], t.0[0][1], 0f32],
            [t.0[1][0], t.0[1][1], 0f32],
            [t.0[2][0], t.0[2][1], 0f32],
        ]));
    }

    draw.mesh().tris(tris.into_iter()).color(RED);

    draw.to_frame(app, &frame).unwrap();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文