Java Code Examples for javafx.scene.paint.Color#getGreen()

The following examples show how to use javafx.scene.paint.Color#getGreen() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DifferenceHash.java    From JImageHash with MIT License 6 votes vote down vote up
private int drawDoublePrecision(FastPixel writer, int width, int wOffset, int height, int hOffset,
		int blockSize, int offset, int yOffset, int[] bitColorIndex, Color[] colors) {
	int i = offset;
	for (int w = 0; w < (width - wOffset) * blockSize; w = w + blockSize) {
		for (int h = 0; h < (height - hOffset) * blockSize; h = h + blockSize) {
			Color c = colors[bitColorIndex[i++]];
			int red = (int) (c.getRed() * 255);
			int green = (int) (c.getGreen() * 255);
			int blue = (int) (c.getBlue() * 255);

			for (int m = 0; m < blockSize; m++) {
				for (int n = 0; n < blockSize; n++) {
					int x = w + m;
					int y = h + n + yOffset * blockSize;
					// bi.setRGB(y, x, bit ? black : white);
					writer.setRed(x, y, red);
					writer.setGreen(x, y, green);
					writer.setBlue(x, y, blue);
				}
			}
		}
	}
	return i-offset;
}
 
Example 2
Source File: Helper.java    From OEE-Designer with MIT License 6 votes vote down vote up
public static final List<Color> createColorPalette(final Color FROM_COLOR, final Color TO_COLOR,
		final int NO_OF_COLORS) {
	int steps = clamp(1, 12, NO_OF_COLORS) - 1;
	double step = 1.0 / steps;
	double deltaRed = (TO_COLOR.getRed() - FROM_COLOR.getRed()) * step;
	double deltaGreen = (TO_COLOR.getGreen() - FROM_COLOR.getGreen()) * step;
	double deltaBlue = (TO_COLOR.getBlue() - FROM_COLOR.getBlue()) * step;
	double deltaOpacity = (TO_COLOR.getOpacity() - FROM_COLOR.getOpacity()) * step;

	List<Color> palette = new ArrayList<>(NO_OF_COLORS);
	Color currentColor = FROM_COLOR;
	palette.add(currentColor);
	for (int i = 0; i < steps; i++) {
		double red = clamp(0d, 1d, (currentColor.getRed() + deltaRed));
		double green = clamp(0d, 1d, (currentColor.getGreen() + deltaGreen));
		double blue = clamp(0d, 1d, (currentColor.getBlue() + deltaBlue));
		double opacity = clamp(0d, 1d, (currentColor.getOpacity() + deltaOpacity));
		currentColor = Color.color(red, green, blue, opacity);
		palette.add(currentColor);
	}
	return palette;
}
 
Example 3
Source File: Util.java    From Enzo with Apache License 2.0 5 votes vote down vote up
public static Image createGrayNoise(final double WIDTH, final double HEIGHT, final Color DARK_COLOR, final Color BRIGHT_COLOR) {
    if (WIDTH <= 0 || HEIGHT <= 0) {
        return null;
    }
    final WritableImage IMAGE      = new WritableImage((int) WIDTH, (int) HEIGHT);
    final PixelWriter PIXEL_WRITER = IMAGE.getPixelWriter();
    final Random RND = new Random();

    double redDark   = DARK_COLOR.getRed();
    double greenDark = DARK_COLOR.getGreen();
    double blueDark  = DARK_COLOR.getBlue();

    double redBright   = DARK_COLOR.getRed();
    double greenBright = DARK_COLOR.getGreen();
    double blueBright  = DARK_COLOR.getBlue();

    int startRed   = (int) (Math.min(redDark, redBright) * 255);
    int startGreen = (int) (Math.min(greenDark, greenBright) * 255);
    int startBlue  = (int) (Math.min(blueDark, blueBright) * 255);
    int start = returnLargest(startRed, startGreen, startBlue);

    int deltaRed   = Math.abs((int) ((BRIGHT_COLOR.getRed() - DARK_COLOR.getRed()) * 255));
    int deltaGreen = Math.abs((int) ((BRIGHT_COLOR.getGreen() - DARK_COLOR.getGreen()) * 255));
    int deltaBlue  = Math.abs((int) ((BRIGHT_COLOR.getBlue() - DARK_COLOR.getBlue()) * 255));
    int delta = returnLargest(deltaRed, deltaGreen, deltaBlue);

    int gray;
    for (int y = 0; y < HEIGHT; y++) {
        for (int x = 0; x < WIDTH; x++) {
            gray = delta > 0 ? start + RND.nextInt(delta) : start;
            PIXEL_WRITER.setColor(x, y, Color.rgb(clamp(0, 255, gray), clamp(0, 255, gray), clamp(0, 255, gray)));
        }
    }
    return IMAGE;
}
 
Example 4
Source File: ImageUtil.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieve an overlay image.
 *
 * @param overlayType
 *            The overlay type.
 * @param side
 *            The side of the eye.
 * @param color
 *            The overlay color.
 *
 * @return The overlay image.
 */
private static Image getOverlayImage(final int overlayType, final RightLeft side, final Color color) {
	URL imageUrl = ClassLoader.getSystemResource("overlay/" + getOverlayFileName(overlayType, side));

	Image image = new Image(imageUrl.toExternalForm());

	Canvas canvas = new Canvas(OVERLAY_SIZE, OVERLAY_SIZE);
	Color colorNoAlpha = new Color(color.getRed(), color.getGreen(), color.getBlue(), 1);

	Blend effect = new Blend(
			BlendMode.SRC_ATOP,
			null,
			new ColorInput(
					0,
					0,
					OVERLAY_SIZE,
					OVERLAY_SIZE,
					colorNoAlpha));

	// Type 2 is not changed in color.
	if (overlayType != 2) {
		canvas.getGraphicsContext2D().setEffect(effect);
	}
	canvas.getGraphicsContext2D().setGlobalAlpha(color.getOpacity());
	canvas.getGraphicsContext2D().drawImage(image, 0, 0, OVERLAY_SIZE, OVERLAY_SIZE);
	SnapshotParameters parameters = new SnapshotParameters();
	parameters.setFill(Color.TRANSPARENT);

	return canvas.snapshot(parameters, null);
}
 
Example 5
Source File: UiUtils.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Convert the color to hex presentation to use in web.
 *
 * @param color the color.
 * @return the web presentation.
 */
@FromAnyThread
public static @NotNull String toWeb(@NotNull final Color color) {
    final int red = (int) (color.getRed() * 255);
    final int green = (int) (color.getGreen() * 255);
    final int blue = (int) (color.getBlue() * 255);
    return "#" + Integer.toHexString(red) + Integer.toHexString(green) + Integer.toHexString(blue);
}
 
Example 6
Source File: HeatTabController.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
/**
 * Helper function to convert a color in linear RGB space to SRGB space.
 */
public static Color convertLinearRGBtoSRGB(Color color) {
    double[] colors = new double[] { color.getRed(), color.getGreen(), color.getBlue() };
    for (int i=0; i<colors.length; i++) {
        if (colors[i] <= 0.0031308) {
            colors[i] = colors[i] * 12.92;
        } else {
            colors[i] = (1.055 * Math.pow(colors[i], (1.0 / 2.4))) - 0.055;
        }
    }
    return Color.color(colors[0], colors[1], colors[2], color.getOpacity());
}
 
Example 7
Source File: ColorUtilty.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 *
 * @param color JavaFX color
 * @return AWT color
 */
@Nullable
public static java.awt.Color colorToAWTColor(final Color color)
{
	if (color == null)
	{
		return null;
	}
	return new java.awt.Color(
			(int) (color.getRed() * 255),
			(int) (color.getGreen() * 255),
			(int) (color.getBlue() * 255)
	);
}
 
Example 8
Source File: SerializableColor.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
public SerializableColor(Color color) {
    if (color != null) {
        r = color.getRed();
        g = color.getGreen();
        b = color.getBlue();
        a = color.getOpacity();
    }
}
 
Example 9
Source File: HeatTabController.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
/**
 * Helper function to convert a color in linear RGB space to SRGB space.
 */
public static Color convertLinearRGBtoSRGB(Color color) {
    double[] colors = new double[] { color.getRed(), color.getGreen(), color.getBlue() };
    for (int i=0; i<colors.length; i++) {
        if (colors[i] <= 0.0031308) {
            colors[i] = colors[i] * 12.92;
        } else {
            colors[i] = (1.055 * Math.pow(colors[i], (1.0 / 2.4))) - 0.055;
        }
    }
    return Color.color(colors[0], colors[1], colors[2], color.getOpacity());
}
 
Example 10
Source File: ColorUtilty.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 *
 * @param color JavaFX color
 * @return AWT color
 */
@Nullable
public static java.awt.Color colorToAWTColor(final Color color)
{
	if (color == null)
	{
		return null;
	}
	return new java.awt.Color(
			(int) (color.getRed() * 255),
			(int) (color.getGreen() * 255),
			(int) (color.getBlue() * 255)
	);
}
 
Example 11
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static int calculateColorDistance2(Color color1, Color color2) {
    double redDiff = (color1.getRed() - color2.getRed()) * 255;
    double greenDiff = (color1.getGreen() - color2.getGreen()) * 255;
    double blueDiff = (color1.getBlue() - color2.getBlue()) * 255;
    int v = (int) Math.round(2 * redDiff * redDiff
            + 4 * greenDiff * greenDiff
            + 3 * blueDiff * blueDiff);
    return v;
}
 
Example 12
Source File: FXUtilities.java    From megan-ce with GNU General Public License v3.0 5 votes vote down vote up
/**
 * changes opacity, if paint is a color
 *
 * @param paint
 * @param opacity
 * @return paint
 */
public static Paint changeOpacity(Paint paint, double opacity) {
    if (paint instanceof Color) {
        Color color = (Color) paint;
        return new Color(color.getRed(), color.getGreen(), color.getBlue(), opacity);
    } else
        return paint;
}
 
Example 13
Source File: ColorPickerSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private String createRGBString(Color c) {
    return "-fx-base: rgb(" + (c.getRed() * 255) + "," + (c.getGreen() * 255) + "," + (c.getBlue() * 255) + ");";
}
 
Example 14
Source File: OBJWriter.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
public void setMaterialColor(Color color){
    diffuseColor=""+((float)(color.getRed()))+" "+((float)(color.getGreen()))+" "+((float)(color.getBlue()));
}
 
Example 15
Source File: ColorPickerDemo.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private String createRGBString(Color c) {
    return "-fx-base: rgb(" + (c.getRed() * 255) + "," + (c.getGreen() * 255) + "," + (c.getBlue() * 255) + ");";
}
 
Example 16
Source File: TextStyle.java    From RichTextFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
static String cssColor(Color color) {
    int red = (int) (color.getRed() * 255);
    int green = (int) (color.getGreen() * 255);
    int blue = (int) (color.getBlue() * 255);
    return "rgb(" + red + ", " + green + ", " + blue + ")";
}
 
Example 17
Source File: ColorPickerPreference.java    From Quelea with GNU General Public License v3.0 4 votes vote down vote up
private String getColorString(Color color) {
    return color.getRed() + "," + color.getGreen() + "," + color.getBlue();
}
 
Example 18
Source File: SVColorArray.java    From arma-dialog-creator with MIT License 4 votes vote down vote up
/** Set the color from a JavaFX Color instance */
public SVColorArray(@NotNull Color newValue) {
	this(newValue.getRed(), newValue.getGreen(), newValue.getBlue(), newValue.getOpacity());
}
 
Example 19
Source File: SVColorIntArray.java    From arma-dialog-creator with MIT License 4 votes vote down vote up
/** Set the color from a JavaFX Color instance */
public SVColorIntArray(@NotNull Color newValue) {
	this(newValue.getRed(), newValue.getGreen(), newValue.getBlue(), newValue.getOpacity());
}
 
Example 20
Source File: ImageEditingApp.java    From FXTutorials with MIT License 4 votes vote down vote up
private double valueOf(Color c) {
    return c.getRed() + c.getGreen() + c.getBlue();
}