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)0x5F6273) Color color2 = new Color((int)0xA4ABBF) def gr = img.createGraphics() def wr = img.getRaster() def buf = new int[4] buf[0] = color2.red buf[1] = color2.green buf[2] = color2.blue buf[3] = 255 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) gr.fillRect(lx+padding, ly+padding, tilesize, tilesize) } else { for(int oy=0;oy<tilesize;oy++){ for(int ox=0;ox<tilesize;ox++){ if( (ox+oy)%2 == 0 ){ wr.setPixel(lx+ox+padding, ly+oy+padding, buf) } } } } } } gr.dispose() ImageIO.write(img, "png", new File("drawrectchecker.png"))
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment