Skip to content
Snippets Groups Projects
Commit 7f2adac0 authored by Legy (Beini)'s avatar Legy (Beini) Committed by Jens Nolte
Browse files

Add hsv function

parent 3fa69024
No related branches found
No related tags found
1 merge request!16Merge dev branch into master
......@@ -27,4 +27,45 @@ namespace qthing {
return RGB(h * v, 0, (1 - h) * v);
}
}
RGB hsv(float hue, float saturation, float value) {
if(value <= 0)
return RGB();
if(saturation <= 0)
return RGB(value, value, value);
if(saturation > 1)
saturation = 1;
if(value > 1)
value = 1;
hue = fmod(hue, 1);
if(hue < 0)
++hue;
float hh = hue * 6;
int i = (int)hh;
float ff = hh - i;
float p = value * (1.0 - saturation);
float q = value * (1.0 - (saturation * ff));
float t = value * (1.0 - (saturation * (1.0 - ff)));
switch(i) {
case(0):
return RGB(value, t, p);
case(1):
return RGB(q, value, p);
case(2):
return RGB(p, value, t);
case(3):
return RGB(p, q, value);
case(4):
return RGB(t, p, value);
case(5):
return RGB(value, p, q);
}
return RGB();
}
}
......@@ -228,6 +228,7 @@ namespace qthing {
};
RGB hue(const float hue, const float value = 1);
RGB hsv(float hue, float staturation = 1, float value = 1);
typedef std::function<led_color_t(uint8_t, uint16_t, led_color_t)> led_color_handler_t;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment