generic/
generic.rs

1use std::{
2    fmt::Display,
3    ops::{Add, Mul, Sub},
4};
5
6use kramaframe::{BTframelist, KramaFrame, keylist::TRES16Bits};
7
8#[derive(Clone, Copy)]
9struct Point {
10    x: f32,
11    y: f32,
12}
13
14impl Display for Point {
15    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16        write!(f, "({}, {})", self.x, self.y)
17    }
18}
19
20impl Add for Point {
21    type Output = Self;
22
23    fn add(self, other: Self) -> Self {
24        Point {
25            x: self.x + other.x,
26            y: self.y + other.y,
27        }
28    }
29}
30
31impl Sub for Point {
32    type Output = Self;
33
34    fn sub(self, other: Self) -> Self {
35        Point {
36            x: self.x - other.x,
37            y: self.y - other.y,
38        }
39    }
40}
41
42impl Mul<f32> for Point {
43    type Output = Self;
44
45    fn mul(self, scalar: f32) -> Self {
46        Point {
47            x: self.x * scalar,
48            y: self.y * scalar,
49        }
50    }
51}
52
53impl Point {
54    fn new(x: f32, y: f32) -> Self {
55        Point { x, y }
56    }
57}
58
59fn main() {
60    let mut animation_instance: KramaFrame<_, BTframelist<_, i16>> = KramaFrame::default();
61    animation_instance
62        .classlist
63        .insert("point", kramaframe::prelude::KeyFrameFunction::EaseIn);
64    animation_instance.insert_new_id("point", 1, TRES16Bits::from_millis(600));
65    animation_instance.restart_progress("point", 1);
66
67    for i in 0..=90 {
68        animation_instance.update_progress(TRES16Bits::from_millis(16));
69        let point_value = animation_instance.get_generic_value_by_rangeinclusive(
70            "point",
71            1,
72            Point::new(3.0, 4.0)..=Point::new(5.0, 6.0),
73        );
74        println!("Frame {} point position is {}", i, point_value)
75    }
76}