1using System.Numerics;
2
3namespace Fjord.Graphics;
4
5public static class SampleAnimations {
6 public static Dictionary<string, CirlceAnimation> anims = new();
7
8 public static CirlceAnimation circlePulseAnimation = new CirlceAnimation()
9 .Radius((x) => {
10 float c1 = 1.70158f;
11 float c3 = c1 + 1;
12
13 return (1 + c3 * (float)Math.Pow(x - 1, 3) + c1 * (float)Math.Pow(x - 1, 2));
14 })
15 .Color((x) => {
16 float c1 = 1.70158f;
17 float c3 = c1 + 1;
18
19 return (1 + c3 * (float)Math.Pow(x - 1, 3) + c1 * (float)Math.Pow(x - 1, 2));
20 }, new(239, 17, 33, 255))
21 .Speed(2f);
22
23 public static CirlceAnimation CirclePulseAnimation(string id)
24 {
25 anims.TryAdd(id, (CirlceAnimation)circlePulseAnimation.Clone());
26
27 return anims[id];
28 }
29}
30
31public class CirlceAnimation : ICloneable {
32 public Func<float, float>? xDriver = null;
33 public Func<float, float>? yDriver = null;
34 public Func<float, float>? radiusDriver = null;
35 public Func<float, float>? colorDriver = null;
36 public Vector4 colorGoal = new();
37
38 public float progress = 0f;
39 public float speed = 0f;
40
41 public CirlceAnimation X(Func<float, float> callback)
42 {
43 this.xDriver = callback;
44 return this;
45 }
46
47 public CirlceAnimation Y(Func<float, float> callback)
48 {
49 this.yDriver = callback;
50 return this;
51 }
52
53 public CirlceAnimation Radius(Func<float, float> callback)
54 {
55 this.radiusDriver = callback;
56 return this;
57 }
58
59 public CirlceAnimation Color(Func<float, float> callback, Vector4 goal)
60 {
61 this.colorDriver = callback;
62 this.colorGoal = goal;
63 return this;
64 }
65
66 public CirlceAnimation Speed(float speed)
67 {
68 this.speed = speed;
69 return this;
70 }
71
72 public object Clone()
73 {
74 return this.MemberwiseClone();
75 }
76}