package rainbowPackage;

//import javafx.scene.paint.Paint.*;
import javafx.scene.paint.Color;

public class ColorSlider //Basic Class For Variating Colors For RainbowSoftColor.java Class
{
	public double[] rgb = {0,0,0};
	public Color fxColor;
	public boolean tooSimilar = false;// = {0,0,0};
	public int currentColorDifference = 0;
	public double colorBeingChecked = 0;//, ColorToBeChecked = 0;
	public int alpha = 0, red = 0, green = 0, blue = 0;
	//ColorValueFit colorValueFit = new ColorValueFit(0.);
	public ColorSlider()//1st Square DiagnosticsClass.java
	{
		rgb = new double[]{0,0,0};
		fxColor = Color.BLACK;
	}
	public ColorSlider( Color FXColor )//2nd Square DiagnosticsClass.java
	{
		fxColor = FXColor;
		rgb = new double[] { fxColor.getRed() * 255, fxColor.getGreen() * 255, fxColor.getBlue() * 255 };
	}
	public ColorSlider( double[] RGB )//3rd Square DiagnosticsClass.java
	{
		rgb = new double[] { ColorValueFitter(RGB[0]),ColorValueFitter(RGB[1]),ColorValueFitter(RGB[2]) };
		fxColor = Color.color(rgb[0]/255.,rgb[1]/255.,rgb[2]/255.,1.);
	}
	public void ColorSliderFunction(double ColorInterval, double Loc, Color ColorBefore, Color ColorAfter)//4th Square DiagnosticsClass.java
	{
		rgb[0] = ColorValueFitter( ToTwoFiveFivergb(ColorAfter.getRed()) + ToTwoFiveFivergb(ColorBefore.getRed()) - ToTwoFiveFivergb(ColorBefore.getRed()) * Loc/ColorInterval - ToTwoFiveFivergb(ColorAfter.getRed()) * ( ColorInterval - Loc )/ColorInterval );
		rgb[1] = ColorValueFitter( ToTwoFiveFivergb(ColorAfter.getGreen()) + ToTwoFiveFivergb(ColorBefore.getGreen()) - ToTwoFiveFivergb(ColorBefore.getGreen()) * Loc/ColorInterval - ToTwoFiveFivergb(ColorAfter.getGreen()) * ( ColorInterval - Loc )/ColorInterval );
		rgb[2] = ColorValueFitter( ToTwoFiveFivergb(ColorAfter.getBlue()) + ToTwoFiveFivergb(ColorBefore.getBlue()) - ToTwoFiveFivergb(ColorBefore.getBlue()) * Loc/ColorInterval - ToTwoFiveFivergb(ColorAfter.getBlue()) * ( ColorInterval - Loc )/ColorInterval );
		fxColor = javafx.scene.paint.Color.rgb((int)ColorValueFitter( rgb[0] ), (int)ColorValueFitter( rgb[1] ), (int)ColorValueFitter( rgb[2] ) );
	}
	public void ColorSliderFunction(double ColorInterval, double Loc, double BrightnessMultiplyer, Color ColorBefore, Color ColorAfter)//5th Square DiagnosticsClass.java
	{
		rgb[0] = ToTwoFiveFivergb(ColorAfter.getRed()) + ToTwoFiveFivergb(ColorBefore.getRed()) - ToTwoFiveFivergb(ColorBefore.getRed()) * Loc/ColorInterval - ToTwoFiveFivergb(ColorAfter.getRed()) * ( ColorInterval - Loc )/ColorInterval;
		rgb[1] = ToTwoFiveFivergb(ColorAfter.getGreen()) + ToTwoFiveFivergb(ColorBefore.getGreen()) - ToTwoFiveFivergb(ColorBefore.getGreen()) * Loc/ColorInterval - ToTwoFiveFivergb(ColorAfter.getGreen()) * ( ColorInterval - Loc )/ColorInterval;
		rgb[2] = ToTwoFiveFivergb(ColorAfter.getBlue()) + ToTwoFiveFivergb(ColorBefore.getBlue()) - ToTwoFiveFivergb(ColorBefore.getBlue()) * Loc/ColorInterval - ToTwoFiveFivergb(ColorAfter.getBlue()) * ( ColorInterval - Loc )/ColorInterval;
		if ( BrightnessMultiplyer <= 1 && BrightnessMultiplyer >= 0 )
			for ( int z = 0; z <= 2; z++ )
				rgb[z] = ColorValueFitter( ( rgb[z] * BrightnessMultiplyer ) );
		else
			for ( int z = 0; z <= 2; z++ )
			{
				rgb[z] = rgb[z] + ( rgb[z]  + 4 ) * ( BrightnessMultiplyer - 1 );
				if ( rgb[z] > 255 )
					rgb[z] = 255;
				rgb[z] = ColorValueFitter( rgb[z] );
			}
		fxColor = javafx.scene.paint.Color.rgb((int)ColorValueFitter( rgb[0] ), (int)ColorValueFitter( rgb[1] ), (int)ColorValueFitter( rgb[2] ) );
	}
	public void ColorSliderFunction(double ColorInterval, double Loc, Color ColorBefore, Color ColorAfter, int Gradations)//6th Square DiagnosticsClass.java
	{
		rgb[0] = ColorValueFitter( ToTwoFiveFivergb(ColorAfter.getRed()) + ToTwoFiveFivergb(ColorBefore.getRed()) - ToTwoFiveFivergb(ColorBefore.getRed()) * Math.floor( Loc/ColorInterval * ( Gradations + 2 ) ) / ( Gradations + 1 ) - ToTwoFiveFivergb(ColorAfter.getRed()) * Math.floor( ( ColorInterval - Loc )/ColorInterval * ( Gradations + 2 ) ) / ( Gradations + 1 ) );
		rgb[1] = ColorValueFitter( ToTwoFiveFivergb(ColorAfter.getGreen()) + ToTwoFiveFivergb(ColorBefore.getGreen()) - ToTwoFiveFivergb(ColorBefore.getGreen()) * Math.floor( Loc/ColorInterval * ( Gradations + 2 ) ) / ( Gradations + 1 ) - ToTwoFiveFivergb(ColorAfter.getGreen()) * Math.floor( ( ColorInterval - Loc )/ColorInterval * ( Gradations + 2 ) ) / ( Gradations + 1 ) );
		rgb[2] = ColorValueFitter( ToTwoFiveFivergb(ColorAfter.getBlue()) + ToTwoFiveFivergb(ColorBefore.getBlue()) - ToTwoFiveFivergb(ColorBefore.getBlue()) * Math.floor( Loc/ColorInterval * ( Gradations + 2 ) ) / ( Gradations + 1 ) - ToTwoFiveFivergb(ColorAfter.getBlue()) * Math.floor( ( ColorInterval - Loc )/ColorInterval * ( Gradations + 2 ) ) / ( Gradations + 1 ) );
		fxColor = javafx.scene.paint.Color.rgb((int)ColorValueFitter( rgb[0] ), (int)ColorValueFitter( rgb[1] ), (int)ColorValueFitter( rgb[2] ) );
	}
	public void ColorSliderFunction(double ColorInterval, double Loc, double BrightnessMultiplyer, Color ColorBefore, Color ColorAfter, int Gradations)//7th Square DiagnosticsClass.java
	{
		rgb[0] = ToTwoFiveFivergb(ColorAfter.getRed()) + ToTwoFiveFivergb(ColorBefore.getRed()) - ToTwoFiveFivergb(ColorBefore.getRed()) * Math.floor( Loc/ColorInterval * ( Gradations + 2 ) ) / ( Gradations + 1 ) - ToTwoFiveFivergb(ColorAfter.getRed()) * Math.floor( ( ColorInterval - Loc )/ColorInterval * ( Gradations + 2 ) ) / ( Gradations + 1 );
		rgb[1] = ToTwoFiveFivergb(ColorAfter.getGreen()) + ToTwoFiveFivergb(ColorBefore.getGreen()) - ToTwoFiveFivergb(ColorBefore.getGreen()) * Math.floor( Loc/ColorInterval * ( Gradations + 2 ) ) / ( Gradations + 1 ) - ToTwoFiveFivergb(ColorAfter.getGreen()) * Math.floor( ( ColorInterval - Loc )/ColorInterval * ( Gradations + 2 ) ) / ( Gradations + 1 );
		rgb[2] = ToTwoFiveFivergb(ColorAfter.getBlue()) + ToTwoFiveFivergb(ColorBefore.getBlue()) - ToTwoFiveFivergb(ColorBefore.getBlue()) * Math.floor( Loc/ColorInterval * ( Gradations + 2 ) ) / ( Gradations + 1 ) - ToTwoFiveFivergb(ColorAfter.getBlue()) * Math.floor( ( ColorInterval - Loc )/ColorInterval * ( Gradations + 2 ) ) / ( Gradations + 1 );
		if ( BrightnessMultiplyer <= 1 && BrightnessMultiplyer >= 0 )
			for ( int z = 0; z <= 2; z++ )
				rgb[z] = ColorValueFitter( ( rgb[z] * BrightnessMultiplyer ) );
		else
			for ( int z = 0; z <= 2; z++ )
			{
				rgb[z] = rgb[z] + ( rgb[z]  + 4 ) * ( BrightnessMultiplyer - 1 );
				if ( rgb[z] > 255 )
					rgb[z] = 255;
				rgb[z] = ColorValueFitter( rgb[z] );
			}
		fxColor = javafx.scene.paint.Color.rgb((int)ColorValueFitter( rgb[0] ), (int)ColorValueFitter( rgb[1] ), (int)ColorValueFitter( rgb[2] ) );
	}
	public Color ToFXColor ()//8th Square DiagnosticsClass.java
	{
		return fxColor;
	}
	public double[] ToRGB ()//8th Square DiagnosticsClass.java
	{
		return rgb;
	}
	public Color ToFXColor ( double[] RGB )//9th Square DiagnosticsClass.java
	{
		rgb = RGB;
		fxColor = javafx.scene.paint.Color.rgb((int)ColorValueFitter( rgb[0] ), (int)ColorValueFitter( rgb[1] ), (int)ColorValueFitter( rgb[2] ) );
		return fxColor;
	}
	/*public int ToARGBcolorNum()
	{
		alpha = (alpha << 24) & 0xFF000000;
	    red = (red << 16) & 0x00FF0000; //Shift red 16-bits and mask out other stuff
	    green = (green << 8) & 0x0000FF00; //Shift Green 8-bits and mask out other stuff
	    blue = blue & 0x000000FF; //Mask out anything not blue.

	    return 0x00000000 alpha | red | green | blue; //0xFF000000 for 100% Alpha. Bitwise OR everything together.
	}
	public int ToARGBcolorNum ()//8th Square DiagnosticsClass.java
	{
        fxColor = new ColorSlider( rgb ).ToFXColor();
        return (int)( 255 * 16777216 + rgb[0] * 65536 + rgb[1] * 256 + rgb[2] );
	}
	public int ToARGBcolorNum ( double[] RGB )//9th Square DiagnosticsClass.java
	{
		rgb = RGB;
        fxColor = new ColorSlider( rgb ).ToFXColor();
        return (int)( 255 * 16777216 + rgb[0] * 65536 + rgb[1] * 256 + rgb[2] );
	}
	public int ToARGBcolorNum ( Color FXColor )//9th Square DiagnosticsClass.java
	{
		rgb = new double[] { FXColor.getRed() * 255, FXColor.getGreen() * 255, FXColor.getBlue() * 255 };
        fxColor = FXColor;
        return (int)( 255 * 16777216 + rgb[0] * 65536 + rgb[1] * 256 + rgb[2] );
	}*/
	//tempFXColor = tempColor.rgb((int)color.rgb[0] , Math.abs( (int)color.rgb[1] ), (int)color.rgb[2]).invert();
	public Boolean ColorTooSimilarFunction(int Color1, int Color2)//28th Square DiagnosticsClass.java
	{
		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(color1A - color2A) + 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( Color Color1, Color Color2)//29th Square DiagnosticsClass.java
	{
		tooSimilar = false;
		int colorDifference = (int)( 255 * ( Math.abs(Color1.getOpacity() - Color2.getOpacity()) + Math.abs(Color1.getRed() - Color2.getRed()) + Math.abs(Color1.getGreen() - Color2.getGreen()) + Math.abs(Color1.getBlue() - Color2.getBlue() ) ) );
		if ( colorDifference <= 164 )
			tooSimilar = true;
		else
			tooSimilar = false;
		//System.out.println("colorDifference: " + colorDifference);
		//System.out.println(tooSimilar);
		return tooSimilar;
	}
	public Boolean ColorTooSimilarFunction(ColorSlider Color1, ColorSlider Color2)//11th Square DiagnosticsClass.java
	{
		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 Boolean ColorTooSimilarFunction( int Color1, int Color2, double ColorDifference )//3rd Square DiagnosticsClass.java
	{
		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 colorDifference = Math.abs(color1A - color2A) + Math.abs(color1R - color2R) + Math.abs(color1G - color2G) + Math.abs(color1B - color2B);
		if ( colorDifference <= ColorDifference )//200 )
			tooSimilar = true;
		else
			tooSimilar = false;
		//System.out.println("colorDifference: " + colorDifference);
		//System.out.println(tooSimilar);
		return tooSimilar;
	}
	public Boolean ColorTooSimilarFunction( Color Color1, Color Color2, double ColorDifference )//4th Square DiagnosticsClass.java
	{
		tooSimilar = false;
		int colorDifference = (int)( 255 * ( Math.abs(Color1.getOpacity() - Color2.getOpacity()) + Math.abs(Color1.getRed() - Color2.getRed()) + Math.abs(Color1.getGreen() - Color2.getGreen()) + Math.abs(Color1.getBlue() - Color2.getBlue()) ) );
		if ( colorDifference <= ColorDifference )//200 )
			tooSimilar = true;
		else
			tooSimilar = false;
		//System.out.println("colorDifference: " + colorDifference);
		//System.out.println(tooSimilar);
		return tooSimilar;
	}
	public Boolean ColorTooSimilarFunction(ColorSlider Color1, ColorSlider Color2, double ColorDifference)//11th Square DiagnosticsClass.java
	{
		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 <= ColorDifference )
			tooSimilar = true;
		else
			tooSimilar = false;
		return tooSimilar;
	}
	public double ColorValueFitter ( double ColorToBeChecked )//30th Square DiagnosticsClass.java
	{
		colorBeingChecked = ColorToBeChecked;
		while ( colorBeingChecked < -4080 )
			colorBeingChecked = colorBeingChecked + 4080;
		while ( colorBeingChecked < 0 )
			colorBeingChecked = colorBeingChecked + 255;
		while ( colorBeingChecked > 4080 )
			colorBeingChecked = colorBeingChecked - 4080;
		while ( colorBeingChecked > 255 )
			colorBeingChecked = colorBeingChecked - 255;
		return Math.round(colorBeingChecked);
	}
	public double ColorValueFitterCapper ( double ColorToBeChecked )//30th Square DiagnosticsClass.java
	{
		colorBeingChecked = ColorToBeChecked;
		while ( colorBeingChecked < 0 )
			colorBeingChecked = 0;
		while ( colorBeingChecked > 255 )
			colorBeingChecked = 255;
		return Math.round(colorBeingChecked);
	}
	public double ToTwoFiveFivergb ( double ZeroToOne )
	{	return 255. * ZeroToOne;	}
	public void set(double[] RGB) { rgb = RGB; fxColor = javafx.scene.paint.Color.rgb((int)ColorValueFitter( rgb[0] ), (int)ColorValueFitter( rgb[1] ), (int)ColorValueFitter( rgb[2] ) ); }//13th Square DiagnosticsClass.java
	public void set(Color FXColor) { fxColor = FXColor; rgb = new double[] { ColorValueFitter(ToTwoFiveFivergb(fxColor.getRed())), ColorValueFitter(ToTwoFiveFivergb(fxColor.getGreen())), ColorValueFitter(ToTwoFiveFivergb(fxColor.getBlue())) }; }//14th Square DiagnosticsClass.java
	public Object get() { return fxColor; }//15th Square DiagnosticsClass.java
	//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;
}*/
