Java examples for 2D Graphics:Rectangle
fill Blurred Glitch Rect
//package com.java2s; import java.awt.Color; import java.awt.Graphics; public class Main { public static void fillBlurredGlitchRect(Graphics g, Color c, int x, int y, int width, int height, int horizBlurSize, int vertBlurSize) { Color previousColor = g.getColor(); g.setColor(c);//from w w w . j a va2s .c om g.fillRect(x, y, width, height); if (vertBlurSize > 0) { int vertAlphaStep = previousColor.getAlpha() / vertBlurSize; for (int i = 1; i <= vertBlurSize; ++i) { g.setColor(setColorAlpha(previousColor, g.getColor() .getAlpha() - vertAlphaStep)); g.drawLine(x, y - i, x + width, y - i); g.drawLine(x, y + height + i - 1, x + width, y + height + i - 1); } } g.setColor(previousColor); if (horizBlurSize > 0) { int vertAlphaStep = previousColor.getAlpha() / vertBlurSize; for (int i = 1; i <= horizBlurSize; ++i) { g.setColor(setColorAlpha(previousColor, g.getColor() .getAlpha() - vertAlphaStep)); g.drawLine(x - i, y, x - i, y + height - 1); g.drawLine(x + width + i, y, x + width + i, y + height - 1); } } } public static Color setColorAlpha(Color c, int alpha) { if (alpha > 255 || alpha < 0) return c; return new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha); } }