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 = Math.max(Math.max(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 = Math.max(Math.max(deltaRed, deltaGreen), deltaBlue);
int width = (int) WIDTH;
int height = (int) HEIGHT;
IntStream.range(0, height).parallel().forEach(
y -> {
IntStream.range(0, width).parallel().forEach(
x -> {
int 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;