Java Graphics Draw Grid drawBrickGrid(Color color, Graphics2D g, int size, int maxX, int maxY)

Here you can find the source of drawBrickGrid(Color color, Graphics2D g, int size, int maxX, int maxY)

Description

draw Brick Grid

License

Open Source License

Declaration

public static void drawBrickGrid(Color color, Graphics2D g, int size, int maxX, int maxY) 

Method Source Code

//package com.java2s;
/*//  w  w w .j  av a  2  s . c  o  m
 * Copyright 2015 Laszlo Balazs-Csiki
 *
 * This file is part of Pixelitor. Pixelitor is free software: you
 * can redistribute it and/or modify it under the terms of the GNU
 * General Public License, version 3 as published by the Free
 * Software Foundation.
 *
 * Pixelitor is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Pixelitor. If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.Color;

import java.awt.Graphics2D;

public class Main {
    public static void drawBrickGrid(Color color, Graphics2D g, int size, int maxX, int maxY) {
        if (size < 1) {
            throw new IllegalArgumentException("size = " + size);
        }

        g.setColor(color);

        int doubleSize = size * 2;
        int y = size;
        int verticalCount = 0;
        while (y < maxY) {
            // vertical lines
            int hShift = 0;
            if ((verticalCount % 2) == 1) {
                hShift = size;
            }
            for (int x = hShift; x < maxX; x += doubleSize) {
                g.drawLine(x, y, x, y - size);
            }

            // horizontal lines
            g.drawLine(0, y, maxX, y);
            y += size;
            verticalCount++;

        }
    }
}

Related

  1. drawGrid(Color color, Graphics2D g, int maxX, int maxY, int hWidth, int hSpacing, int vWidth, int vSpacing, boolean emptyIntersections)
  2. drawGrid(Graphics2D g, double lowerX, double upperX, int numX, double lowerY, double upperY, int numY)
  3. drawIntegralCoordinateGrid(Graphics2D g, Component comp, int delta)
  4. paintGrid(Graphics g, int width, int height, Color darkColor, Color brightColor)