Crates.io | minifb_geometry |
lib.rs | minifb_geometry |
version | 0.1.1 |
source | src |
created_at | 2024-04-23 13:26:28.753957 |
updated_at | 2024-05-08 17:54:49.663639 |
description | A crate meant to help draw shapes in the minifb window |
homepage | |
repository | https://github.com/HimaSava/rust_minifb_geometry.git |
max_upload_size | |
id | 1217576 |
size | 17,401 |
Addon crate for the minifb crate, that enables you to add basic geometric shapes into the minifb window.
Add this to your Cargo.toml
:
[dependencies]
minifb_geometry = "0.1"
use minifb::{Window, WindowOptions};
use minifb_geometry::GeometryDrawer;
const WIDTH: usize = 640;
const HEIGHT: usize = 360;
fn main() {
let mut buffer: Vec<u32> = vec![0; WIDTH * HEIGHT];
let geometry = GeometryDrawer::new(WIDTH);
let mut window = Window::new(
"minifb_geometry - ESC to exit",
WIDTH,
HEIGHT,
WindowOptions::default(),
)
.unwrap_or_else(|e| {
panic!("{}", e);
});
let _ = geometry.draw_box(&mut buffer, 120, 130, 220, 230, 0xffff00);
let _ = geometry.draw_circle(&mut buffer, 320, 180, 50, 0xffffff);
let _ = geometry.draw_rectangle(&mut buffer, 420, 130, 520, 230, 5, 0x00ff00);
let _ = geometry.draw_line(&mut buffer, 10, 10, WIDTH - 10, 10,0xff00ff);
let _ = geometry.draw_line(&mut buffer, 10, 10, 10, HEIGHT - 10,0xff00ff);
let _ = geometry.draw_line(&mut buffer, WIDTH - 10, 10, WIDTH - 10, HEIGHT - 10,0xff00ff);
let _ = geometry.draw_line(&mut buffer, 10, HEIGHT - 10, WIDTH - 10, HEIGHT - 10,0xff00ff);
while window.is_open() && !window.is_key_down(minifb::Key::Escape) {
window.update_with_buffer(&buffer, WIDTH, HEIGHT).unwrap();
}
}