Created
September 13, 2015 09:36
-
-
Save rikusalminen/270223cc996dc2d483c4 to your computer and use it in GitHub Desktop.
HSV to RGB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
void hsv2rgb(float h, float s, float v, float *rgb) { | |
float c = v * s; | |
float hh = h * 6.0; | |
float x = c * (1.0 - fabsf(fmodf(hh, 2) - 1.)); | |
float m = v - c; | |
int i = (int)hh % 6; | |
rgb[(1 + 2*i)%3] = x + m; | |
rgb[((i+1)/2)%3] = c + m; | |
rgb[(2+(i/2))%3] = 0.0 + m; | |
} | |
#include <stdio.h> | |
int main() { | |
int steps = 24; | |
for(int i = 0; i <= steps; ++i) { | |
float h = i / (float)steps; | |
float rgb[3]; | |
hsv2rgb(h, 1.0, 1.0, rgb); | |
printf("%d\t%2.2f\t%2.2f\t%2.2f\n", i*(360/steps), rgb[0], rgb[1], rgb[2]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment