now with the main loop

This commit is contained in:
numzero 2025-09-06 03:36:19 +03:00
parent 9d4c61d7ec
commit 58fb346b25
3 changed files with 45 additions and 31 deletions

1
Cargo.lock generated
View File

@ -885,6 +885,7 @@ name = "gears"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"flo_draw", "flo_draw",
"futures",
"glam", "glam",
] ]

View File

@ -5,4 +5,5 @@ edition = "2024"
[dependencies] [dependencies]
flo_draw = "0.3.1" flo_draw = "0.3.1"
futures = "0.3.31"
glam = "0.30.5" glam = "0.30.5"

View File

@ -1,9 +1,14 @@
use std::f32::consts::PI; use std::{
f32::consts::PI,
pin::pin,
task::{Context, Poll, Waker},
};
use flo_draw::{ use flo_draw::{
canvas::{Color::Rgba, GraphicsContext, GraphicsPrimitives}, canvas::{Color::Rgba, GraphicsContext, GraphicsPrimitives},
create_drawing_window, with_2d_graphics, create_drawing_window, create_drawing_window_with_events, with_2d_graphics,
}; };
use futures::{StreamExt, executor, pin_mut};
use glam::{FloatExt, Mat2, Vec2, vec2}; use glam::{FloatExt, Mat2, Vec2, vec2};
const fn rad(deg: f32) -> f32 { const fn rad(deg: f32) -> f32 {
@ -92,7 +97,13 @@ fn main() {
let sat = gear_shape(N_TEETH_SAT); let sat = gear_shape(N_TEETH_SAT);
let crown = gear_shape_outer(N_TEETH_SKY); let crown = gear_shape_outer(N_TEETH_SKY);
let canvas = create_drawing_window("Canvas window"); let (canvas, mut events) = create_drawing_window_with_events("Canvas window");
'main: loop {
while let Poll::Ready(event) =
events.poll_next_unpin(&mut Context::from_waker(Waker::noop()))
{
let Some(_event) = event else { break 'main };
}
canvas.draw(|gc| { canvas.draw(|gc| {
gc.clear_canvas(Rgba(0.1, 0.1, 0.1, 1.0)); gc.clear_canvas(Rgba(0.1, 0.1, 0.1, 1.0));
@ -100,7 +111,7 @@ fn main() {
gc.line_width(0.25); gc.line_width(0.25);
gc.new_path(); gc.new_path();
for pt in sun { for pt in &sun {
let pt = R_SUN * pt; let pt = R_SUN * pt;
gc.line_to(pt.x, pt.y); gc.line_to(pt.x, pt.y);
} }
@ -121,7 +132,7 @@ fn main() {
} }
gc.new_path(); gc.new_path();
for pt in crown { for pt in &crown {
let pt = R_SKY * pt; let pt = R_SKY * pt;
gc.line_to(pt.x, pt.y); gc.line_to(pt.x, pt.y);
} }
@ -129,5 +140,6 @@ fn main() {
gc.stroke_color(Rgba(0.1, 0.4, 0.8, 1.0)); gc.stroke_color(Rgba(0.1, 0.4, 0.8, 1.0));
gc.stroke(); gc.stroke();
}); });
}
}); });
} }