import java.applet.Applet;
import java.awt.*;
import java.util.*;
public class m0104304_fractal extends Applet{
  double scale=0.9501;
  int n=50;
  int angle=30;
  int w,h;
  double ang=90.0;
  double ang2 = -90;
  double len=5.0;
double ang_r1 = 30.0;
double ang_r2 = -30.0;
int ysc,xsc;


  public void paint(Graphics g){
    w=getSize().width;
    h=getSize().height;
    double x0,y0,x1,y1;
    x0=0;
    y0=00;
    x1 = x0;
    y1 = y0 - 25;
    ysc = 50;
    xsc = 50;
    g.setColor(Color.white);
    g.fillRect(0,0,w,h);
    g.setColor(new Color(145,42,42));
    for(int i = 0;i<10;i++){
		for(int j = 0;j<10;j++){
			g.drawLine((int)x0+i*xsc,(int)(h-(y0+j*ysc)),(int)x1+i*xsc,(int)(h-(y1+j*ysc)));
		    rtree(g,n,x0+i*xsc,y0+j*ysc,len,ang,ang_r1);
		    rtree(g,n,x0+i*xsc,y0+j*ysc,len,ang,ang_r2);
		    rtree(g,n,x1+i*xsc,y1+j*ysc,len,ang2,ang_r1);
		    rtree(g,n,x1+i*xsc,y1+j*ysc,len,ang2,ang_r2);
		}
	}
  }
  public void rtree(Graphics g,int nn,double x0,double y0,
                    double len,double ang,double ang_r){
							g.setColor(new Color((int)(Math.random()*200),(int)(Math.random()*200),(int)(Math.random()*200)));

    if(nn<=0){
      return;
    }if(nn==1){
      g.setColor(new Color(0,200,97));

    }if(nn==2){
      g.setColor(new Color(0,215,97));
    }if(nn==3){
      g.setColor(new Color(0,245,97));
    }if(nn==4){
      g.setColor(new Color(0,245,120));
    }
    double x,y;
    final double RAD=Math.PI/180.0;
    x=len*Math.cos(RAD*ang)+x0;
    y=len*Math.sin(RAD*ang)+y0;

    g.drawLine((int)x0,(int)(h-y0),(int)x,(int)(h-y));
    if(nn==5){
    rtree(g,nn-1,x,y,len*scale,ang+ang_r,ang_r);
}


    rtree(g,nn-1,x,y,len*scale,ang-ang_r,ang_r);
    g.setColor(new Color(145,42,42));
  }
}

