Here you can find the source of drawBrickGrid(Color color, Graphics2D g, int size, int maxX, int maxY)
public static void drawBrickGrid(Color color, Graphics2D g, int size, int maxX, int maxY)
//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++; } } }