2个版本
0.1.1 | 2024年5月8日 |
---|---|
0.1.0 | 2024年4月23日 |
#375 in 数学
12KB
138 行
minifb_geometry
minifb crate的插件crate,允许你在minifb窗口中添加基本几何形状。
用法
将此添加到你的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();
}
}
许可证
- MIT许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)