interpolation/
interpolation.rs1use std::f32::consts::TAU;
2
3use sge::prelude::*;
4
5fn random_rect() -> Rect {
6 let sf = window_height().min(window_width());
7 let center: Vec2 = rand::<Vec2>() * sf;
8 let size: Vec2 = rand::<Vec2>() * sf;
9 let color = rand_choice(&Palette::PALETTES).v500;
10
11 Rect::from_center(center, size, color).with_rotation(rand::<f32>() * TAU)
12}
13
14#[main("Animation")]
15async fn main() -> anyhow::Result<()> {
16 let mut animation_controller =
17 AnimationController::new(random_rect(), random_rect(), 1.0, EaseOutElastic);
18
19 loop {
20 clear_screen(Color::hex(0x101013));
21
22 draw(&animation_controller.value());
23
24 if animation_controller.is_complete() {
25 animation_controller.now_animate_towards(random_rect());
26 }
27
28 if should_quit() {
29 break;
30 }
31
32 next_frame().await;
33 }
34
35 Ok(())
36}