//Fapplet is an applet for z^3 -1 not Mandlebro import java.awt.event.MouseListener; import java.awt.event.MouseEvent; import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.awt.Graphics; public class Fapplet extends Applet implements MouseListener { StringBuffer buffer; double xCurser; double yCurser; int imax; int jmax; double aspectRatio; double xcenter; double ycenter; double xstart; double ystart; double xincrement; double yincrement; double zoom; static int BUTTON1_MASK; public void init() { addMouseListener(this); zoom=1.0; xcenter=0.0; ycenter=0.0; imax=300; jmax=300; aspectRatio=((double)jmax)/((double) imax); // xincrement=2.0*zoom/((double)imax); // yincrement=xincrement*aspectRatio; System.out.println("aspectRatio="+aspectRatio); // System.out.println("xincrement="+xincrement); // System.out.println("yincrement="+yincrement); buffer = new StringBuffer(); // addItem("initializing... "); } public void start() { // addItem("starting... "); } public void stop() { // addItem("stopping... "); } public void destroy() { // addItem("preparing for unloading..."); } // void addItem(String newWord) { // System.out.println(newWord); // buffer.append(newWord); // repaint(); // } public void mouseEntered(MouseEvent event) { } public void mouseExited(MouseEvent event) { } public void mousePressed(MouseEvent event) { } public void mouseReleased(MouseEvent event) { } public void mouseClicked(MouseEvent event) { // addItem("click!..."); if( (event.getModifiers() & event.BUTTON3_MASK)== event.BUTTON3_MASK ){ System.out.println("right button pressed"); zoom=zoom*2.0; } if( (event.getModifiers() & event.BUTTON1_MASK)== event.BUTTON1_MASK ){ System.out.println("left button pressed"); zoom=zoom*0.5; } xCurser=event.getX(); yCurser=event.getY(); xcenter=xstart+xCurser*xincrement; ycenter=ystart-yCurser*yincrement; System.out.println("xcenter=" + xcenter + "ycenter=" + ycenter); System.out.println("zoom=" + zoom); repaint(); } public void paint(Graphics g) { g.setColor(Color.black); g.fillRect(0,0,imax,jmax); double thresh=0.0001; double x,y; xstart=xcenter-zoom; ystart=ycenter+zoom*aspectRatio; xincrement=2.0*zoom/((double)imax); yincrement=xincrement*aspectRatio; int maxcount=50; int icount; Complex znew= new Complex(); Complex zold= new Complex(); Complex z2= new Complex(); Complex z3= new Complex(); Complex one=new Complex(1.0,0.0); Complex three=new Complex(3.0,0.0); Complex f= new Complex(); Complex fprime= new Complex(); Complex quot=new Complex(); Complex diff=new Complex(); double absdiff; for (int i=0;ithresh) { zold=znew; z2=zold.Times(zold); z3=zold.Times(z2); f=z3.Minus(one); fprime=z2.Times(three); quot=f.DivideBy(fprime); znew=zold.Minus(quot); diff=znew.Minus(zold); absdiff=diff.Magnitude(); icount=icount+1; if (icount>maxcount) break; } //end while if(icount<=maxcount){ if(icount<=3){ g.setColor(Color.red); g.drawRect(i,j,0,0); } else if((icount>3)&&(icount<=6)){ g.setColor(Color.blue); g.drawRect(i,j,1,1); } else if((icount>6)&&(icount<=9)){ g.setColor(Color.green); g.drawRect(i,j,1,1); } else if((icount>9)&&(icount<=12)){ g.setColor(Color.yellow); g.drawRect(i,j,1,1); } else if((icount>12)&&(icount<=15)){ g.setColor(Color.orange); g.drawRect(i,j,1,1); } else if((icount>15)&&(icount<=18)){ g.setColor(Color.red); g.drawRect(i,j,1,1); } else if((icount>18)&&(icount<=21)){ g.setColor(Color.blue); g.drawRect(i,j,1,1); } else if((icount>21)&&(icount<=24)){ g.setColor(Color.green); g.drawRect(i,j,1,1); } else if((icount>24)&&(icount<=27)){ g.setColor(Color.yellow); g.drawRect(i,j,1,1); } else if((icount>27)&&(icount<=30)){ g.setColor(Color.green); g.drawRect(i,j,1,1); } else if((icount>30)&&(icount<=33)){ g.setColor(Color.red); g.drawRect(i,j,1,1); } else if((icount>33)&&(icount<=36)){ g.setColor(Color.blue); g.drawRect(i,j,1,1); } else if((icount>36)&&(icount<=39)){ g.setColor(Color.yellow); g.drawRect(i,j,1,1); } else if((icount>39)&&(icount<=42)){ g.setColor(Color.blue); g.drawRect(i,j,1,1); } else if((icount>42)&&(icount<=45)){ g.setColor(Color.red); g.drawRect(i,j,1,1); } else if((icount>45)&&(icount<=48)){ g.setColor(Color.blue); g.drawRect(i,j,1,1); } else if((icount>48)&&(icount<=50)){ g.setColor(Color.yellow); g.drawRect(i,j,1,1); } else{ g.setColor(Color.black); g.drawRect(i,j,1,1); } }//end if(icount