Color interpolation effect

This commit is contained in:
Martin Bauer
2021-11-19 20:26:56 +01:00
parent 0bbb5d278c
commit da9a96fdfa
8 changed files with 215 additions and 10 deletions

View File

@@ -1,3 +1,5 @@
#pragma once
#include "helpers/ColorHSV.h"
#include "helpers/ColorRGBW.h"

View File

@@ -5,4 +5,42 @@
struct ColorHSV
{
float h, s, v;
};
};
inline ColorHSV operator*(const ColorHSV &c, float scalar)
{
return {scalar * c.h,
scalar * c.s,
scalar * c.v};
}
inline ColorHSV operator*(float scalar, const ColorHSV &c)
{
return {scalar * c.h,
scalar * c.s,
scalar * c.v};
}
inline ColorHSV operator+(const ColorHSV &c1, const ColorHSV &c2)
{
return {
c1.h + c2.h,
c1.s + c2.s,
c1.v + c2.v};
}
inline ColorHSV interpolate(const ColorHSV &c1, const ColorHSV &c2, float f)
{
return ColorHSV{
(1.0f - f) * c1.h + f * c2.h,
(1.0f - f) * c1.s + f * c2.s,
(1.0f - f) * c1.v + f * c2.v};
}
#ifndef PLATFORM_NATIVE
inline void print(const char *prefix, const ColorHSV &c)
{
Serial.printf("%s HSV(%f, %f, %f)\n", prefix, c.h, c.s, c.v);
}
#endif