minifb_geometry

Crates.iominifb_geometry
lib.rsminifb_geometry
version0.1.1
sourcesrc
created_at2024-04-23 13:26:28.753957
updated_at2024-05-08 17:54:49.663639
descriptionA crate meant to help draw shapes in the minifb window
homepage
repositoryhttps://github.com/HimaSava/rust_minifb_geometry.git
max_upload_size
id1217576
size17,401
Himanshu Savargaonkar (HimaSava)

documentation

README

minifb_geometry

Addon crate for the minifb crate, that enables you to add basic geometric shapes into the minifb window.

Example

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

Commit count: 15

cargo fmt