add animation
This commit is contained in:
parent
58fb346b25
commit
ab4794fb59
26
src/main.rs
26
src/main.rs
|
|
@ -92,38 +92,54 @@ fn main() {
|
||||||
const OFF_SAT: f32 = R_SUN + R_SAT;
|
const OFF_SAT: f32 = R_SUN + R_SAT;
|
||||||
const R_SKY: f32 = R_SCALE * N_TEETH_SKY as f32;
|
const R_SKY: f32 = R_SCALE * N_TEETH_SKY as f32;
|
||||||
|
|
||||||
|
const FPS: f32 = 60.0;
|
||||||
|
const V_SUN: f32 = 2.0;
|
||||||
|
const V_SKY: f32 = -1.0;
|
||||||
|
|
||||||
|
const V_SAT: f32 = (V_SKY - V_SUN) / 2.0;
|
||||||
|
const V_ORBIT: f32 = (V_SUN + V_SKY) / 2.0;
|
||||||
|
|
||||||
|
const W_SUN: f32 = V_SUN / N_TEETH_SUN as f32;
|
||||||
|
const W_SKY: f32 = V_SKY / N_TEETH_SKY as f32;
|
||||||
|
const W_SAT: f32 = V_SAT / N_TEETH_SAT as f32;
|
||||||
|
const W_ORBIT: f32 = V_ORBIT / (N_TEETH_SUN + N_TEETH_SAT) as f32;
|
||||||
|
|
||||||
with_2d_graphics(|| {
|
with_2d_graphics(|| {
|
||||||
let sun = gear_shape(N_TEETH_SUN);
|
let sun = gear_shape(N_TEETH_SUN);
|
||||||
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, mut events) = create_drawing_window_with_events("Canvas window");
|
let (canvas, mut events) = create_drawing_window_with_events("Canvas window");
|
||||||
|
let mut frame = 0;
|
||||||
'main: loop {
|
'main: loop {
|
||||||
while let Poll::Ready(event) =
|
while let Poll::Ready(event) =
|
||||||
events.poll_next_unpin(&mut Context::from_waker(Waker::noop()))
|
events.poll_next_unpin(&mut Context::from_waker(Waker::noop()))
|
||||||
{
|
{
|
||||||
let Some(_event) = event else { break 'main };
|
let Some(_event) = event else { break 'main };
|
||||||
}
|
}
|
||||||
|
let t = frame as f32 / FPS;
|
||||||
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));
|
||||||
|
|
||||||
gc.canvas_height(100.0);
|
gc.canvas_height(100.0);
|
||||||
gc.line_width(0.25);
|
gc.line_width(0.25);
|
||||||
|
|
||||||
|
let m = Mat2::from_angle(t * W_SUN + 1.0 / N_TEETH_SUN as f32 * PI);
|
||||||
gc.new_path();
|
gc.new_path();
|
||||||
for pt in &sun {
|
for pt in &sun {
|
||||||
let pt = R_SUN * pt;
|
let pt = R_SUN * m * pt;
|
||||||
gc.line_to(pt.x, pt.y);
|
gc.line_to(pt.x, pt.y);
|
||||||
}
|
}
|
||||||
gc.close_path();
|
gc.close_path();
|
||||||
gc.stroke_color(Rgba(0.8, 0.7, 0.1, 1.0));
|
gc.stroke_color(Rgba(0.8, 0.7, 0.1, 1.0));
|
||||||
gc.stroke();
|
gc.stroke();
|
||||||
|
|
||||||
|
let mr = Mat2::from_angle(t * W_SAT);
|
||||||
for k in 0..N_SAT {
|
for k in 0..N_SAT {
|
||||||
let m = Mat2::from_angle(k as f32 / N_SAT as f32 * 2. * PI);
|
let mo = Mat2::from_angle(t * W_ORBIT + k as f32 / N_SAT as f32 * 2. * PI);
|
||||||
gc.new_path();
|
gc.new_path();
|
||||||
for pt in &sat {
|
for pt in &sat {
|
||||||
let pt = m * vec2(OFF_SAT, 0.) + R_SAT * pt;
|
let pt = mo * vec2(OFF_SAT, 0.) + R_SAT * mr * pt;
|
||||||
gc.line_to(pt.x, pt.y);
|
gc.line_to(pt.x, pt.y);
|
||||||
}
|
}
|
||||||
gc.close_path();
|
gc.close_path();
|
||||||
|
|
@ -131,15 +147,17 @@ fn main() {
|
||||||
gc.stroke();
|
gc.stroke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let m = Mat2::from_angle(t * W_SKY);
|
||||||
gc.new_path();
|
gc.new_path();
|
||||||
for pt in &crown {
|
for pt in &crown {
|
||||||
let pt = R_SKY * pt;
|
let pt = R_SKY * m * pt;
|
||||||
gc.line_to(pt.x, pt.y);
|
gc.line_to(pt.x, pt.y);
|
||||||
}
|
}
|
||||||
gc.close_path();
|
gc.close_path();
|
||||||
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();
|
||||||
});
|
});
|
||||||
|
frame += 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user