import java.applet.Applet;
import java.awt.*;
import java.util.*;
public class sakura extends Applet{
	double scale=0.9501;
	int n=10;
	int angle=230;
	int w,h;
	double ang;
	double len=80.0;
	int edaR=100, edaG=90, edaB=70;
	int hanaR=220, hanaG=190, hanaB=200;

	public void paint(Graphics g){
		w=getSize().width;
		h=getSize().height;
		double x0,y0;
		x0=w+60;
		g.setColor(Color.black);
		g.fillRect(0,0,w,h);

		for(int i = 0; i<70; i ++){

			y0=h- (int)(Math.random()*h/2);
			ang = 170 + (int)(Math.random()*45);
			edaR = 120*i/100;
			edaG = 100*i/100;
			edaB = 80*i/100;
			hanaR = 250*i/100;
			hanaG = 230*i/100;
			hanaB = 220*i/100;

			rtree(g,n,x0,y0,len,ang, edaR,edaG,edaB, hanaR, hanaG, hanaB);
		}
	}
	public void rtree(Graphics g,int nn,double x0,double y0,
	double len,double ang,int edaR,int edaG,int edaB, int hanaR, int hanaG, int hanaB){
		if(nn<=0){
			return;
		}else{
			g.setColor(new Color(edaR,edaG,edaB));
		}
		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));
		int ang_r1=(int)(Math.random()*50)-20;
		int ang_r2=(int)(Math.random()*50)-25;
		//int ang_r3=(int)(Math.random()*30);
		rtree(g,nn-1,x,y,len*scale,ang+ang_r1,edaR,edaG,edaB,hanaR, hanaG, hanaB);//‰¡
		rtree2(g,1,x,y,len*scale,ang+ang_r2,edaR,edaG,edaB,hanaR, hanaG, hanaB);//‰º
		//rtree(g,nn-1,x,y,len*scale,ang+ang_r3);//ã
	}

	public void rtree2(Graphics g,int nn,double x0,double y0,
	double len,double ang,int edaR,int edaG,int edaB,int hanaR, int hanaG, int hanaB){
		g.setColor(new Color(edaR,edaG,edaB));
		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));

		double a,b,c,d;
		a = x0; b = y0; c = x; d = y;

		hanaOval(g, a, b, c, d,hanaR, hanaG, hanaB);
	}

	public void hanaOval(Graphics g, double x0, double y0, double x, double y,int hanaR, int hanaG, int hanaB){
		g.setColor(new Color(hanaR, hanaG, hanaB));
		double a, b, c, d;
		double posX[] = new double[6];
		double posY[] = new double[6];
		a=x;
		b=h-y;
		c=x0;
		d=h-y0;

		for(int i = 0; i < 6; i ++){
			posX[i] = (c-a)/4*i + a;
			posY[i] = (d-b)/4*i + b;
		}

		for(int i=0; i<3; i++){
			g.fillOval((int)posX[i]-4,(int)posY[i]-4,8,8	);
		}

	}
}
