Vertex drawing

This commit is contained in:
2025-11-27 23:26:23 +01:00
parent 39d1306d93
commit 78a6cbf031
2 changed files with 123 additions and 28 deletions
+21 -28
View File
@@ -3,37 +3,30 @@ pub mod components;
use osmium::{renderer::Point, terminal};
fn main() {
let (term_width, term_height) = crossterm::terminal::size().unwrap();
let a = term_height - 3;
let engine = osmium::init();
let my_rect = engine.entity(|r| {
r.draw_rect(0, 0, 1, 2, 0xff0000);
r.draw_rect(1, 0, 1, 2, 0x00ff00);
r.draw_rect(2, 0, 1, 2, 0x0000ff);
});
engine.entity(|r| {
r.draw_vertex(
0,
0,
&[
Point { x: 0, y: 0 },
Point { x: 30, y: 0 },
Point { x: 15, y: 8 },
],
0x0000ff,
);
my_rect.component(components::Velocity(Point { x: 0, y: 0 }));
my_rect.component(components::ZigZag(term_width - 3));
my_rect.set_position(0, term_height - 3);
components::threads::tick(&engine);
components::threads::key(&engine);
engine.on_event({
let my_rect = my_rect.clone();
move |e: &crossterm::event::Event| {
if let Some(key_event) = e.as_key_event() {
match key_event.code {
crossterm::event::KeyCode::Char(' ') => {
my_rect.component(components::Jumping(0, a));
}
_ => {}
}
}
}
r.draw_vertex_outline(
0,
0,
&[
Point { x: 0, y: 0 },
Point { x: 30, y: 0 },
Point { x: 15, y: 8 },
],
0xff0000,
);
});
terminal::hide_cursor().unwrap();