/* cappello@cs.ucsb.edu Peter Cappello Sequential Mandelbrot set, preparatory for a multiprocessor version Uses an array to hold the counts */ import java.lang.*; import java.awt.*; import java.applet.*; import java.awt.event.*; import java.awt.image.*; public class Mandelbrot extends Applet implements ActionListener { Complex ll = new Complex(-2.0, -1.25); double edge = 2.5; // edge length of square in complex plane int clr = 2, // bits of R,G,B; lim = 2^(3*clr) lgRes = 7, // resolution: descretize region into 2^exp X 2^exp squares lgAtom = 6; // log of number of squares on a side of an atomic region final static int yPO = 40; // vertical offset: display region below GUI Label resL = new Label("Resolution"), clrL = new Label("Bits of Red, Green, Blue"), atomL = new Label("Atomic size"); TextField resT = new TextField("7", 1), clrT = new TextField("2", 4), atomT = new TextField("6", 3); public void init() { add(resL); add(resT); add(clrL); add(clrT); add(atomL); add(atomT); resT.addActionListener(this); clrT.addActionListener(this); atomT.addActionListener(this); } public void actionPerformed(ActionEvent e) { lgRes = Integer.parseInt(resT.getText()); lgAtom = Integer.parseInt(atomT.getText()); clr = Integer.parseInt(clrT.getText()); repaint(); } public void paint(Graphics g) { int res = (int) Math.pow(2,lgRes),// resolution: res x res grid lim = (int) Math.pow(2,3*clr), atom = (int) Math.pow(2,lgAtom),// size of atomic piece counts[][] = new int[res][res]; // display Mandelbrot set int num = res/atom, // num sub-regions cnts[][] = new int[atom][atom]; // count array for atom double deltaC = edge/num; // edge of a sub-region Complex deltaRow = new Complex(deltaC,0), deltaCol = new Complex(0,deltaC), cc; MandelbrotSet s; for (int j, i = 0; i < num; i++) for ( j = 0; j < num; j++) { cc = new Complex(j*deltaC,i*deltaC); cc.add(ll); s = new MandelbrotSet(cc, deltaC, atom, clr); s.compute(); s.show(this, g, j*atom, i*atom + yPO); } } }