21 #include "hx3d/graphics/color.hpp" 28 static float outBounce(
float t) {
30 (t < 0.3636) ? 7.5625 * t * t:
31 (t < 0.7272) ? 7.5625 * (t - 0.5454) * (t - 0.5454) + 0.75:
32 (t < 0.9090) ? 7.5625 * (t - 0.8181) * (t - 0.8181) + 0.9375:
33 7.5625 * (t - 0.9545) * (t - 0.9545) + 0.984375;
36 static float inExpo(
float t) {
37 return std::pow(2, 10 * (t-1));
40 static float inCirc(
float t) {
41 return -(std::sqrt(1 - t*t) - 1);
44 static float inBack(
float t) {
45 return t*t * (3*t - 2);
48 static float inElastic(
float t) {
49 return (t == 0 || t == 1) ? t :
50 -std::pow(2, 8 * (t-1)) * std::sin(((t-1) * 80 - 7.5) *
math::PI / 15);
57 case Interpolation::InQuad:
60 case Interpolation::OutQuad:
63 case Interpolation::InOutQuad:
64 t = (t < 0.5f) ? 2 * t * t : -1 + (4-2*t)*t;
67 case Interpolation::InCubic:
70 case Interpolation::OutCubic:
71 t = (t-1) * (t-1) * (t-1) + 1;
73 case Interpolation::InOutCubic:
74 t = (t < 0.5f) ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1;
77 case Interpolation::InQuart:
80 case Interpolation::OutQuart:
81 t = 1 - (t-1) * (t-1) * (t-1) * (t-1);
83 case Interpolation::InOutQuart:
84 t = (t < 0.5f) ? 8*t*t*t*t : 1 - 8*(t-1)*(t-1)*(t-1)*(t-1);
87 case Interpolation::InQuint:
90 case Interpolation::OutQuint:
91 t = 1 + (t-1) * (t-1) * (t-1) * (t-1) * (t-1);
93 case Interpolation::InOutQuint:
94 t = (t < 0.5f) ? 16*t*t*t*t*t : 1 + 16*(t-1)*(t-1)*(t-1)*(t-1)*(t-1);
97 case Interpolation::InSine:
98 t = -1 * std::cos(t * (
math::PI / 2)) + 1;
100 case Interpolation::OutSine:
103 case Interpolation::InOutSine:
104 t = (std::cos(t *
math::PI) - 1) / -2;
107 case Interpolation::InExpo:
110 case Interpolation::OutExpo:
111 t = 1 - inExpo(1 - t);
113 case Interpolation::InOutExpo:
116 1 - inExpo(t * -2 + 2) / 2;
119 case Interpolation::InCirc:
122 case Interpolation::OutCirc:
123 t = 1 - inCirc(1 - t);
125 case Interpolation::InOutCirc:
128 1 - inCirc(t * -2 + 2) / 2;
131 case Interpolation::InBack:
134 case Interpolation::OutBack:
135 t = 1 - inBack(1 - t);
137 case Interpolation::InOutBack:
140 1 - inBack(t * -2 + 2) / 2;
143 case Interpolation::InBounce:
144 t = 1 - outBounce(1 - t);
146 case Interpolation::OutBounce:
149 case Interpolation::InOutBounce:
152 (1 - outBounce(1 - t*2)) * 0.5:
153 outBounce(t * 2 - 1) * 0.5 + 1 * 0.5;
156 case Interpolation::InElastic:
159 case Interpolation::OutElastic:
160 t = 1 - inElastic(1 - t);
162 case Interpolation::InOutElastic:
164 inElastic(t * 2) / 2 :
165 1 - inElastic(t * -2 + 2) / 2;
168 case Interpolation::Linear:
173 return a + t*(b - a);
178 Color ca = Color::rgbToHsv(a);
179 Color cb = Color::rgbToHsv(b);
186 return Color::hsvToRgb(
final);
unsigned char g
Green component.
Four [0..255] components defined color.
T interpolate(T a, T b, float t, Interpolation type)
Interpolate between two values.
Interpolation
Interpolate using functions.
unsigned char b
Blue component.
unsigned char r
Red component.