diff options
author | TymanWasTaken <tyman@tyman.tech> | 2021-07-06 17:15:21 -0400 |
---|---|---|
committer | TymanWasTaken <tyman@tyman.tech> | 2021-07-06 17:17:22 -0400 |
commit | a8e475fa0a7977f64f072548459d592274169d66 (patch) | |
tree | 2f6e3c2fc4aa55c52b848adc493a9ecc842e53f8 /src/main/java/com/thatgravyboat/skyblockhud/SpecialColour.java | |
parent | bb75fd7b83b238f1f922ffc64b2a0a535c5524b7 (diff) | |
download | SkyblockHud-Death-Defied-a8e475fa0a7977f64f072548459d592274169d66.tar.gz SkyblockHud-Death-Defied-a8e475fa0a7977f64f072548459d592274169d66.tar.bz2 SkyblockHud-Death-Defied-a8e475fa0a7977f64f072548459d592274169d66.zip |
Format v2
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/SpecialColour.java')
-rw-r--r-- | src/main/java/com/thatgravyboat/skyblockhud/SpecialColour.java | 205 |
1 files changed, 105 insertions, 100 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/SpecialColour.java b/src/main/java/com/thatgravyboat/skyblockhud/SpecialColour.java index 06dd70c..f675778 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/SpecialColour.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/SpecialColour.java @@ -4,111 +4,116 @@ import java.awt.*; public class SpecialColour { - public static String special(int chromaSpeed, int alpha, int rgb) { - return special( - chromaSpeed, - alpha, - (rgb & 0xFF0000) >> 16, - (rgb & 0x00FF00) >> 8, - (rgb & 0x0000FF) - ); - } - - private static final int RADIX = 10; - - public static String special( - int chromaSpeed, - int alpha, - int r, - int g, - int b - ) { - StringBuilder sb = new StringBuilder(); - sb.append(Integer.toString(chromaSpeed, RADIX)).append(":"); - sb.append(Integer.toString(alpha, RADIX)).append(":"); - sb.append(Integer.toString(r, RADIX)).append(":"); - sb.append(Integer.toString(g, RADIX)).append(":"); - sb.append(Integer.toString(b, RADIX)); - return sb.toString(); - } - - private static int[] decompose(String csv) { - String[] split = csv.split(":"); - - int[] arr = new int[split.length]; - - for (int i = 0; i < split.length; i++) { - arr[i] = Integer.parseInt(split[split.length - 1 - i], RADIX); + public static String special(int chromaSpeed, int alpha, int rgb) { + return special( + chromaSpeed, + alpha, + (rgb & 0xFF0000) >> 16, + (rgb & 0x00FF00) >> 8, + (rgb & 0x0000FF) + ); } - return arr; - } - - public static int specialToSimpleRGB(String special) { - int[] d = decompose(special); - int r = d[2]; - int g = d[1]; - int b = d[0]; - int a = d[3]; - int chr = d[4]; - - return (a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF); - } - - public static int getSpeed(String special) { - return decompose(special)[4]; - } - - public static float getSecondsForSpeed(int speed) { - return ( - (255 - speed) / - 254f * - (MAX_CHROMA_SECS - MIN_CHROMA_SECS) + - MIN_CHROMA_SECS - ); - } - - private static final int MIN_CHROMA_SECS = 1; - private static final int MAX_CHROMA_SECS = 60; - - public static long startTime = -1; - - public static int specialToChromaRGB(String special) { - if (startTime < 0) startTime = System.currentTimeMillis(); - - int[] d = decompose(special); - int chr = d[4]; - int a = d[3]; - int r = d[2]; - int g = d[1]; - int b = d[0]; - - float[] hsv = Color.RGBtoHSB(r, g, b, null); - - if (chr > 0) { - float seconds = getSecondsForSpeed(chr); - hsv[0] += (System.currentTimeMillis() - startTime) / 1000f / seconds; - hsv[0] %= 1; - if (hsv[0] < 0) hsv[0] += 1; + + private static final int RADIX = 10; + + public static String special( + int chromaSpeed, + int alpha, + int r, + int g, + int b + ) { + StringBuilder sb = new StringBuilder(); + sb.append(Integer.toString(chromaSpeed, RADIX)).append(":"); + sb.append(Integer.toString(alpha, RADIX)).append(":"); + sb.append(Integer.toString(r, RADIX)).append(":"); + sb.append(Integer.toString(g, RADIX)).append(":"); + sb.append(Integer.toString(b, RADIX)); + return sb.toString(); + } + + private static int[] decompose(String csv) { + String[] split = csv.split(":"); + + int[] arr = new int[split.length]; + + for (int i = 0; i < split.length; i++) { + arr[i] = Integer.parseInt(split[split.length - 1 - i], RADIX); + } + return arr; } - return ( - (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF) - ); - } + public static int specialToSimpleRGB(String special) { + int[] d = decompose(special); + int r = d[2]; + int g = d[1]; + int b = d[0]; + int a = d[3]; + int chr = d[4]; + + return ( + (a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF) + ); + } + + public static int getSpeed(String special) { + return decompose(special)[4]; + } + + public static float getSecondsForSpeed(int speed) { + return ( + (255 - speed) / + 254f * + (MAX_CHROMA_SECS - MIN_CHROMA_SECS) + + MIN_CHROMA_SECS + ); + } - public static int rotateHue(int argb, int degrees) { - int a = (argb >> 24) & 0xFF; - int r = (argb >> 16) & 0xFF; - int g = (argb >> 8) & 0xFF; - int b = (argb) & 0xFF; + private static final int MIN_CHROMA_SECS = 1; + private static final int MAX_CHROMA_SECS = 60; - float[] hsv = Color.RGBtoHSB(r, g, b, null); + public static long startTime = -1; - hsv[0] += degrees / 360f; - hsv[0] %= 1; + public static int specialToChromaRGB(String special) { + if (startTime < 0) startTime = System.currentTimeMillis(); - return ( - (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF) - ); - } + int[] d = decompose(special); + int chr = d[4]; + int a = d[3]; + int r = d[2]; + int g = d[1]; + int b = d[0]; + + float[] hsv = Color.RGBtoHSB(r, g, b, null); + + if (chr > 0) { + float seconds = getSecondsForSpeed(chr); + hsv[0] += + (System.currentTimeMillis() - startTime) / 1000f / seconds; + hsv[0] %= 1; + if (hsv[0] < 0) hsv[0] += 1; + } + + return ( + (a & 0xFF) << 24 | + (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF) + ); + } + + public static int rotateHue(int argb, int degrees) { + int a = (argb >> 24) & 0xFF; + int r = (argb >> 16) & 0xFF; + int g = (argb >> 8) & 0xFF; + int b = (argb) & 0xFF; + + float[] hsv = Color.RGBtoHSB(r, g, b, null); + + hsv[0] += degrees / 360f; + hsv[0] %= 1; + + return ( + (a & 0xFF) << 24 | + (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF) + ); + } } |