egui_map/map/
animation.rs

1use crate::map::{objects::RawPoint, Error};
2use egui::{epaint::CircleShape, Color32, Painter, Shape};
3use std::time::Instant;
4
5pub(crate) struct Animation {}
6
7impl Animation {
8    pub(crate) fn pulse(
9        painter: &Painter,
10        center: RawPoint,
11        zoom: f32,
12        initial_time: Instant,
13        color: Color32,
14    ) -> Result<bool, Error> {
15        let current_instant = Instant::now();
16        let mut result = false;
17        let time_diff = current_instant.duration_since(initial_time);
18        let secs_played = time_diff.as_secs_f32();
19        let radius = (4.00 + (40.00 * secs_played)) * zoom;
20        let mut transparency = 1.00 - (secs_played / 3.50).abs();
21        if transparency < 0.00 {
22            transparency = 0.00;
23        }
24        let corrected_color = Color32::from_rgba_unmultiplied(
25            color.r(),
26            color.g(),
27            color.b(),
28            (255.00 * transparency).round() as u8,
29        );
30        let circle = Shape::Circle(CircleShape::filled(center.into(), radius, corrected_color));
31        painter.extend(vec![circle]);
32        if secs_played < 3.50 {
33            result = true;
34        }
35        Ok(result)
36    }
37}