import java.awt.*; import java.applet.*; public class Graafik3 extends Applet{ double kaugus(int x1, int y1, int x2, int y2){ return Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); } void ruut(Graphics g, int x1, int y1, int x2, int y2){ int x3=-x1+x2; int y3=y1+y2; int x5=x1+2*x2; int x6=x1+4*x2; int x7=x1+6*x2; int x8=x1+8*x2; g.setColor(Color.black); g.fillRect(x1, y1, x2, y2); g.fillRect(x5, y1, x2, y2); g.fillRect(x6, y1, x2, y2); g.fillRect(x7, y1, x2, y2); g.fillRect(x8, y1, x2, y2); try{Thread.sleep(500);}catch(Exception e){} if(kaugus(x1, y1, x3, y3)>10){ ruut(g, x3, y3, x2, y2); } } public void paint(Graphics g){ ruut(g, 0, 0, 50, 50); } public static void main(String argumendid[]){ Frame f=new Frame("Joonis"); f.add(new Graafik3()); f.setSize(510, 475); f.setVisible(true); } }