import java.applet.Applet; import java.awt.*; public class Puu extends Applet{ double kaugus(int x1, int y1, int x2, int y2){ return Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); } void joonistaPuu(Graphics g, int x1, int y1, int x2, int y2){ int x3=x1+(x2-x1)/2+(y2-y1)/2; int y3=y1+(y2-y1)/2-(x2-x1)/2; g.drawLine(x1, y1, x2, y2); g.drawLine(x1, y1, x3, y3); g.drawLine(x3, y3, x2, y2); try{Thread.sleep(500);}catch(Exception e){} if(kaugus(x1, y1, x3, y3)>10){ joonistaPuu(g, x1, y1, x3, y3); joonistaPuu(g, x3, y3, x2, y2); } } public void paint(Graphics g){ joonistaPuu(g, 130, 290, 170, 290); } }