Core: Lerp(Color)

This commit is contained in:
Mirek Fidler 2024-12-09 09:06:15 +01:00
parent ce5ee8f82f
commit d29b51dfd9
3 changed files with 15 additions and 1 deletions

View file

@ -6,13 +6,17 @@ using namespace Upp;
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT);
StdLogSetup(LOG_COUT|LOG_FILE);
DUMP(Lerp(10, 20, 0.5));
DUMP(Lerp(10.0, 20.0, 0.25));
DUMP(Lerp(Point(10, 20), Point(30, 40), 0.5));
DUMP(Lerp(Size(100, 200), Size(300, 400), 0.5));
DUMP(Lerp(Rect(0, 0, 100, 100), Rect(100, 100, 200, 200), 0.5));
DUMP(Lerp(Color(100, 200, 150), Color(200, 100, 120), 0.5));
DUMP(Lerp(Color(100, 200, 150), Color(200, 100, 120), 1.5));
DUMP(Lerp(Color(100, 200, 150), Color(200, 100, 120), -1));
}

View file

@ -307,6 +307,14 @@ Color Blend(Color c1, Color c2, int alpha)
min(((a * (c2.GetB() - c1.GetB())) >> 8) + c1.GetB(), 255));
}
Color Lerp(Color a, Color b, double t)
{
auto Ch = [&](byte a, byte b) {
return (byte)clamp(Lerp((double)a, (double)b, t), 0., 255.);
};
return Color(Ch(a.GetR(), b.GetR()), Ch(a.GetG(), b.GetG()), Ch(a.GetB(), b.GetB()));
}
INITBLOCK {
Value::SvoRegister<Color>("Color");
}

View file

@ -166,6 +166,8 @@ double ContrastRatio(Color c1, Color c2);
Color Blend(Color c1, Color c2, int alpha = 128);
Color Lerp(Color a, Color b, double t);
String ColorToHtml(Color color);
Color ColorFromText(const char *s);