use piston_window::grid::Grid; use piston_window::*; use sdl2_window::Sdl2Window; pub const BLACK: [f32; 4] = [0.0, 0.0, 0.0, 0.8]; fn main() { let mut window: PistonWindow = WindowSettings::new("Hello there!", [1000, 1000]) .build() .expect("Could not initialise window"); let mut pixels_per_m = 64.; let grid_line = Line::new(BLACK, 1.5); let mut events = Events::new(EventSettings::new().lazy(true)); while let Some(e) = events.next(&mut window) { e.mouse_scroll(|[_, y]| { if y < 0. { pixels_per_m *= 1.2; } else if y > 0. { pixels_per_m /= 1.2; } }); if let Some(Button::Keyboard(Key::Escape)) = e.press_args() { window.set_should_close(true); } let win_size = window.draw_size(); let grid = Grid { cols: (win_size.width / pixels_per_m) as u32 + 1, rows: (win_size.height / pixels_per_m) as u32 + 1, units: pixels_per_m, }; window.draw_2d(&e, |c, g, _device| { clear([1.0; 4], g); grid.draw(&grid_line, &c.draw_state, c.transform, g); }); } }