Java Graphics Draw drawCheckerPattern(Graphics g_, int checkerSize)

Here you can find the source of drawCheckerPattern(Graphics g_, int checkerSize)

Description

draw Checker Pattern

License

Open Source License

Declaration

public static void drawCheckerPattern(Graphics g_, int checkerSize) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;

public class Main {
    public static void drawCheckerPattern(Graphics g_, int checkerSize) {
        Graphics2D g = (Graphics2D) g_;
        g.setColor(new Color(150, 150, 200));
        Rectangle clipBounds = g.getClipBounds();
        g.fillRect(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height);

        g.setColor(Color.GRAY);//  ww w . j a va 2s . co  m
        for (int i = floor(clipBounds.x, checkerSize); i < clipBounds.width + clipBounds.x; i += checkerSize)
            for (int j = floor(clipBounds.y, checkerSize); j < clipBounds.height + clipBounds.y; j += checkerSize)
                if (((i + j) / checkerSize) % 2 == 0)
                    g.fillRect(i, j, checkerSize, checkerSize);
    }

    private static int floor(int val, int base) {
        return val / base * base;
    }
}

Related

  1. drawBubbleHead(Graphics2D g, Point2D headPosition, double orientation, double size, Color color, Stroke stroke)
  2. drawBubbles(Graphics g, int nCode)
  3. drawChar(char c, int x, int y, Graphics g)
  4. drawChars(JComponent c, Graphics g, char[] data, int offset, int length, int x, int y)
  5. drawCheck(Graphics g, int x, int y)
  6. drawColors(Color[] colors, Graphics g, int x1, int y1, int x2, int y2, int direction)
  7. drawCoordinateAxes(Graphics2D g, Component comp)
  8. drawCross(Graphics2D g2d, int x, int y, int size)
  9. drawCrosshatch(Graphics2D g, Color color, int left, int right, int top, int height, int spacing, int verticalOffset)