package rainbowPackage;

//import javafx.scene.paint.Paint.*;
//import javafx.scene.paint.Paint.*;
import javafx.scene.paint.Stop;
//import javafx.scene.paint.Color.*;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.*;
//import javafx.scene.paint.Paint;
//import javafx.scene.shape.Rectangle;
import javafx.scene.image.*;
import javafx.scene.layout.StackPane;

//import java.io.IOException;
//import java.net.MalformedURLException;
//import java.net.URI;
//import java.net.URL;

//import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Group;
//import javafx.scene.Node;
//import javafx.scene.Parent;
import javafx.scene.Scene;
//import javafx.scene.Scene.*;
import javafx.scene.SnapshotParameters;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.stage.*;

public class ColorFader //Basic Class For Variating Colors And Determining Transparency For RainbowSoftColor.java Class
{
	public Color fxColor = Color.BLACK;
	/*StackPane pixelPane = new StackPane();
	Color pixelColor = Color.BLACK;
	Rectangle pixelRectangle = new Rectangle( 1, 1, fxColor );
	
	ImageView pixelImageView = new ImageView();
	
	//Parent pixelParent;
	URL pixelURL;//URI.create("file:///C:/Dev/RainbowFirm/RainbowSoft/rainbowPackage/3Dfxml/View3D.fxml").toURL();
	FXMLLoader pixelLoader;// = new FXMLLoader(pixelURL);
	Parent pixelRoot;//pixelLoader.load();
	Node pixelNode = new Canvas();
	Scene pixelScene;// = new Scene( (Parent) pixelNode );// */
	Stage pixelStage = new Stage();
	Group pixelRoot = new Group();
	SnapshotParameters pixelSnapshotParameters = new SnapshotParameters();
	Rectangle2D pixelRectangle2D = new Rectangle2D( 0, 0, 1152, 400 );
	WritableImage bufferPicture = new WritableImage( 1152, 400 );
	Canvas pixelCanvas = new Canvas( 1152, 400 );
	GraphicsContext graphicsContext = pixelCanvas.getGraphicsContext2D();
	StackPane pixelPane = new StackPane();
	ImageView pixelImageView = new ImageView();
	Image pixelImage;
	public double colorBeingChecked = 0, opacityBeingChecked = 1;//, ColorToBeChecked = 0;
	//ColorValueFit colorValueFit = new ColorValueFit(0.);
	public ColorFader()//1st Square DiagnosticsClass.java
	{
        fxColor = Color.rgb( 0, 0, 0, 1 );
	}
	public ColorFader( Color FXColor )//2nd Square DiagnosticsClass.java
	{
		fxColor = FXColor;
    }
	public Object ColorFaderFunction(double ColorInterval, double Loc, Color ColorBefore, Color ColorAfter) //5th Square DiagnosticsClass.java
	{
		//pixelColor.rgb( (int)ColorBefore.getRed(), (int)ColorBefore.getGreen(), (int)ColorBefore.getBlue(), OpacityValueFitter( 1 - Loc / ColorInterval ) );
		//pixelRectangle = new Rectangle ( 1, 1, pixelColor);
		pixelSnapshotParameters.setFill(Color.TRANSPARENT);
		pixelSnapshotParameters.setViewport(pixelRectangle2D);
		/*pixelImage = pixelRectangle.snapshot( pixelSnapshotParameters, bufferPicture );
		pixelPane.getBackground().fill(ColorAfter);
		
		
		pixelPane.getChildren().add( pixelImageView );

		
		try {
			pixelURL = URI.create("file:///C:/Dev/RainbowFirm/RainbowSoft/rainbowPackage/3Dfxml/View0D.fxml").toURL();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		pixelLoader = new FXMLLoader(pixelURL);
				try {
					pixelRoot = pixelLoader.load();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		if (pixelRoot == null) {
			throw new RuntimeException("Could not find " + pixelRoot.toString()); }
		// */
		//pixelScene.setRoot(pixelParent);
	    //pixelStage = (Stage) pixelRoot.getScene().getWindow();
		//pixelScene.snapshot(bufferPicture);
		
		LinearGradient pixelVaryation = new LinearGradient( 0, 0, 1.0, 0, true, CycleMethod.REPEAT, new Stop( 0.0, ColorBefore ), new Stop( 1.0, ColorAfter ) );
		//graphicsContext.setStroke(pixelVaryation);
		//Rectangle imaginarySlider = new Rectangle(0, 0, 1152, 1);
		graphicsContext.setLineWidth(400);
		graphicsContext.setStroke(pixelVaryation);
	    graphicsContext.stroke();
	    
	    pixelRoot.getChildren().add(pixelCanvas);
	    pixelStage.setScene(new Scene(pixelRoot));
	    pixelImageView.setImage( pixelImage );
	    pixelPane.getChildren().add(pixelImageView);
	    pixelStage.show();
		//graphicsContext.getCanvas().snapshot( pixelSnapshotParameters, bufferPicture);//bufferPicture.getPixelReader().getColor( 0, 0 );//snapshot(pixelSnapshotParameters, bufferPicture).getPixelReader().getColor( 0, 0 );
		//fxColor = bufferPicture.getPixelReader().getColor( (int)(1151 * Loc / ColorInterval ), 199 );
		try {
			pixelStage.wait( 200 );
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		pixelStage.hide();
		return fxColor;
	}
	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 OpacityValueFitter ( double OpacityToBeChecked )//31st Square DiagnosticsClass.java
	{
		opacityBeingChecked = OpacityToBeChecked;
		while ( opacityBeingChecked < -16 )
			opacityBeingChecked = opacityBeingChecked + 16;
		while ( opacityBeingChecked < 0 )
			opacityBeingChecked = opacityBeingChecked + 1;
		while ( opacityBeingChecked > 1 )
			opacityBeingChecked = opacityBeingChecked - 1;
		while ( opacityBeingChecked > 16 )
			opacityBeingChecked = opacityBeingChecked - 16;
		return opacityBeingChecked;
	}

	public void set(Color FXColor) { fxColor = FXColor; }//24th Square DiagnosticsClass.java
    public Object getFXColor() { return fxColor; }
    //public Object get() { return fxColor; }
}
