package squeek.veganoption.helpers;

public class ColorHelper
{
	public static int blendBetweenColors(double val, int minColor, int maxColor)
	{
		return blendBetweenColors(val, minColor, maxColor, 0d, 1d);
	}

	public static int blendBetweenColors(double val, int minColor, int maxColor, double min, double max)
	{
		if (min == max)
			return maxColor;

		double range = max - min;
		double ratioOfMax = (max - val) / range;
		double ratioOfMin = (val - min) / range;

		int[] minColorRGBA = toRGBA(minColor);
		int[] maxColorRGBA = toRGBA(maxColor);
		int[] color = new int[]{
			(int) (maxColorRGBA[0] * ratioOfMin + minColorRGBA[0] * ratioOfMax),
			(int) (maxColorRGBA[1] * ratioOfMin + minColorRGBA[1] * ratioOfMax),
			(int) (maxColorRGBA[2] * ratioOfMin + minColorRGBA[2] * ratioOfMax),
			(int) (maxColorRGBA[3] * ratioOfMin + minColorRGBA[3] * ratioOfMax)
		};

		return fromRGBA(color[0], color[1], color[2], color[3]);
	}

	public static float[] toNormalizedRGB(int color)
	{
		return toNormalizedRGBA(color | (255 & 255) << 24);
	}

	public static float[] toNormalizedRGBA(int color)
	{
		int[] rgba = toRGBA(color);

		return new float[]{rgba[0] / 255f, rgba[1] / 255f, rgba[2] / 255f, rgba[3] / 255f};
	}

	public static int[] toRGBA(int color)
	{
		int alpha = color >> 24 & 255;
		int red = color >> 16 & 255;
		int green = color >> 8 & 255;
		int blue = color & 255;

		return new int[]{red, green, blue, alpha};
	}

	public static int fromRGBA(int r, int g, int b, int a)
	{
		return (a & 255) << 24 | (r & 255) << 16 | (g & 255) << 8 | b & 255;
	}

	public static int fromRGB(int r, int g, int b)
	{
		return fromRGBA(r, g, b, 255);
	}

	public static int fromNormalizedRGBA(float r, float g, float b, float a)
	{
		return fromRGBA((int) r * 255, (int) g * 255, (int) b * 255, (int) a * 255);
	}

	public static int fromNormalizedRGB(float r, float g, float b)
	{
		return fromNormalizedRGBA(r, g, b, 1f);
	}
}
@@ -61,879 +61,8 @@
 r%0A%7B%0A
-%09public static int blendBetweenColors(double val, int minColor, int maxColor)%0A%09%7B%0A%09%09return blendBetweenColors(val, minColor, maxColor, 0d, 1d);%0A%09%7D%0A%0A%09public static int blendBetweenColors(double val, int minColor, int maxColor, double min, double max)%0A%09%7B%0A%09%09if (min == max)%0A%09%09%09return maxColor;%0A%0A%09%09double range = max - min;%0A%09%09double ratioOfMax = (max - val) / range;%0A%09%09double ratioOfMin = (val - min) / range;%0A%0A%09%09int%5B%5D minColorRGBA = toRGBA(minColor);%0A%09%09int%5B%5D maxColorRGBA = toRGBA(maxColor);%0A%09%09int%5B%5D color = new int%5B%5D%7B%0A%09%09%09(int) (maxColorRGBA%5B0%5D * ratioOfMin + minColorRGBA%5B0%5D * ratioOfMax),%0A%09%09%09(int) (maxColorRGBA%5B1%5D * ratioOfMin + minColorRGBA%5B1%5D * ratioOfMax),%0A%09%09%09(int) (maxColorRGBA%5B2%5D * ratioOfMin + minColorRGBA%5B2%5D * ratioOfMax),%0A%09%09%09(int) (maxColorRGBA%5B3%5D * ratioOfMin + minColorRGBA%5B3%5D * ratioOfMax)%0A%09%09%7D;%0A%0A%09%09return fromRGBA(color%5B0%5D, color%5B1%5D, color%5B2%5D, color%5B3%5D);%0A%09%7D%0A%0A
 %09pub
@@ -148,19 +148,11 @@
 r %7C 
-(
 255
- & 255)
  %3C%3C 
@@ -1042,10 +1042,881 @@
  1f);%0A%09%7D
+%0A%0A%09public static int blendBetweenColors(double val, int minColor, int maxColor)%0A%09%7B%0A%09%09return blendBetweenColors(val, minColor, maxColor, 0d, 1d);%0A%09%7D%0A%0A%09public static int blendBetweenColors(double val, int minColor, int maxColor, double min, double max)%0A%09%7B%0A%09%09if (min == max)%0A%09%09%09return maxColor;%0A%0A%09%09double range = max - min;%0A%09%09double ratioOfMax = (max - val) / range;%0A%09%09double ratioOfMin = (val - min) / range;%0A%0A%09%09int%5B%5D minColorRGBA = toRGBA(minColor);%0A%09%09int%5B%5D maxColorRGBA = toRGBA(maxColor);%0A%09%09int%5B%5D color = new int%5B%5D%7B%0A%09%09%09(int) (maxColorRGBA%5B0%5D * ratioOfMin + minColorRGBA%5B0%5D * ratioOfMax),%0A%09%09%09(int) (maxColorRGBA%5B1%5D * ratioOfMin + minColorRGBA%5B1%5D * ratioOfMax),%0A%09%09%09(int) (maxColorRGBA%5B2%5D * ratioOfMin + minColorRGBA%5B2%5D * ratioOfMax),%0A%09%09%09(int) (maxColorRGBA%5B3%5D * ratioOfMin + minColorRGBA%5B3%5D * ratioOfMax)%0A%09%09%7D;%0A%0A%09%09return fromRGBA(color%5B0%5D, color%5B1%5D, color%5B2%5D, color%5B3%5D);%0A%09%7D
 %0A%7D

Reorganize color helper a bit