import java.awt.*;
import javax.swing.*;
import java.util.ArrayList;
import static java.lang.Math.*;

/* <applet code="Tree.class" width="300" height="height"></applet> */

public class Tree extends JApplet {
  
  ArrayList<int[]> data = new ArrayList<int []>();
  
  public void drawTree(int d, double x, double y, double r, double t) {
    /* d       --- 再帰呼出しの深さ */
    /* (x, y)  --- 枝の根元の座標 */
    /* r       --- 枝の長さ */
    /* t       --- 枝の角度（ラジアン） */
    double r1;
    if (d==0) return;
    data.add(new int[] {(int)x, (int)y, (int)(x+r*cos(t)), (int)(y+r*sin(t))});
    r1 = r;      drawTree(d-1, x+r1*cos(t), y+r1*sin(t), 0.5*r, t+0.2);
    r1 = 0.55*r; drawTree(d-1, x+r1*cos(t), y+r1*sin(t), 0.5*r, t+1.25);
    r1 = 0.45*r; drawTree(d-1, x+r1*cos(t), y+r1*sin(t), 0.5*r, t-1.3);
  } 
  
  @Override
  public void init() {
    drawTree(6, 128, 255, 128, -PI/2);      
  }
  
  @Override
  public void paint(Graphics g) {
    g.setColor(Color.GREEN);
    for(int[] pts : data) {
      g.drawLine(pts[0], pts[1], pts[2], pts[3]);
      System.out.printf("(%d, %d)--(%d, %d)%n", pts[0], pts[1], pts[2], pts[3]);
    }
  }
}

