repl.it
@candh/

HSI2RGB

C

No description

fork
loading
Files
  • main.c
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <math.h>

void HSI2RGB(double h, double s, double i, double* r, double* g, double* b)
{
	double x = i * (1 - s);		
	if(h < 2 * M_PI / 3)
	{
		// puts("h < ");
		double y = i * (1 + (s * cos(h)) / (cos(M_PI / 3 - h)));
		double z = 3 * i - (x + y);
		*b = x; *r = y; *g = z;
	}
	else if(h < 4 * M_PI / 3)
	{
		puts("ran");
		double y = i * (1 + (s * cos(h - 2 * M_PI / 3)) / (cos(M_PI / 3 - (h  - 2 * M_PI / 3))));
		double z = 3 * i - (x + y);
		*r = x; *g = y; *b = z;
	}
	else
	{

		double y = i * (1 + (s * cos(h - 4 * M_PI / 3)) / (cos(M_PI / 3 - (h  - 4 * M_PI / 3))));
		double z = 3 * i - (x + y);
		*r = z; *g = x; *b = y;
	}
}

int main(void) {
  printf("Hello World\n");
	double r, g, b;
	HSI2RGB(0.33333, 1, 0.5, &r, &g, &b);
	printf("%f %f %f\n", r, g, b);
  return 0;
}
Fetching token
?