From 6f12a83d67fa87b30c57bf531270029e22b1df2f Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 15 Feb 2023 01:05:55 -0500 Subject: [PATCH] Add color::lerp(). --- include/color.hpp | 2 ++ src/color.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/include/color.hpp b/include/color.hpp index b0f251ac..a32868f4 100644 --- a/include/color.hpp +++ b/include/color.hpp @@ -34,6 +34,8 @@ NVGcolor plus(NVGcolor a, NVGcolor b); /** Multiplies color components elementwise. */ NVGcolor mult(NVGcolor a, NVGcolor b); NVGcolor mult(NVGcolor a, float x); +/** Interpolates RGBA color values. */ +NVGcolor lerp(NVGcolor a, NVGcolor b, float t); /** Screen blending with alpha compositing */ NVGcolor screen(NVGcolor a, NVGcolor b); /** Multiplies alpha value. */ diff --git a/src/color.cpp b/src/color.cpp index e1e04122..3c90a756 100644 --- a/src/color.cpp +++ b/src/color.cpp @@ -44,6 +44,13 @@ NVGcolor mult(NVGcolor a, float x) { return a; } +NVGcolor lerp(NVGcolor a, NVGcolor b, float t) { + NVGcolor c; + for (int i = 0; i < 4; i++) + c.rgba[i] = a.rgba[i] * (1 - t) + b.rgba[i] * t; + return c; +} + /** Screen blending with alpha compositing */ NVGcolor screen(NVGcolor a, NVGcolor b) { if (a.a == 0.f)