animated_triangle/
animated_triangle.rs1#[qqx::qqx(polygon)]
2struct Vertex {
3 #[mutable]
4 pos: qqx::Vec2 <f32>,
5 color: qqx::Color
6}
7
8fn main() {
9 let window = qqx::Window::new().build();
10
11 let mut triangle = qqx::Polygon::new().vertex(Vertex::new()
12 .pos(qqx::Vec2::new(-0.5, -0.5))
13 .color(qqx::Color::RED))
14 .vertex(Vertex::new()
15 .pos(qqx::Vec2::new(0.0, 0.5))
16 .color(qqx::Color::GREEN))
17 .vertex(Vertex::new()
18 .pos(qqx::Vec2::new(0.5, -0.25))
19 .color(qqx::Color::BLUE)
20 ).bind(window);
21
22 triangle.set_pos(qqx::Vec2::new(-0.5, 0.0));
23 qqx::callback::on_frame(move || {
24 triangle.r#move(qqx::Vec2::new(0.0002, 0.0));
25 if triangle.get_pos().x > 0.5 {
26 triangle.set_pos(qqx::Vec2::new(-0.5, 0.0));
27 }
28
29 window.draw()
30 .clear(qqx::Color::from(qqx::Vec4::new(0.0, 0.1, 1.0, 1.0)))
31 .draw(&triangle)
32 .finish();
33
34 qqx::ControlFlow::Poll
35 });
36
37 qqx::eventloop();
38}
39