Java Code Examples for javafx.scene.image.PixelWriter#setColor()

The following examples show how to use javafx.scene.image.PixelWriter#setColor() . 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: FXColorPicker.java    From gef with Eclipse Public License 2.0 7 votes vote down vote up
/**
 * Draws a color wheel into the given {@link WritableImage}, starting at the
 * given offsets, in the given size (in pixel).
 *
 * @param image
 *            The {@link WritableImage} in which the color wheel is drawn.
 * @param offsetX
 *            The horizontal offset (in pixel).
 * @param offsetY
 *            The vertical offset (in pixel).
 * @param size
 *            The size (in pixel).
 */
private void renderColorWheel(WritableImage image, int offsetX, int offsetY,
		int size) {
	PixelWriter px = image.getPixelWriter();
	double radius = size / 2;
	Point2D mid = new Point2D(radius, radius);
	for (int y = 0; y < size; y++) {
		for (int x = 0; x < size; x++) {
			double d = mid.distance(x, y);
			if (d <= radius) {
				// compute hue angle
				double angleRad = d == 0 ? 0
						: Math.atan2(y - mid.getY(), x - mid.getX());
				// compute saturation depending on distance to
				// middle
				// ([0;1])
				double sat = d / radius;
				Color color = Color.hsb(angleRad * 180 / Math.PI, sat, 1);
				px.setColor(offsetX + x, offsetY + y, color);
			} else {
				px.setColor(offsetX + x, offsetY + y, Color.TRANSPARENT);
			}
		}
	}
}
 
Example 2
Source File: SingleColorTextureFileCreator.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@BackgroundThread
protected void writeData(@NotNull final VarTable vars, final @NotNull Path resultFile) throws IOException {
    super.writeData(vars, resultFile);

    final Color color = UiUtils.from(vars.get(PROP_COLOR, ColorRGBA.class));

    final int width = vars.getInteger(PROP_WIDTH);
    final int height = vars.getInteger(PROP_HEIGHT);

    final WritableImage writableImage = new WritableImage(width, height);
    final PixelWriter pixelWriter = writableImage.getPixelWriter();

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            pixelWriter.setColor(i, j, color);
        }
    }

    final BufferedImage bufferedImage = SwingFXUtils.fromFXImage(writableImage, null);

    try (final OutputStream out = Files.newOutputStream(resultFile)) {
        ImageIO.write(bufferedImage, "png", out);
    }
}
 
Example 3
Source File: VideoDHGR.java    From jace with GNU General Public License v2.0 6 votes vote down vote up
protected void showDhgr(WritableImage screen, int xOffset, int y, int dhgrWord) {
    PixelWriter writer = screen.getPixelWriter();
    try {
        for (int i = 0; i < 7; i++) {
            Color color;
            if (!dhgrMode && hiresMode) {
                color = Palette.color[dhgrWord & 15];
            } else {
                color = Palette.color[FLIP_NYBBLE[dhgrWord & 15]];
            }
            writer.setColor(xOffset++, y, color);
            writer.setColor(xOffset++, y, color);
            writer.setColor(xOffset++, y, color);
            writer.setColor(xOffset++, y, color);
            dhgrWord >>= 4;
        }
    } catch (ArrayIndexOutOfBoundsException ex) {
        Logger.getLogger(getClass().getName()).warning("Went out of bounds in video display");
    }
}
 
Example 4
Source File: JFXColorPickerUI.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
private Image getHuesCircle(int width, int height) {
    WritableImage raster = new WritableImage(width, height);
    PixelWriter pixelWriter = raster.getPixelWriter();
    Point2D center = new Point2D((double) width / 2, (double) height / 2);
    double rsmall = 0.8 * width / 2;
    double rbig = (double) width / 2;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            double dx = x - center.getX();
            double dy = y - center.getY();
            double distance = Math.sqrt((dx * dx) + (dy * dy));
            double o = Math.atan2(dy, dx);
            if (distance > rsmall && distance < rbig) {
                double H = map(o, -Math.PI, Math.PI, 0, 255);
                double S = 255;
                double L = 152;
                pixelWriter.setColor(x, y, HSL2RGB(H, S, L));
            }
        }
    }
    return raster;
}
 
Example 5
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static Image verticalImage(Image image) {
    int width = (int) image.getWidth();
    int height = (int) image.getHeight();
    PixelReader pixelReader = image.getPixelReader();
    WritableImage newImage = new WritableImage(width, height);
    PixelWriter pixelWriter = newImage.getPixelWriter();
    for (int i = 0; i < width; ++i) {
        int t = 0, b = height - 1;
        while (t <= b) {
            Color ct = pixelReader.getColor(i, t);
            Color cb = pixelReader.getColor(i, b);
            pixelWriter.setColor(i, t, cb);
            pixelWriter.setColor(i, b, ct);
            t++;
            b--;
        }
    }
    return newImage;
}
 
Example 6
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static Image cropInsideFx(Image image, DoubleShape shape, Color bgColor) {
    if (image == null || shape == null || !shape.isValid()
            || bgColor == null) {
        return image;
    }
    int width = (int) image.getWidth();
    int height = (int) image.getHeight();
    PixelReader pixelReader = image.getPixelReader();
    WritableImage newImage = new WritableImage(width, height);
    PixelWriter pixelWriter = newImage.getPixelWriter();
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            if (shape.include(x, y)) {
                pixelWriter.setColor(x, y, bgColor);
            } else {
                pixelWriter.setColor(x, y, pixelReader.getColor(x, y));
            }
        }
    }
    return newImage;
}
 
Example 7
Source File: LcdClockSkin.java    From Enzo with Apache License 2.0 6 votes vote down vote up
private Image createNoiseImage(final double WIDTH, final double HEIGHT, final Color DARK_COLOR, final Color BRIGHT_COLOR, final double ALPHA_VARIATION_IN_PERCENT) {
    int width  = WIDTH <= 0 ? (int) PREFERRED_WIDTH : (int) WIDTH;
    int height = HEIGHT <= 0 ? (int) PREFERRED_HEIGHT : (int) HEIGHT;
    double alphaVariationInPercent      = getSkinnable().clamp(0, 100, ALPHA_VARIATION_IN_PERCENT);
    final WritableImage IMAGE           = new WritableImage(width, height);
    final PixelWriter   PIXEL_WRITER    = IMAGE.getPixelWriter();
    final Random        BW_RND          = new Random();
    final Random        ALPHA_RND       = new Random();
    final double        ALPHA_START     = alphaVariationInPercent / 100 / 2;
    final double        ALPHA_VARIATION = alphaVariationInPercent / 100;
    Color  noiseColor;
    double noiseAlpha;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            noiseColor = BW_RND.nextBoolean() == true ? BRIGHT_COLOR : DARK_COLOR;
            noiseAlpha = getSkinnable().clamp(0, 1, ALPHA_START + ALPHA_RND.nextDouble() * ALPHA_VARIATION);
            PIXEL_WRITER.setColor(x, y, Color.color(noiseColor.getRed(), noiseColor.getGreen(), noiseColor.getBlue(), noiseAlpha));
        }
    }
    return IMAGE;
}
 
Example 8
Source File: Helper.java    From Medusa with Apache License 2.0 6 votes vote down vote up
public static final Image createNoiseImage(final double WIDTH, final double HEIGHT, final Color DARK_COLOR, final Color BRIGHT_COLOR, final double ALPHA_VARIATION_IN_PERCENT) {
    if (Double.compare(WIDTH, 0) <= 0 || Double.compare(HEIGHT, 0) <= 0) return null;
    int                 width                   = (int) WIDTH;
    int                 height                  = (int) HEIGHT;
    double              alphaVariationInPercent = Helper.clamp(0.0, 100.0, ALPHA_VARIATION_IN_PERCENT);
    final WritableImage IMAGE                   = new WritableImage(width, height);
    final PixelWriter   PIXEL_WRITER            = IMAGE.getPixelWriter();
    final Random        BW_RND                  = new Random();
    final Random        ALPHA_RND               = new Random();
    final double        ALPHA_START             = alphaVariationInPercent / 100 / 2;
    final double        ALPHA_VARIATION         = alphaVariationInPercent / 100;
    for (int y = 0 ; y < height ; y++) {
        for (int x = 0 ; x < width ; x++) {
            final Color  NOISE_COLOR = BW_RND.nextBoolean() ? BRIGHT_COLOR : DARK_COLOR;
            final double NOISE_ALPHA = Helper.clamp(0.0, 1.0, ALPHA_START + ALPHA_RND.nextDouble() * ALPHA_VARIATION);
            PIXEL_WRITER.setColor(x, y, Color.color(NOISE_COLOR.getRed(), NOISE_COLOR.getGreen(), NOISE_COLOR.getBlue(), NOISE_ALPHA));
        }
    }
    return IMAGE;
}
 
Example 9
Source File: SingleColorTextureFileCreator.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
protected boolean validate(@NotNull final VarTable vars) {

    final Color color = UiUtils.from(vars.get(PROP_COLOR, ColorRGBA.class));

    final int width = vars.getInteger(PROP_WIDTH);
    final int height = vars.getInteger(PROP_HEIGHT);

    final WritableImage writableImage = new WritableImage(width, height);
    final PixelWriter pixelWriter = writableImage.getPixelWriter();

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            pixelWriter.setColor(i, j, color);
        }
    }

    getImageView().setImage(writableImage);
    return true;
}
 
Example 10
Source File: ImagePane.java    From oim-fx with MIT License 6 votes vote down vote up
private void setGrayImage(Image image) {
	if (null != image && !image.isBackgroundLoading()) {
		int imageWidth = (int) image.getWidth();
		int imageHeight = (int) image.getHeight();
		if (imageWidth > 0 && imageHeight > 0) {
			PixelReader pixelReader = image.getPixelReader();
			grayImage = new WritableImage(imageWidth, imageHeight);
			PixelWriter pixelWriter = grayImage.getPixelWriter();
			for (int y = 0; y < imageHeight; y++) {
				for (int x = 0; x < imageWidth; x++) {
					Color color = pixelReader.getColor(x, y);
					color = color.grayscale();
					pixelWriter.setColor(x, y, color);
				}
			}
		} else {
			grayImage = null;
		}
	} else {
		grayImage = null;
	}
}
 
Example 11
Source File: HeadImageItemPane.java    From oim-fx with MIT License 6 votes vote down vote up
private void setGrayImage(Image image) {
	if (null != image&&!image.isBackgroundLoading()) {
		int imageWidth = (int) image.getWidth();
		int imageHeight = (int) image.getHeight();
		if (imageWidth > 0 && imageHeight > 0) {
			PixelReader pixelReader = image.getPixelReader();
			grayImage = new WritableImage(imageWidth, imageHeight);
			PixelWriter pixelWriter = grayImage.getPixelWriter();
			for (int y = 0; y < imageHeight; y++) {
				for (int x = 0; x < imageWidth; x++) {
					Color color = pixelReader.getColor(x, y);
					color = color.grayscale();
					pixelWriter.setColor(x, y, color);
				}
			}
		} else {
			grayImage = null;
		}
	} else {
		grayImage = null;
	}
}
 
Example 12
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 13
Source File: Utils.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get an image filled with the specified colour.
 * <p/>
 * @param color the colour of the image.
 * @return the image.
 */
public static Image getImageFromColour(final Color color) {
	WritableImage image = new WritableImage(2, 2);
	PixelWriter writer = image.getPixelWriter();
	for (int i = 0; i < image.getWidth(); i++) {
		for (int j = 0; j < image.getHeight(); j++) {
			writer.setColor(i, j, color);
		}
	}
	return image;
}
 
Example 14
Source File: ImageHandler.java    From oim-fx with MIT License 5 votes vote down vote up
private void pixWithImage(int type) {
	PixelReader pixelReader = imageView.getImage().getPixelReader();
	// Create WritableImage
	wImage = new WritableImage((int) image.getWidth(),(int) image.getHeight());
	PixelWriter pixelWriter = wImage.getPixelWriter();

	for (int y = 0; y < image.getHeight(); y++) {
		for (int x = 0; x < image.getWidth(); x++) {
			Color color = pixelReader.getColor(x, y);
			switch (type) {
			case 0:
				color = color.brighter();
				break;
			case 1:
				color = color.darker();
				break;
			case 2:
				color = color.grayscale();
				break;
			case 3:
				color = color.invert();
				break;
			case 4:
				color = color.saturate();
				break;
			case 5:
				color = color.desaturate();
				break;
			default:
				break;
			}
			pixelWriter.setColor(x, y, color);
		}
	}
	imageView.setImage(wImage);
}
 
Example 15
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static Image dragMarginsFx(Image image, Color color, DoubleRectangle rect) {
    try {
        if (image == null || rect == null) {
            return image;
        }
        int iwidth = (int) image.getWidth();
        int iheight = (int) image.getHeight();

        int rwidth = (int) rect.getWidth();
        int rheight = (int) rect.getHeight();
        int rx = (int) rect.getSmallX();
        int ry = (int) rect.getSmallY();
        PixelReader pixelReader = image.getPixelReader();
        WritableImage newImage = new WritableImage(rwidth, rheight);
        PixelWriter pixelWriter = newImage.getPixelWriter();
        int ix, iy;
        for (int j = 0; j < rheight; ++j) {
            for (int i = 0; i < rwidth; ++i) {
                ix = i + rx;
                iy = j + ry;
                if (ix >= 0 && ix < iwidth && iy >= 0 && iy < iheight) {
                    pixelWriter.setColor(i, j, pixelReader.getColor(ix, iy));
                } else {
                    pixelWriter.setColor(i, j, color);
                }
            }
        }

        return newImage;

    } catch (Exception e) {
        logger.error(e.toString());
        return image;
    }

}
 
Example 16
Source File: VideoDHGR.java    From jace with GNU General Public License v2.0 5 votes vote down vote up
protected void displayDoubleLores(WritableImage screen, int xOffset, int y, int rowAddress) {
        int c1 = ((RAM128k) computer.getMemory()).getAuxVideoMemory().readByte(rowAddress + xOffset) & 0x0FF;
        int c2 = ((RAM128k) computer.getMemory()).getMainMemory().readByte(rowAddress + xOffset) & 0x0FF;
        if ((y & 7) < 4) {
            c1 &= 15;
            c2 &= 15;
        } else {
            c1 >>= 4;
            c2 >>= 4;
        }
        PixelWriter writer = screen.getPixelWriter();
//        int yOffset = xyOffset[y][times14[xOffset]];
        Color color = Palette.color[FLIP_NYBBLE[c1]];
        // Unrolled loop, faster
        int xx = xOffset * 14;
        writer.setColor(xx++, y, color);
        writer.setColor(xx++, y, color);
        writer.setColor(xx++, y, color);
        writer.setColor(xx++, y, color);
        writer.setColor(xx++, y, color);
        writer.setColor(xx++, y, color);
        writer.setColor(xx++, y, color);
        color = Palette.color[c2];
        writer.setColor(xx++, y, color);
        writer.setColor(xx++, y, color);
        writer.setColor(xx++, y, color);
        writer.setColor(xx++, y, color);
        writer.setColor(xx++, y, color);
        writer.setColor(xx++, y, color);
        writer.setColor(xx++, y, color);
    }
 
Example 17
Source File: WidgetTransfer.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
/**
     * Create a image representing the dragged widget.
     *
     * @param widget The {@link Widget} being dragged.
     * @param image The widget's type image. Can be {@code null}.
     * @return An {@link Image} instance.
     */
    private static Image createDragImage ( final Widget widget, final Image image, final int width, final int height ) {

        WritableImage dImage = new WritableImage(width, height);

        if ( image != null ) {

//            int w = (int) image.getWidth();
//            int h = (int) image.getHeight();
//            int xo = (int) ( ( width - w ) / 2.0 );
//            int yo = (int) ( ( height - h ) / 2.0 );
//            PixelReader pixelReader = image.getPixelReader();
            PixelWriter pixelWriter = dImage.getPixelWriter();

//  TODO: CR: It seems there is a bug pixelReader.getArgb(...) when on Mac when
//  screen is scaled to have more resolution (no retina scaling is used).
//            for ( int x = 0; x < w; x++ ) {
//                for ( int y = 0; y < h; y++ ) {
//
//                    int wx = xo + x;
//                    int wy = yo + y;
//
//                    if ( wx > 0 && wx < width && wy > 0 && wy < height ) {
//
//                        int argb = pixelReader.getArgb(x, y);
//
//                        pixelWriter.setArgb(wx, wy, pixelReader.getArgb(x, y));
//
//                    }
//
//                }
//            }

            //  CR: Solution #1 - draw only the widget outline.
            for ( int x = 0; x < width; x++ ) {
                pixelWriter.setColor(x, 0, GRAY);
                pixelWriter.setColor(x, height - 1, GRAY);
            }
            for ( int y = 0; y < height; y++ ) {
                pixelWriter.setColor(0, y, GRAY);
                pixelWriter.setColor(width - 1, y, GRAY);
            }

        }

        return dImage;

//  CR: Solution #2 - draw only the widget type image.
//        return image;

    }
 
Example 18
Source File: VideoNTSC.java    From jace with GNU General Public License v2.0 4 votes vote down vote up
private void renderScanline(WritableImage screen, int y) {
        int p = 0;
        if (rowStart != 0) {
//            getCurrentWriter().markDirty(y);
            p = rowStart * 28;
            if (rowStart < 0) {
                return;
            }
        }
        PixelWriter writer = screen.getPixelWriter();
        // Reset scanline position
        int byteCounter = 0;
        for (int s = rowStart; s < 20; s++) {
            int add = 0;
            int bits;
            if (hiresMode) {
                bits = scanline[s] << 2;
                if (s > 0) {
                    bits |= (scanline[s - 1] >> 26) & 3;
                }
            } else {
                bits = scanline[s] << 3;
                if (s > 0) {
                    bits |= (scanline[s - 1] >> 25) & 7;
                }
            }
            if (s < 19) {
                add = (scanline[s + 1] & 7);
            }
            boolean isBW = false;
            boolean mixed = enableVideo7 && dhgrMode && graphicsMode == rgbMode.MIX;
            for (int i = 0; i < 28; i++) {
                if (i % 7 == 0) {
                    isBW = monochomeMode || !colorActive[byteCounter] || (mixed && !hiresMode && !useColor[byteCounter]);
                    byteCounter++;
                }
                if (isBW) {
                    writer.setColor(p++, y, ((bits & 0x8) == 0) ? BLACK : WHITE);
                } else {
                    writer.setArgb(p++, y, activePalette[i % 4][bits & 0x07f]);
                }
                bits >>= 1;
                if (i == 20) {
                    bits |= add << (hiresMode ? 9 : 10);
                }
            }
//                    } else {
//                        for (int i = 0; i < 28; i++) {
//                            writer.setArgb(p++, y, activePalette[i % 4][bits & 0x07f]);
//                            bits >>= 1;
//                            if (i == 20) {
//                                bits |= add << (hiresMode ? 9 : 10);
//                            }
//                        }
//                    }
        }
        Arrays.fill(scanline, 0);
        rowStart = -1;
    }
 
Example 19
Source File: BrushedMetalPaint.java    From Enzo with Apache License 2.0 4 votes vote down vote up
private void setRGB(final WritableImage IMAGE, final int X, final int Y, final int[] PIXELS) {
    final PixelWriter RASTER = IMAGE.getPixelWriter();
    for (int x = 0 ; x < PIXELS.length ; x++) {
        RASTER.setColor(X + x, Y, Color.rgb((PIXELS[x] >> 16) & 0xFF, (PIXELS[x] >> 8) & 0xFF, (PIXELS[x] &0xFF)));
    }
}
 
Example 20
Source File: Canvas3.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private void thread_main()
{
    final Semaphore done = new Semaphore(0);
    try
    {
        final double lambda = 50.0;
        int to_update = 0;
        while (true)
        {
            // Draw image off-screen
            long start = System.currentTimeMillis();
            final WritableImage active = image[to_update];
            // PixelWriter is very limited, but might be just what's needed
            // for a display.builder "IntensityGraph".
            final PixelWriter writer = active.getPixelWriter();
            final double phase = System.currentTimeMillis() / 2000.0;
            // Different regions of image could be prepared on parallel threads
            for (int x=0; x<IMAGE_WIDTH; ++x)
            {
                final int dx = (x - IMAGE_WIDTH/2);
                final long dx2 = dx * dx;
                for (int y=0; y<IMAGE_HEIGHT; ++y)
                {
                    final long dy = (y - IMAGE_HEIGHT/2);
                    final double dist = Math.sqrt(dx2 + dy*dy);
                    final double level = 0.5 + 0.5*Math.cos(2*Math.PI * (dist/lambda - phase));
                    // final Color c = Color.hsb(level*360.0, 1.0, 1.0);
                    final Color c = Color.gray(level);
                    writer.setColor(x, y, c );
                }
            }
            long ms = System.currentTimeMillis() - start;
            if (draw_ms < 0)
                draw_ms = ms;
            else
                draw_ms = (draw_ms * 9 + ms) / 10;
            counter.incrementAndGet();

            // Show image in canvas on UI thread
            start = System.currentTimeMillis();
            Platform.runLater(() ->
            {
                final GraphicsContext gc = canvas.getGraphicsContext2D();
                gc.drawImage(active, 0, 0, canvas.getWidth(), canvas.getHeight());
                updates.setText(Long.toString(counter.get()));
                done.release();
            });

            // Wait for UI thread
            done.acquire();
            ms = System.currentTimeMillis() - start;
            if (update_ms < 0)
                update_ms = ms;
            else
                update_ms = (update_ms * 9 + ms) / 10;

            to_update = 1 - to_update;
            Thread.sleep(20);

            if ((counter.get() % 50) == 0)
            {
                System.out.println("Drawing: " + draw_ms + " ms");
                System.out.println("Update : " + update_ms + " ms");
            }
        }
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }
}