/****************************************************************** * * Mandelbrot program written 5/23/2000, Marcus C. Sarofim * * Still to be implemented: * User ability to set "iterFactor" (should call "iterfactor") * and "iterbase" (currently default 50). * Magfactor should default to log base 100 of magnification + 1. * For user change, need radio box. * *******************************************************************/ import java.awt.*; import java.applet.Applet; import java.awt.event.*; import java.applet.*; public class Mandelbrot extends Applet implements ActionListener, MouseListener, ItemListener { private double shiftx, shifty; private double magnification; private double iterFactor; private float iterBase=75; private Checkbox userIter; private TextField iterField; private boolean userIterp=false; public void init() { userIter=new Checkbox("UserIter"); add(userIter); userIter.addItemListener(this); iterField=new TextField(4); add(iterField); iterField.addActionListener(this); iterField.setText("75"); shiftx=shifty=0; magnification=1; iterFactor=1; this.addMouseListener(this); } public void paint(Graphics g) { g.drawString("shiftx: "+shiftx+" shifty: "+shifty,20,500); g.drawString("magnification: "+magnification+" iteractions: " +(int)(iterFactor*iterBase),20,540); for (int x=-100; x<200; x++) { for (int y=-200; y<200; y++) { double temp=0, othertemp=0;; double xorig, yorig; double xold = x/(100*magnification)+shiftx/100; double yold = y/(100*magnification)+shifty/100; xorig=xold; yorig=yold; double xnew, ynew; for(int q=0; (qiterBase*iterFactor*.95) { g.setColor(new Color(0.5f,0.1f,1.0f)); g.drawLine(x+150, y+250, x+150, y+250); } else if (othertemp>iterBase*iterFactor*.9) { g.setColor(new Color(0.45f,0.0f,1.0f)); g.drawLine(x+150, y+250, x+150, y+250); } else if (othertemp>iterBase*iterFactor*.8) { g.setColor(new Color(0.38f,0.0f,0.97f)); g.drawLine(x+150, y+250, x+150, y+250); } else if (othertemp>iterBase*iterFactor*.7) { g.setColor(new Color(0.32f,0.0f,0.92f)); g.drawLine(x+150, y+250, x+150, y+250); } else if (othertemp>iterBase*iterFactor*.6) { g.setColor(new Color(0.24f,0.0f,0.84f)); g.drawLine(x+150, y+250, x+150, y+250); } else if (othertemp>iterBase*iterFactor*.5) { g.setColor(new Color(0.18f,0.0f,0.75f)); g.drawLine(x+150, y+250, x+150, y+250); } else if (othertemp>iterBase*iterFactor*.4) { g.setColor(new Color(0.14f,0.0f,0.67f)); g.drawLine(x+150, y+250, x+150, y+250); } else if (othertemp>iterBase*iterFactor*.3) { g.setColor(new Color(0.11f,0.0f,0.61f)); g.drawLine(x+150, y+250, x+150, y+250); } else if (othertemp>iterBase*iterFactor*.2) { g.setColor(new Color(0.09f,0.0f,0.57f)); g.drawLine(x+150, y+250, x+150, y+250); } else if (othertemp>iterBase*iterFactor*.1) { g.setColor(new Color(0.05f,0.0f,0.51f)); g.drawLine(x+150, y+250, x+150, y+250); } g.setColor(Color.black); } } } public void actionPerformed(ActionEvent event) { if (event.getSource()==iterField) { iterBase=Integer.parseInt(iterField.getText()); repaint(); } } public void itemStateChanged(ItemEvent e) { if (e.getSource()==userIter) { userIterp = userIter.getState(); if (userIterp) iterFactor=1; else iterFactor=1+Math.log(magnification)/4.6; repaint(); } } public void mouseClicked(MouseEvent event) { } public void mouseReleased(MouseEvent event) { } public void mousePressed(MouseEvent event) { int yCoord = event.getY(); int xCoord = event.getX(); if ((yCoord<450)&&(yCoord>50)&&(xCoord<350)&&(xCoord>50)) { shiftx+=(xCoord-150)/magnification; shifty+=(yCoord-250)/magnification; magnification = 2*magnification; if (!userIterp) { iterFactor = 1+Math.log(magnification)/4.6; } else { iterFactor = 1; } repaint(); } } public void mouseEntered(MouseEvent event) { } public void mouseExited(MouseEvent event) { } }