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 rectsize = 10 def padding = 2 def color1 = new Color(0x91AA9D) def color2 = new Color(0x3E606F) def rc = 0 for(int ly=0;ly<img.getHeight()+rectsize;ly+=rectsize){ for(int lx=0;lx<img.getWidth()+rectsize;lx+=rectsize){ def pat = ((int)(ly/rectsize)+(int)(lx/rectsize)) % 2 gr.setColor(( pat == 0 )?color1:color2) gr.fillRect(lx, ly, rectsize, rectsize) gr.setColor(( pat == 0 )?color2:color1) gr.fillRect(lx + padding, ly + padding, rectsize - padding*2, rectsize - padding*2) rc++; } } ImageIO.write(img, "png", new File("drawnestedsquares.png"))
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment