Skip to content

Commit

Permalink
Command colors: fix rounding errors in hue to r,g,b conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Jan 16, 2021
1 parent c159895 commit cc094c7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions builtins/src/main/java/org/jline/builtins/Commands.java
Expand Up @@ -1363,22 +1363,22 @@ private int[] hue2rgb(int degree) {
int[] rgb = {0,0,0};
double hue = degree / 60.0;
double a = Math.tan((degree / 360.0) * 2 * Math.PI) / Math.sqrt(3);
if (hue >= 0 && hue <= 1) {
if (hue >= 0 && hue < 1) {
rgb[0] = 0xff;
rgb[1] = (int) (2 * a * 0xff / (1 + a));
} else if (hue >= 1 && hue <= 2) {
} else if (hue >= 1 && hue < 2) {
rgb[0] = (int) (0xff * (1 + a) / (2 * a));
rgb[1] = 0xff;
} else if (hue >= 2 && hue <= 3) {
} else if (hue >= 2 && hue < 3) {
rgb[1] = 0xff;
rgb[2] = (int) (0xff * (1 + a) / (1 - a));
} else if (hue >= 3 && hue <= 4) {
} else if (hue >= 3 && hue < 4) {
rgb[1] = (int) (0xff * (1 - a) / (1 + a));
rgb[2] = 0xff;
} else if (hue >= 4 && hue <= 5) {
rgb[0] = (int) (0xff * (a - 1) / (2 * a));
rgb[2] = 0xff;
} else if (hue >= 5 && hue <= 6) {
} else if (hue > 5 && hue <= 6) {
rgb[0] = 0xff;
rgb[2] = (int) (0xff * 2 * a / (a - 1));
}
Expand Down

0 comments on commit cc094c7

Please sign in to comment.