PixelLerp for multiple colours

pull/272/head
Julian Lohuis 3 years ago
parent dbeabb8ffc
commit 03190334f3
  1. 11
      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<typename ...Args>
Pixel PixelLerp(float t, const Args& ...args)
{
std::array<Pixel, sizeof...(args)> pixels{args...};
const auto numint = pixels.size() - 1;
const auto idxint = static_cast<int>(t * numint);
const auto tout = (t - (idxint/numint)) * numint - idxint;
return PixelLerp(pixels.at(idxint), pixels.at(idxint+1), tout);
}
// O------------------------------------------------------------------------------O
// | USEFUL CONSTANTS |

Loading…
Cancel
Save