@Grab(group='org.codehaus.griffon', module='jsilhouette-geom', version='0.4') import java.io.* import java.awt.* import java.awt.geom.* import java.awt.image.* import javax.imageio.* import org.codehaus.griffon.jsilhouette.geom.* // ドーナツ模様を描画する 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 = 18 def radius2 = 12 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(0x8C6F5E)) def rc = 0 for(int ly=0;ly<img.getHeight();ly+=interval){ for(int lx=0;lx<img.getWidth()+radius1;lx+=interval){ def donut = new Donut(lx+radius1, ly+radius1, radius1, radius2, 2) if( rc%2 == 0 ){ donut = new Donut(lx+radius1-interval/2, ly+radius1, radius1, radius2, 2) } gr.fill(donut) } rc++; } gr.dispose() ImageIO.write(img, "png", new File("drawdonutspattern.png"))
出力画像
動作環境
groovy 1.8.6, JDK7 update4