Piston 的图形库提供了在两点之间画一条线的功能,但最多只能画两条线。如何有效地绘制通过许多点的路径,而不必为每个段绘制一条线?
假设我有以下代码:
extern crate piston_window;
use piston_window::*;
fn main() {
let mut window: PistonWindow = WindowSettings::new("Hello Piston!", [640, 480])
.exit_on_esc(true).build().unwrap();
while let Some(e) = window.next() {
window.draw_2d(&e, |c, g| {
clear([1.0; 4], g);
let points = [
[100., 100.],
[200., 200.],
[150., 350.],
//...
];
let mut prev = points[0];
for pt in points[1..].iter() {
line([0., 0., 0., 255.], 1., [
prev[0], prev[1], pt[0], pt[1]
], c.transform, g);
prev = *pt;
}
});
}
}
有没有办法把它变成这样的东西?
extern crate piston_window;
use piston_window::*;
fn main() {
let mut window: PistonWindow = WindowSettings::new("Hello Piston!", [640, 480])
.exit_on_esc(true).build().unwrap();
while let Some(e) = window.next() {
window.draw_2d(&e, |c, g| {
clear([1.0; 4], g);
let points = [
[100., 100.],
[200., 200.],
[150., 350.],
//...
];
path([0., 0., 0., 255.], 1., &points, c.transform, g);
});
}
}
我被推荐到里昂图书馆,但我不知道如何将它与活塞一起使用。