summaryrefslogtreecommitdiff
path: root/examples/include/colors.h
blob: abf137c28cf2e257d4ce7cc9c6349e93e7feb3c4 (plain)
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
#pragma once

#include <wolff/types.h>

double hue_to_R(double theta) {
  if (((M_PI / 3 <= theta) && (theta < 2 * M_PI / 3)) || ((4 * M_PI / 3 <= theta) && (theta < 5 * M_PI / 3))) {
    return 1.0 - fabs(fmod(theta / (2 * M_PI / 6), 2) - 1.0);
  } else if (((0 <= theta) && (theta < M_PI / 3)) || ((5 * M_PI / 3 <= theta) && (theta <= 2 * M_PI))) {
    return 1.0;
  } else {
    return 0.0;
  }
}

double hue_to_G(double theta) {
  if (((0 <= theta) && (theta < M_PI / 3)) || ((M_PI <= theta) && (theta < 4 * M_PI / 3))) {
    return 1.0 - fabs(fmod(theta / (2 * M_PI / 6), 2) - 1.0);
  } else if (((M_PI / 3 <= theta) && (theta < 2 * M_PI / 3)) || ((2 * M_PI / 3 <= theta) && (theta < M_PI))) {
    return 1.0;
  } else {
    return 0.0;
  }
}

double hue_to_B(double theta) {
  if (((2 * M_PI / 3 <= theta) && (theta < M_PI)) || ((5 * M_PI / 3 <= theta) && (theta <= 2 * M_PI))) {
    return 1.0 - fabs(fmod(theta / (2 * M_PI / 6), 2) - 1.0);
  } else if (((M_PI <= theta) && (theta < 4 * M_PI / 3)) || ((4 * M_PI / 3 <= theta) && (theta < 5 * M_PI / 3))) {
    return 1.0;
  } else {
    return 0.0;
  }
}