import java.applet.Applet; import java.awt.*; public class Murdjoon2 extends Applet{ int pikimaJoonePikkus=20; /** * Alamprogramm väljastab kahe punkti vahelise kauguse */ public double kaugus(int x1, int y1, int x2, int y2){ int dx=x2-x1; int dy=y2-y1; return Math.sqrt(dx*dx+dy*dy); } public void murdJoon(Graphics g, int x1, int y1, int x2, int y2){ double k=kaugus(x1, y1, x2, y2); if(k>pikimaJoonePikkus){ int kx=(x1+x2)/2; int ky=(y1+y2)/2; int x3=kx+(int)((Math.random()*k*0.4)-k*0.2); int y3=ky+(int)((Math.random()*k*0.4)-k*0.2); murdJoon(g, x1, y1, x3, y3); murdJoon(g, x3, y3, x2, y2); } else { g.drawLine(x1, y1, x2, y2); } } public void paint(Graphics g){ murdJoon(g, 10, 20, 150, 200); } public static void main(String[] argumendid){ Frame f=new Frame(); f.add(new Murdjoon2()); f.setSize(300, 300); f.setVisible(true); } }