import java.applet.Applet;
import java.awt.*;
public class l4 extends Applet  {
Image pilt, sahver;
Graphics piltg, sahverg;
Thread tr=null;
int koht=0, pikkus=500, korgus=500;
int kohtx[]={1, 3, 5, 7, 9, 12, 14, 15, 16, 16,
              17, 18, 18, 19, 19, 20, 20, 20, 20, 20 };
int kohty[]={0, 1, 1, 2, 3, 4, 4, 5, 6, 7, 8, 9,
              10, 11, 13, 15, 17, 20, 23, 26, 28, 30};
Color varvid[]=new Color[5];
public void init(){
varvid[0]=Color.red;
varvid[1]=Color.green;
varvid[2]=Color.blue;
varvid[3]=Color.black;
pilt=createImage(pikkus, korgus);
sahver=createImage(pikkus, korgus);
piltg=pilt.getGraphics();
sahverg=sahver.getGraphics();
a1();
}


public void joonistaL(int arv, Graphics g, int x, int y){
 for(int i=0; i<arv; i++){
 g.drawRect(x, y-(i+1)*20,18, 18);
 g.drawRect(x+i*20, y-20, 18, 18);
 }

}

public int arv(int n){
 if(n==0) return 0;
 if(n==1) return 1;
 else return n+arv(n-1);
}

public void a1(){

for(int i=0; i<4; i++){
  joonistaL(i+1, piltg, 30+i*70+20*arv(i), 100);}


 repaint();

}


public void paint(Graphics g){
g.drawImage(pilt, 0, 0, this);
}
public void update(Graphics g){paint(g);}

}
