package rainbowPackage;

import javafx.scene.paint.Color;

public class ColorSlider
{
	public double[] RGB;// = {0,0,0};
	public Color FXColor;
	public double ColorBeingChecked = 0;//, ColorToBeChecked = 0;
	//ColorValueFit colorValueFit = new ColorValueFit(0.);
	public ColorSlider( Color FXColor )
	{
		this.FXColor = FXColor;
        this.RGB = new double[] { FXColor.getRed(), FXColor.getGreen(), FXColor.getBlue() };
    }
	public ColorSlider( double[] RGB )
	{
        this.RGB = RGB;
        this.FXColor = FXColor.rgb( (int)(ColorValueFitter(RGB[0])), (int)(ColorValueFitter(RGB[1])), (int)(ColorValueFitter(RGB[2])) );
    }
	public ColorSlider()
	{
        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 ColorSliderFunction(double ColorInterval, double Loc, ColorSlider ColorBefore, ColorSlider ColorAfter)
	{
		for (int z = 0; z <= 2; z++)
			RGB[z] = Math.abs( ( (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 ColorSlider( RGB );
	}
	public Object ColorSliderFunction(double ColorInterval, double Loc, double BrightnessMultiplyer, ColorSlider ColorBefore, ColorSlider ColorAfter)
	{
		if ( BrightnessMultiplyer <= 1 && BrightnessMultiplyer >= 0 )
			for (int z = 0; z <= 2; z++)
				RGB[z] = Math.abs( ( ( (ColorAfter.RGB[z] - ColorBefore.RGB[z]) * Loc/ColorInterval + ColorBefore.RGB[z] ) * BrightnessMultiplyer) );
		else
			for (int z = 0; z <= 2; z++)
			{
				RGB[z] = Math.abs( ( ( (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 ColorSlider( RGB );
	}
	public Object ColorSliderFunction(double ColorInterval, double Loc, ColorSlider ColorBefore, ColorSlider ColorAfter, int Gradations)
	{
		for (int z = 0; z <= 2; z++)
			RGB[z] = Math.abs( ( (ColorAfter.RGB[z] - ColorBefore.RGB[z]) * Math.floor( Loc/ColorInterval * ( Gradations + 2 ) ) / ( Gradations + 1 ) + ColorBefore.RGB[z] ) );
        this.FXColor = FXColor.rgb( (int)(ColorValueFitter(RGB[0])), (int)(ColorValueFitter(RGB[1])), (int)(ColorValueFitter(RGB[2])) );
		return new ColorSlider( RGB );
	}
	public Object ColorSliderFunction(double ColorInterval, double Loc, double BrightnessMultiplyer, ColorSlider ColorBefore, ColorSlider ColorAfter, int Gradations)
	{
		if ( BrightnessMultiplyer <= 1 && BrightnessMultiplyer >= 0 )
			for (int z = 0; z <= 2; z++)
				RGB[z] = Math.abs( ( (ColorAfter.RGB[z] - ColorBefore.RGB[z]) * Math.floor( Loc/ColorInterval * ( Gradations + 2 ) ) / ( Gradations + 1 ) + ColorBefore.RGB[z] * BrightnessMultiplyer ) );
		else
			for (int z = 0; z <= 2; z++)
			{
				RGB[z] = Math.abs( ( (ColorAfter.RGB[z] - ColorBefore.RGB[z]) * Math.floor( Loc/ColorInterval * ( Gradations + 2 ) ) / ( Gradations + 1 ) + 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 ColorSlider( 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(ColorSlider Color1, ColorSlider 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;
}*/
