Skip to main content

simple/
simple.rs

1extern crate egaku2d;
2
3use glutin::event::{Event, VirtualKeyCode, WindowEvent};
4use glutin::event_loop::ControlFlow;
5
6fn main() {
7    let events_loop = glutin::event_loop::EventLoop::new();
8    let mut sys = egaku2d::WindowedSystem::new([640, 480], &events_loop, "shapes example");
9
10    //Draw 60 frames per second.
11    let mut timer = egaku2d::RefreshTimer::new(16);
12
13    let mut cursor = [0.0; 2];
14    events_loop.run(move |event, _, control_flow| match event {
15        Event::WindowEvent { event, .. } => match event {
16            WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode {
17                Some(VirtualKeyCode::Escape) => {
18                    *control_flow = ControlFlow::Exit;
19                }
20                _ => {}
21            },
22            WindowEvent::CursorMoved {
23                device_id: _,
24                position: p,
25                ..
26            } => {
27                cursor = [p.x as f32, p.y as f32];
28            }
29            WindowEvent::CloseRequested => {
30                *control_flow = ControlFlow::Exit;
31            }
32            WindowEvent::Resized(_dim) => {}
33            _ => {}
34        },
35
36        Event::MainEventsCleared => {
37            if timer.is_ready() {
38                let canvas = sys.canvas_mut();
39
40                canvas.clear_color([0.2; 3]);
41
42                let mut circles = canvas.circles();
43
44                for x in (20..400).step_by(20) {
45                    for y in (20..400).step_by(20) {
46                        circles.add([
47                            cursor[0] + (x as f32) * (cursor[0] * 0.01),
48                            cursor[1] + y as f32,
49                        ]);
50                    }
51                }
52
53                circles
54                    .send_and_uniforms(canvas, 10.0)
55                    .with_color([1.0, 1.0, 1.0, 1.0])
56                    .draw();
57
58                //display what we drew
59                sys.swap_buffers();
60            }
61        }
62        _ => {}
63    });
64}