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 linelength = 16 def lineinterval = 2; def padding = 2 Color color1 = new Color((int)0x1C425C) def interval = linelength + padding*2 def gr = img.createGraphics() gr.setColor(color1) for(int ly=0;ly<img.getHeight();ly+=interval){ def cc=((int)ly/interval)%2==0?0:1 for(int lx=0;lx<img.getWidth();lx+=interval){ if( cc%2 == 0 ){ for(int py=0;py<=linelength;py+=lineinterval){ gr.drawLine(lx+padding, ly+py+padding, lx+padding+linelength, ly+py+padding) } } else { for(int px=0;px<=linelength;px+=lineinterval){ gr.drawLine(lx+px+padding, ly+padding, lx+px+padding, ly+padding+linelength) } } cc++ } } ImageIO.write(img, "png", new File("drawhvlines.png"))
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment