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 gr = img.createGraphics() gr.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ) gr.setColor(new Color((int)0xff8899ee)) def path = new Path2D.Double() // 分割数 def par = 16 // 半径 def rad1 = 90 // 描画する円の半径 def rad2 = 10 def dr=0 while(dr<360){ def cx = img.getWidth()/2 + Math.cos(2*Math.PI*dr/360)*rad1 -rad2 def cy = img.getHeight()/2 + Math.sin(2*Math.PI*dr/360)*rad1 -rad2 def ellipse = new Ellipse2D.Double(cx, cy, rad2*2, rad2*2) gr.fill(ellipse) dr += 360/par } gr.fill(path) gr.dispose() ImageIO.write(img, "png", new File("circles.png"))
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment