// 菊 葉(3) // ギザギザの葉を描く // // スケールを徐々に小さく変えて内部を塗り潰す // 回転もできる // スケール倍するとき、回転の中心を調整する import java.applet.Applet; import java.awt.*; public class leaf3c extends Applet { public void paint(Graphics g) { final double RADIAN = Math.PI/180.0; final double[] x = {0,0,10,15,15,17,19,21,25,25,32,34,37,40,42,42,44,45,47,50}; final double[] y = {0,2, 2, 6,11,14,13,15,14,10,15,14,14, 7, 8, 6, 7, 5, 6, 0}; int N = x.length; // 葉の尖端の個数 int i,x1,y1,x2,y2; double xx1,yy1,xx2=0,yy2=0,cx,cy; double scale = 5.0; double theta = 30; // 回転角度 // スケール倍の中心 cx = (x[N-1]-x[0])/2.0; cy = 0.0; graphics.SetColor(g,0x008800); while (scale>0) { for (i=0; i<N-1; i++) { // 葉の上半分 xx1 = (x[i]-cx)*scale; yy1 = (y[i]-cy)*scale; x1 = (int)(graphics.RotateX(xx1,yy1,theta)); y1 = (int)(graphics.RotateY(xx1,yy1,theta)); xx2 = (x[i+1]-cx)*scale; yy2 = (y[i+1]-cy)*scale; x2 = (int)(graphics.RotateX(xx2,yy2,theta)); y2 = (int)(graphics.RotateY(xx2,yy2,theta)); graphics.DrawLine(g,x1,y1,x2,y2); // 葉の下半分 x1 = (int)(graphics.RotateX(xx1,-yy1,theta)); y1 = (int)(graphics.RotateY(xx1,-yy1,theta)); x2 = (int)(graphics.RotateX(xx2,-yy2,theta)); y2 = (int)(graphics.RotateY(xx2,-yy2,theta)); graphics.DrawLine(g,x1,y1,x2,y2); } scale -= 0.001; } } }