2 releases
0.1.1 | May 8, 2024 |
---|---|
0.1.0 | Apr 23, 2024 |
#561 in Math
64 downloads per month
12KB
138 lines
minifb_geometry
Addon crate for the minifb crate, that enables you to add basic geometric shapes into the minifb window.
Usage
Add this to your Cargo.toml
:
[dependencies]
minifb_geometry = "0.1"
Example
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();
}
}
License
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)