package rainbowPackage;

import javafx.scene.paint.Color;

public class RainbowSoftColor
{
	ColorSlider black = new ColorSlider( new double[]{0,0,0} );

	ColorSlider color = black;	

	ColorSlider white = new ColorSlider( new double[]{255,255,255} );
	ColorSlider skyblue = new ColorSlider( new double[]{134,206,249} );
	ColorSlider oxylblue = new ColorSlider( new double[]{0,255,255} );
	ColorSlider pink = new ColorSlider( new double[]{255,64,143} );
	ColorSlider blue = new ColorSlider( new double[]{0,0,192} );
	ColorSlider red = new ColorSlider( new double[]{193,0,0} );
	ColorSlider purple = new ColorSlider( new double[]{122,0,178} );
	ColorSlider orange = new ColorSlider( new double[]{255,134,0} );
	ColorSlider green = new ColorSlider( new double[]{0,133,50} );
	ColorSlider yellow = new ColorSlider( new double[]{246,252,15} );
	ColorSlider teal = new ColorSlider( new double[]{3,224,149} );
	ColorSlider bronze = new ColorSlider( new double[]{152,123,46} );
	ColorSlider silver = new ColorSlider( new double[]{193,192,192} );
	ColorSlider gold = new ColorSlider( new double[]{205,191,44} );
	ColorSlider lime = new ColorSlider( new double[]{126,193,33} );
	ColorSlider brown = new ColorSlider( new double[]{131,103,71} );
	ColorSlider oxylBlue0FF = new ColorSlider( new double[]{0,255,255} );

	public double[] RGB;// = {0,0,0};
	public Color FXColor;
	public double ColorBeingChecked = 0;//, ColorToBeChecked = 0;
	//ColorValueFit colorValueFit = new ColorValueFit(0.);

	public RainbowSoftColor( Color FXColor )
	{
		this.FXColor = FXColor;
		this.RGB = new double[] { FXColor.getRed(), FXColor.getGreen(), FXColor.getBlue() };
	}
	public RainbowSoftColor( double[] RGB )
	{
		this.RGB = RGB;
		this.FXColor = FXColor.rgb( (int)(ColorValueFitter(RGB[0])), (int)(ColorValueFitter(RGB[1])), (int)(ColorValueFitter(RGB[2])) );
	}
	public RainbowSoftColor()
	{
		this.RGB = new double[]{0,0,0,0};
		this.FXColor = FXColor.rgb( (int)(ColorValueFitter(RGB[0])), (int)(ColorValueFitter(RGB[1])), (int)(ColorValueFitter(RGB[2])) );
	}
	public Object RainbowSoftColorFunction(double ColorInterval, double Loc, RainbowSoftColor ColorBefore, RainbowSoftColor ColorAfter)
	{
		for (int z = 0; z <= 2; z++)
			RGB[z] = ( (ColorAfter.RGB[z] - ColorBefore.RGB[z]) * Loc/ColorInterval + ColorBefore.RGB[z] );
		this.FXColor = FXColor.rgb( (int)(ColorValueFitter(RGB[0])), (int)(ColorValueFitter(RGB[1])), (int)(ColorValueFitter(RGB[2])) );
		return new RainbowSoftColor( RGB );
	}
	public Object RainbowSoftColorFunction(double ColorInterval, double Loc, double BrightnessMultiplyer, RainbowSoftColor ColorBefore, RainbowSoftColor ColorAfter)
	{
		if ( BrightnessMultiplyer < 1)
			for (int z = 0; z <= 2; z++)
				RGB[z] = ( ( (ColorAfter.RGB[z] - ColorBefore.RGB[z]) * Loc/ColorInterval + ColorBefore.RGB[z] ) * BrightnessMultiplyer);
		else
			for (int z = 0; z <= 2; z++)
			{
				RGB[z] = ( ( (ColorAfter.RGB[z] - ColorBefore.RGB[z]) * Loc/ColorInterval + ColorBefore.RGB[z] ) );
				RGB[z] = ( (255 - RGB[z]) / BrightnessMultiplyer + RGB[z] );
			}
		this.FXColor = FXColor.rgb( (int)(ColorValueFitter(RGB[0])), (int)(ColorValueFitter(RGB[1])), (int)(ColorValueFitter(RGB[2])) );
		return new RainbowSoftColor( RGB );
	}
	public Object RainbowSoftColorRainbowFunction(double ColorIntervalVariable, double CoreVariable)
	{
		if ( CoreVariable < ColorIntervalVariable)//For Normal Rainbow Use This Instead Of The Others
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, red, orange);
		else if ( CoreVariable < 2 * ColorIntervalVariable )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - ColorIntervalVariable, orange, yellow);
		else if ( CoreVariable < 3 * ColorIntervalVariable )		
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 2 * ColorIntervalVariable, yellow, green);
		else if ( CoreVariable < 4 * ColorIntervalVariable )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 3 * ColorIntervalVariable, green, teal);
		else if ( CoreVariable < 5 * ColorIntervalVariable )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 4 * ColorIntervalVariable, teal, blue);
		else
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 5 * ColorIntervalVariable, blue, purple);
		this.RGB = color.RGB;
		this.FXColor = color.ToFXColor();
		return new RainbowSoftColor( RGB );
	}
	/*public Object RainbowSoftColorRainbowFunction(double ColorIntervalVariable, double CoreVariable, double BrightnessMultiplyer)
	{
		if ( CoreVariable < ColorIntervalVariable)//For Normal Rainbow Use This Instead Of The Others
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, red, orange);
		else if ( CoreVariable < 2 * ColorIntervalVariable )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - ColorIntervalVariable, orange, yellow);
		else if ( CoreVariable < 3 * ColorIntervalVariable )		
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 2 * ColorIntervalVariable, yellow, green);
		else if ( CoreVariable < 4 * ColorIntervalVariable )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 3 * ColorIntervalVariable, green, teal);
		else if ( CoreVariable < 5 * ColorIntervalVariable )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 4 * ColorIntervalVariable, teal, blue);
		else
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 5 * ColorIntervalVariable, blue, purple);
		if ( BrightnessMultiplyer <= 1 && BrightnessMultiplyer >= 0 )
			for (int z = 0; z <= 2; z++)
				RGB[z] = RGB[z] * BrightnessMultiplyer;
		else
			for (int z = 0; z <= 2; z++)
			{
				RGB[z] = (255 - RGB[z]) / BrightnessMultiplyer + RGB[z];
			}
		//this.FXColor = FXColor.rgb( Math.abs( (int)RGB[0] ), Math.abs( (int)RGB[1] ), Math.abs( (int)RGB[2] ) );
		this.RGB = color.RGB;
		this.FXColor = color.ToFXColor();
		return new RainbowSoftColor( color.RGB );
	}//*/
	public Object RainbowSoftColorRainbowFunctionReverse(double ColorIntervalVariable, double CoreVariable)
	{
		if ( CoreVariable < ColorIntervalVariable)//For Normal Rainbow Use This Instead Of The Others
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, purple, blue);
		else if ( CoreVariable < 2 * ColorIntervalVariable )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - ColorIntervalVariable, blue, teal);
		else if ( CoreVariable < 3 * ColorIntervalVariable )		
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 2 * ColorIntervalVariable, teal, pink);
		else if ( CoreVariable < 4 * ColorIntervalVariable )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 3 * ColorIntervalVariable, pink, yellow);
		else if ( CoreVariable < 5 * ColorIntervalVariable )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 4 * ColorIntervalVariable, yellow, orange);
		else
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 5 * ColorIntervalVariable, orange, red);
		this.RGB = color.RGB;
		this.FXColor = color.ToFXColor();
		return new RainbowSoftColor( RGB );
	}
	/*public Object RainbowSoftColorRainbowFunctionReverse(double ColorIntervalVariable, double CoreVariable, double BrightnessMultiplyer)
	{
		if ( CoreVariable < ( ColorIntervalVariable / ( 2 + Gradations) ) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, purple, purple);
		else if ( CoreVariable < ColorIntervalVariable)//For Normal Rainbow Use This Instead Of The Others
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, purple, blue, Gradations);
		else if ( CoreVariable < ( 2 * ColorIntervalVariable) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - ColorIntervalVariable, blue, teal, Gradations);
		else if ( CoreVariable < ( 3 * ColorIntervalVariable) )		
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 2 * ColorIntervalVariable, teal, pink, Gradations);
		else if ( CoreVariable < ( 4 * ColorIntervalVariable) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 3 * ColorIntervalVariable, pink, yellow, Gradations);
		else if ( CoreVariable < ( 5 * ColorIntervalVariable) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 4 * ColorIntervalVariable, yellow, orange, Gradations);
		else if ( CoreVariable < 6 * ColorIntervalVariable - ColorIntervalVariable / ( 2 + Gradations) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 5 * ColorIntervalVariable, orange, red, Gradations);
		else
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, red, red);
		if ( BrightnessMultiplyer <= 1 && BrightnessMultiplyer >= 0 )
			for (int z = 0; z <= 2; z++)
				RGB[z] = RGB[z] * BrightnessMultiplyer;
		else
			for (int z = 0; z <= 2; z++)
			{
				RGB[z] = (255 - RGB[z]) / BrightnessMultiplyer + RGB[z];
			}
		//this.FXColor = FXColor.rgb( Math.abs( (int)RGB[0] ), Math.abs( (int)RGB[1] ), Math.abs( (int)RGB[2] ) );
		this.RGB = color.RGB;
		this.FXColor = color.ToFXColor();
		return new RainbowSoftColor( color.RGB );
	}//*/
	/*public Object RainbowSoftColorRainbowFunction(double ColorIntervalVariable, double CoreVariable, int Gradations)
	{
		if ( CoreVariable < ( ColorIntervalVariable / ( 2 + Gradations) ) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, red, red);
		else if ( CoreVariable < ColorIntervalVariable)//For Normal Rainbow Use This Instead Of The Others
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, red, orange, Gradations);
		else if ( CoreVariable < 2 * ColorIntervalVariable )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - ColorIntervalVariable, orange, yellow, Gradations);
		else if ( CoreVariable < 3 * ColorIntervalVariable )		
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 2 * ColorIntervalVariable, yellow, green, Gradations);
		else if ( CoreVariable < 4 * ColorIntervalVariable )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 3 * ColorIntervalVariable, green, teal, Gradations);
		else if ( CoreVariable < 5 * ColorIntervalVariable )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 4 * ColorIntervalVariable, teal, blue, Gradations);
		else if ( CoreVariable < 6 * ColorIntervalVariable - ColorIntervalVariable / ( 2 + Gradations) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 5 * ColorIntervalVariable, blue, purple, Gradations);
		else
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, purple, purple);
		this.RGB = color.RGB;
		this.FXColor = color.ToFXColor();
		return new RainbowSoftColor( RGB );
	}*/
	public Object RainbowSoftColorRainbowFunction(double ColorIntervalVariable, double CoreVariable, double BrightnessMultiplyer, int Gradations)
	{
		if ( CoreVariable < ( ColorIntervalVariable / ( 2 + Gradations) ) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, red, red);
		else if ( CoreVariable < ColorIntervalVariable)//For Normal Rainbow Use This Instead Of The Others
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, red, orange, Gradations);
		else if ( CoreVariable < 2 * ColorIntervalVariable )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - ColorIntervalVariable, orange, yellow, Gradations);
		else if ( CoreVariable < 3 * ColorIntervalVariable )		
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 2 * ColorIntervalVariable, yellow, green, Gradations);
		else if ( CoreVariable < 4 * ColorIntervalVariable )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 3 * ColorIntervalVariable, green, teal, Gradations);
		else if ( CoreVariable < 5 * ColorIntervalVariable )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 4 * ColorIntervalVariable, teal, blue, Gradations);
		else if ( CoreVariable < 6 * ColorIntervalVariable - ColorIntervalVariable / ( 2 + Gradations) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 5 * ColorIntervalVariable, blue, purple, Gradations);
		else
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, purple, purple);
		if ( BrightnessMultiplyer <= 1 && BrightnessMultiplyer >= 0 )
			for (int z = 0; z <= 2; z++)
				RGB[z] = RGB[z] * BrightnessMultiplyer;
		else
			for (int z = 0; z <= 2; z++)
			{
				RGB[z] = (255 - RGB[z]) / BrightnessMultiplyer + RGB[z];
			}
		//this.FXColor = FXColor.rgb( Math.abs( (int)RGB[0] ), Math.abs( (int)RGB[1] ), Math.abs( (int)RGB[2] ) );
		this.RGB = color.RGB;
		this.FXColor = color.ToFXColor();
		return new RainbowSoftColor( color.RGB );
	}
	/*public Object RainbowSoftColorRainbowFunctionReverse(double ColorIntervalVariable, double CoreVariable, int Gradations)
	{
		if ( CoreVariable < ( ColorIntervalVariable / ( 2 + Gradations) ) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, purple, purple);
		else if ( CoreVariable < ColorIntervalVariable)//For Normal Rainbow Use This Instead Of The Others
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, purple, blue, Gradations);
		else if ( CoreVariable < ( 2 * ColorIntervalVariable) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - ColorIntervalVariable, blue, teal, Gradations);
		else if ( CoreVariable < ( 3 * ColorIntervalVariable) )		
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 2 * ColorIntervalVariable, teal, pink, Gradations);
		else if ( CoreVariable < ( 4 * ColorIntervalVariable) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 3 * ColorIntervalVariable, pink, yellow, Gradations);
		else if ( CoreVariable < ( 5 * ColorIntervalVariable) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 4 * ColorIntervalVariable, yellow, orange, Gradations);
		else if ( CoreVariable < 6 * ColorIntervalVariable - ColorIntervalVariable / ( 2 + Gradations) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 5 * ColorIntervalVariable, orange, red, Gradations);
		else
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, red, red);
		this.RGB = color.RGB;
		this.FXColor = color.ToFXColor();
		return new RainbowSoftColor( RGB );
	}//*/
	public Object RainbowSoftColorRainbowFunctionReverse(double ColorIntervalVariable, double CoreVariable, double BrightnessMultiplyer, int Gradations)
	{
		if ( CoreVariable < ( ColorIntervalVariable / ( 2 + Gradations) ) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, purple, purple);
		else if ( CoreVariable < ColorIntervalVariable)//For Normal Rainbow Use This Instead Of The Others
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, purple, blue, Gradations);
		else if ( CoreVariable < ( 2 * ColorIntervalVariable) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - ColorIntervalVariable, blue, teal, Gradations);
		else if ( CoreVariable < ( 3 * ColorIntervalVariable) )		
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 2 * ColorIntervalVariable, teal, pink, Gradations);
		else if ( CoreVariable < ( 4 * ColorIntervalVariable) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 3 * ColorIntervalVariable, pink, yellow, Gradations);
		else if ( CoreVariable < ( 5 * ColorIntervalVariable) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 4 * ColorIntervalVariable, yellow, orange, Gradations);
		else if ( CoreVariable < 6 * ColorIntervalVariable - ColorIntervalVariable / ( 2 + Gradations) )
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable - 5 * ColorIntervalVariable, orange, red, Gradations);
		else
			color.ColorSliderFunction(ColorIntervalVariable, CoreVariable, red, red);
		if ( BrightnessMultiplyer <= 1 && BrightnessMultiplyer >= 0 )
			for (int z = 0; z <= 2; z++)
				RGB[z] = RGB[z] * BrightnessMultiplyer;
		else
			for (int z = 0; z <= 2; z++)
			{
				RGB[z] = (255 - RGB[z]) / BrightnessMultiplyer + RGB[z];
			}
		//this.FXColor = FXColor.rgb( Math.abs( (int)RGB[0] ), Math.abs( (int)RGB[1] ), Math.abs( (int)RGB[2] ) );
		this.RGB = color.RGB;
		this.FXColor = color.ToFXColor();
		return new RainbowSoftColor( color.RGB );
	}
	public Color ToFXColor ()
	{
		this.FXColor = FXColor.rgb( (int)(ColorValueFitter(RGB[0])), (int)(ColorValueFitter(RGB[1])), (int)(ColorValueFitter(RGB[2])) );
		return FXColor;
	}
	public Color ToFXColor ( double[] RGB )
	{
		this.RGB = RGB;
		this.FXColor = FXColor.rgb( (int)(ColorValueFitter(RGB[0])), (int)(ColorValueFitter(RGB[1])), (int)(ColorValueFitter(RGB[2])) );
		return FXColor;
	}
	//tempFXColor = tempFXColor.rgb((int)color.RGB[0] , Math.abs( (int)color.RGB[1] ), (int)color.RGB[2]).invert();
	public Boolean ColorTooSimilarFunction(int Color1, int Color2)
	{
		Boolean TooSimilar = false;
		int color1A = (Color1 >> 24) & 0xff;
		int color1R = (Color1 >> 16) & 0xff;
		int color1G = (Color1 >> 8) & 0xff;
		int color1B = (Color1) & 0xff;
		int color2A = (Color2 >> 24) & 0xff;
		int color2R = (Color2 >> 16) & 0xff;
		int color2G = (Color2 >> 8) & 0xff;
		int color2B = (Color2) & 0xff;
		/*
		int Color1A = Color1 / 16777216;
		int Color1R = ( Color1 - Color1A * 16777216 ) / 65536;
		int Color1G = ( Color1 - Color1A * 16777216 - Color1R * 65536 ) / 256;
		int Color1B = ( Color1 - Color1A * 16777216 - Color1R * 65536 - Color1G * 256);
		int Color2A = Color2 / 16777216;
		int Color2R = ( Color2 - Color2A * 16777216 ) / 65536;
		int Color2G = ( Color2 - Color2A * 16777216 - Color2R * 65536 ) / 256;
		int Color2B = ( Color2 - Color2A * 16777216 - Color2R * 65536 - Color2G * 256);// */
		int colorDifference = Math.abs(color1R - color2R) + Math.abs(color1G - color2G) + Math.abs(color1B - color2B);
		if ( colorDifference <= 164 )
			TooSimilar = true;
		else
			TooSimilar = false;
		//System.out.println("colorDifference: " + colorDifference);
		//System.out.println(TooSimilar);
		return TooSimilar;
	}
	public Boolean ColorTooSimilarFunction(RainbowSoftColor Color1, RainbowSoftColor Color2)
	{
		Boolean TooSimilar = false;
		int colorDifference = (int)( Math.abs(Color1.RGB[0] - Color2.RGB[0]) + Math.abs(Color1.RGB[1] - Color2.RGB[1]) + Math.abs(Color1.RGB[2] - Color2.RGB[2]) );
		if ( colorDifference <= 164 )
			TooSimilar = true;
		else
			TooSimilar = false;
		//System.out.println("colorDifference: " + colorDifference);
		//System.out.println(TooSimilar);
		return TooSimilar;
	}
	public double ColorValueFitter ( double ColorToBeChecked )
	{
		this.ColorBeingChecked = Math.abs(ColorToBeChecked);
		while ( ColorBeingChecked > 255)
			ColorBeingChecked = ColorBeingChecked - 255;
		return ColorBeingChecked;
	}
	public void set(double[] RGB) { this.RGB = RGB; this.FXColor = FXColor.rgb( (int)(ColorValueFitter(RGB[0])), (int)(ColorValueFitter(RGB[1])), (int)(ColorValueFitter(RGB[2])) ); }
	public void set(Color FXColor) { this.FXColor = FXColor; this.RGB = new double[] { FXColor.getRed(), FXColor.getGreen(), FXColor.getBlue() }; }
	public Object get() { return RGB; }
	//public Object get() { return FXColor; }
}//*/


/*public class Color(double R, double G, double B)  Color
{
	RGB[0] = R;
	RGB[1] = G;
	RGB[2] = B;
	//return RGB;
}*/
