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)0xff8793)) def path = new Path2D.Double() // 分割数 def par = 8 // 中心x def cx = img.getWidth()/2 // 中心y def cy = img.getHeight()/2 // 制御点半径(大) def rad1 = 100 // 半径(小) def rad2 = 40 def dr1=0 def dr2=360/(par*2) path.moveTo( (int)(cx-Math.cos(2*Math.PI*-dr2/360)*rad2), (int)(cy-Math.sin(2*Math.PI*-dr2/360)*rad2) ) path.quadTo( (cx-Math.cos(2*Math.PI*dr1/360)*rad1), (cy-Math.sin(2*Math.PI*dr1/360)*rad1), (cx-Math.cos(2*Math.PI*dr2/360)*rad2), (cy-Math.sin(2*Math.PI*dr2/360)*rad2) ) dr1 += 360/par dr2 += 360/par while(dr2<360){ path.quadTo( (cx-Math.cos(2*Math.PI*dr1/360)*rad1), (cy-Math.sin(2*Math.PI*dr1/360)*rad1), (cx-Math.cos(2*Math.PI*dr2/360)*rad2), (cy-Math.sin(2*Math.PI*dr2/360)*rad2) ) dr1 += 360/par dr2 += 360/par } gr.fill(path) gr.dispose() ImageIO.write(img, "png", new File("flower.png"))
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment