3 个版本 (破坏性更新)
0.4.0 | 2021 年 5 月 7 日 |
---|---|
0.3.0 | 2019 年 12 月 21 日 |
0.2.0 | 2019 年 6 月 6 日 |
0.1.3 |
|
0.1.2 |
|
#632 in 图像
每月 21 次下载
37KB
858 代码行
桃子
Processing 风格的 Rust 沙盒库,使用 wgpu。
示例
请参阅 示例文件夹 以获取更多代码片段,以及(最终)屏幕截图。
use peach::prelude::*;
fn main() {
let settings = Settings {
title: Some("Example Sketch"),
size: [512.0, 512.0].into(),
framerate: None,
exit_key: Some(Key::Escape),
..Default::default()
};
peach::run::<Example>(settings).unwrap();
}
#[derive(Default)]
struct Example;
impl Handler for Example {
fn setup(sketch: &mut Sketch) -> Self {
sketch.set_clear_color(Color::new(1.0, 1.0, 1.0, 1.0));
Self::default()
}
#[rustfmt::skip]
fn draw(&mut self, sketch: &mut Sketch, gfx: &mut Graphics) {
gfx.fill(Color {
r: 1.0,
g: 0.33,
b: 0.66,
a: 1.0,
});
let t = sketch.get_time_since_start().as_secs_scalar();
let x = 1.5 * t.cos();
let y = (2.0 * t).sin();
let size = Point::from(sketch.get_size().to_tuple());
let center = sketch.get_center();
let pos = center.to_vector() + Vector::new(x, y) * 100.0;
gfx.stroke(colors::BLACK);
gfx.stroke_weight(2.0);
gfx.square(sketch.get_mouse_position(), 20.0);
gfx.save();
gfx.stroke(colors::BLUE);
gfx.anchor_mode(AnchorMode::Center);
gfx.rotate(Angle::radians(x * PI));
gfx.translate(pos);
gfx.square(Point::zero(), 10.0 + 20.0 * x.abs());
gfx.restore();
gfx.fill(colors::BLUE);
gfx.square( size - sketch.get_mouse_position().to_vector(), 20.0);
}
}
依赖项
~9–23MB
~365K SLoC