now with the main loop
This commit is contained in:
parent
9d4c61d7ec
commit
58fb346b25
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -885,6 +885,7 @@ name = "gears"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"flo_draw",
|
||||
"futures",
|
||||
"glam",
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -5,4 +5,5 @@ edition = "2024"
|
|||
|
||||
[dependencies]
|
||||
flo_draw = "0.3.1"
|
||||
futures = "0.3.31"
|
||||
glam = "0.30.5"
|
||||
|
|
|
|||
74
src/main.rs
74
src/main.rs
|
|
@ -1,9 +1,14 @@
|
|||
use std::f32::consts::PI;
|
||||
use std::{
|
||||
f32::consts::PI,
|
||||
pin::pin,
|
||||
task::{Context, Poll, Waker},
|
||||
};
|
||||
|
||||
use flo_draw::{
|
||||
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};
|
||||
|
||||
const fn rad(deg: f32) -> f32 {
|
||||
|
|
@ -92,42 +97,49 @@ fn main() {
|
|||
let sat = gear_shape(N_TEETH_SAT);
|
||||
let crown = gear_shape_outer(N_TEETH_SKY);
|
||||
|
||||
let canvas = create_drawing_window("Canvas window");
|
||||
canvas.draw(|gc| {
|
||||
gc.clear_canvas(Rgba(0.1, 0.1, 0.1, 1.0));
|
||||
|
||||
gc.canvas_height(100.0);
|
||||
gc.line_width(0.25);
|
||||
|
||||
gc.new_path();
|
||||
for pt in sun {
|
||||
let pt = R_SUN * pt;
|
||||
gc.line_to(pt.x, pt.y);
|
||||
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 };
|
||||
}
|
||||
gc.close_path();
|
||||
gc.stroke_color(Rgba(0.8, 0.7, 0.1, 1.0));
|
||||
gc.stroke();
|
||||
canvas.draw(|gc| {
|
||||
gc.clear_canvas(Rgba(0.1, 0.1, 0.1, 1.0));
|
||||
|
||||
gc.canvas_height(100.0);
|
||||
gc.line_width(0.25);
|
||||
|
||||
for k in 0..N_SAT {
|
||||
let m = Mat2::from_angle(k as f32 / N_SAT as f32 * 2. * PI);
|
||||
gc.new_path();
|
||||
for pt in &sat {
|
||||
let pt = m * vec2(OFF_SAT, 0.) + R_SAT * pt;
|
||||
for pt in &sun {
|
||||
let pt = R_SUN * pt;
|
||||
gc.line_to(pt.x, pt.y);
|
||||
}
|
||||
gc.close_path();
|
||||
gc.stroke_color(Rgba(0.1, 0.8, 0.1, 1.0));
|
||||
gc.stroke_color(Rgba(0.8, 0.7, 0.1, 1.0));
|
||||
gc.stroke();
|
||||
}
|
||||
|
||||
gc.new_path();
|
||||
for pt in crown {
|
||||
let pt = R_SKY * pt;
|
||||
gc.line_to(pt.x, pt.y);
|
||||
}
|
||||
gc.close_path();
|
||||
gc.stroke_color(Rgba(0.1, 0.4, 0.8, 1.0));
|
||||
gc.stroke();
|
||||
});
|
||||
for k in 0..N_SAT {
|
||||
let m = Mat2::from_angle(k as f32 / N_SAT as f32 * 2. * PI);
|
||||
gc.new_path();
|
||||
for pt in &sat {
|
||||
let pt = m * vec2(OFF_SAT, 0.) + R_SAT * pt;
|
||||
gc.line_to(pt.x, pt.y);
|
||||
}
|
||||
gc.close_path();
|
||||
gc.stroke_color(Rgba(0.1, 0.8, 0.1, 1.0));
|
||||
gc.stroke();
|
||||
}
|
||||
|
||||
gc.new_path();
|
||||
for pt in &crown {
|
||||
let pt = R_SKY * pt;
|
||||
gc.line_to(pt.x, pt.y);
|
||||
}
|
||||
gc.close_path();
|
||||
gc.stroke_color(Rgba(0.1, 0.4, 0.8, 1.0));
|
||||
gc.stroke();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user