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_RGB ) def gr = img.createGraphics() gr.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ) def radius1 = 9 def radius2 = 3 def dr = radius1 - radius2 def padding = 2 def interval = radius1*2 + padding gr.setColor(new Color(0xffffff)) gr.fillRect(0, 0, img.getWidth(), img.getHeight()) gr.setColor(new Color(0x99bbff)) def rc = 0 for(int ly=0;ly<img.getHeight();ly+=interval){ def dc = (rc%2==0)?1:0 for(int lx=0;lx<img.getWidth()+radius1;lx+=interval){ def rr = new Ellipse2D.Double( lx+dr, ly+dr, radius2*2, radius2*2) if( dc%2 == 0 ){ rr = new Ellipse2D.Double( lx, ly, radius1*2, radius1*2) } gr.fill(rr) dc++; } rc++; } gr.dispose() ImageIO.write(img, "png", new File("draw2dots.png"))
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment