// ギザギザの葉を描く import java.applet.Applet; import java.awt.*; public class leaf1 extends Applet { int _X = 250; int _Y = 400; // グラフィックス上の新座標系の原点が (250,400) public void paint(Graphics g) { final int[] x = {0,12,10,20,18,30,25,40,34,44,41,47,45,50}; final int[] y = {0, 9, 5,10, 7,12, 5,10, 5, 6, 3, 4, 2, 0}; int N = x.length; // 葉の尖端の個数 // 葉 g.setColor(Color.green); int i,x1,y1,x2,y2; double scale = 5.0; while (scale>0) { // 葉の半分 for (i=0; i<N-1; i++) { x1 = (int)(x[i]*scale); y1 = (int)(y[i]*scale); x2 = (int)(x[i+1]*scale); y2 = (int)(y[i+1]*scale); DrawLine(g,x1,y1,x2,y2); } scale -= 0.02; } } void DrawLine(Graphics g, int x1, int y1, int x2, int y2) { g.drawLine(_X+x1,_Y-y1,_X+x2,_Y-y2); } }