import java.awt.*; import java.applet.*; // copyright, M Paez, 1999, U of Antioquia, r Landau OSU public class Fern extends Applet { double mxx,myy,bxx,byy; public void Fernplot(Graphics g) { int i; double x, y, xn, yn, r; int pex,pey; int max, seed; max=15000; seed=68111; x=0.5; /* starting point */ y=0.0; coormundo(0.0,1.0,1.0,-0.5); setBackground(Color.black); g.setColor(Color.green); for(i=1; i<=max; i++) /* iterations */ { r=Math.random(); if (r <= 0.02) /* case 1 */ { xn = 0.5; yn = 0.27*y; } else if((r>0.02) && (r<=0.17)) /* case 2 */ { xn = -0.139*x + 0.263*y + 0.57; yn = 0.246*x + 0.224*y - 0.036; } else if ((r>0.17) && (r<=0.3)) /* case 3 */ { xn = 0.17*x - 0.215*y + 0.408; yn = 0.222*x + 0.176*y + 0.0893; } else /* case 4 */ { xn = 0.781*x + 0.034*y + 0.1075; yn = -0.032*x + 0.739*y + 0.27; } x=xn; y=yn; pex=(int)(mxx*x+bxx); pey=(int)(myy*y+byy); g.drawLine(pex,pey,pex,pey); } } void coormundo(double xiz,double ysu,double xde,double yinf) { double maxx,maxy,xxfin,xxcom,yyin,yysu; maxx=600; maxy=450; xxcom=0.15*maxx; xxfin=0.75*maxx; yyin=0.8*maxy; yysu=0.2*maxy; mxx=(xxfin-xxcom)/(xde-xiz); bxx=0.5*(xxcom+xxfin-mxx*(xiz+xde)); myy=(yyin-yysu)/(yinf-ysu); byy=0.5*(yysu+yyin-myy*(yinf+ysu)); } public void paint(Graphics g) { Fernplot(g); showStatus("Done"); } }