import java.io.* import java.awt.* import java.awt.geom.* import java.awt.image.* import javax.imageio.* // 間隔の空いた市松模様を描画する def img = new BufferedImage( 200, 200, BufferedImage.TYPE_INT_ARGB ) def tilesize = 16 def padding = 2 def interval = tilesize + padding*2 Color color1 = new Color((int)0xF0E4C5) Color color2 = new Color((int)0xD6C28F) def gr = img.createGraphics() for(int ly=0;ly<img.getHeight();ly+=interval){ for(int lx=0;lx<img.getWidth();lx+=interval){ if( ((int)(ly/interval+lx/interval))%2 == 0 ){ gr.setColor(color1) } else { gr.setColor(color2) } gr.fillRect(lx+padding, ly+padding, tilesize, tilesize) } } gr.dispose() ImageIO.write(img, "png", new File("drawtileschecker.png"))
出力画像
動作環境
groovy 1.8.6, JDK7 update4