From 03190334f314d0fc2a2fb4d9eddf73f492b6532e Mon Sep 17 00:00:00 2001 From: Julian Lohuis Date: Tue, 8 Feb 2022 17:14:38 +0100 Subject: [PATCH] PixelLerp for multiple colours --- olcPixelGameEngine.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/olcPixelGameEngine.h b/olcPixelGameEngine.h index fd077c4..f0ab6a0 100644 --- a/olcPixelGameEngine.h +++ b/olcPixelGameEngine.h @@ -195,7 +195,7 @@ Author ~~~~~~ - David Barr, aka javidx9, ©OneLoneCoder 2018, 2019, 2020, 2021, 2022 + David Barr, aka javidx9, ©OneLoneCoder 2018, 2019, 2020, 2021, 2022 */ #pragma endregion @@ -548,7 +548,16 @@ namespace olc Pixel PixelF(float red, float green, float blue, float alpha = 1.0f); Pixel PixelLerp(const olc::Pixel& p1, const olc::Pixel& p2, float t); + template + Pixel PixelLerp(float t, const Args& ...args) + { + std::array pixels{args...}; + const auto numint = pixels.size() - 1; + const auto idxint = static_cast(t * numint); + const auto tout = (t - (idxint/numint)) * numint - idxint; + return PixelLerp(pixels.at(idxint), pixels.at(idxint+1), tout); + } // O------------------------------------------------------------------------------O // | USEFUL CONSTANTS |