mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-19 18:18:09 +08:00
Animation (#355)
This commit is contained in:
@@ -145,6 +145,77 @@ Color Color::HSV(uint8_t h, uint8_t s, uint8_t v) {
|
||||
return Color(0, 0, 0);
|
||||
}
|
||||
|
||||
// static
|
||||
Color Color::Interpolate(float t, const Color& a, const Color& b) {
|
||||
float red;
|
||||
float green;
|
||||
float blue;
|
||||
switch (a.type_) {
|
||||
case ColorType::Palette1: {
|
||||
if (t < 0.5)
|
||||
return a;
|
||||
else
|
||||
return b;
|
||||
}
|
||||
|
||||
case ColorType::Palette16: {
|
||||
ColorInfo info = GetColorInfo(Color::Palette16(a.index_));
|
||||
red = info.red * (1 - t);
|
||||
green = info.green * (1 - t);
|
||||
blue = info.blue * (1 - t);
|
||||
break;
|
||||
}
|
||||
|
||||
case ColorType::Palette256: {
|
||||
ColorInfo info = GetColorInfo(Color::Palette256(a.index_));
|
||||
red = info.red * (1 - t);
|
||||
green = info.green * (1 - t);
|
||||
blue = info.blue * (1 - t);
|
||||
break;
|
||||
}
|
||||
|
||||
case ColorType::TrueColor: {
|
||||
red = a.red_ * (1 - t);
|
||||
green = a.green_ * (1 - t);
|
||||
blue = a.blue_ * (1 - t);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (b.type_) {
|
||||
case ColorType::Palette1: {
|
||||
if (t > 0.5)
|
||||
return a;
|
||||
else
|
||||
return b;
|
||||
}
|
||||
|
||||
case ColorType::Palette16: {
|
||||
ColorInfo info = GetColorInfo(Color::Palette16(b.index_));
|
||||
red += info.red * t;
|
||||
green += info.green * t;
|
||||
blue += info.blue * t;
|
||||
break;
|
||||
}
|
||||
|
||||
case ColorType::Palette256: {
|
||||
ColorInfo info = GetColorInfo(Color::Palette256(b.index_));
|
||||
red += info.red * t;
|
||||
green += info.green * t;
|
||||
blue += info.blue * t;
|
||||
break;
|
||||
}
|
||||
|
||||
case ColorType::TrueColor: {
|
||||
red += b.red_ * t;
|
||||
green += b.green_ * t;
|
||||
blue += b.blue_ * t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Color::RGB(red, green, blue);
|
||||
}
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
Color operator""_rgb(unsigned long long int combined) {
|
||||
|
Reference in New Issue
Block a user