hi rachel
sorry here is the code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class canvas1 extends JFrame {
man mandel;
public canvas1() {
setTitle("MandelbrotSet");
setSize(600,600);
getContentPane().setLayout(new BorderLayout() );
JPanel Bottom = new JPanel();
JButton StartButton = new JButton("START");
StartButton.setEnabled(true);
mandel= new man();
getContentPane().add(mandel,BorderLayout.CENTER );
Thread runner = new Thread(mandel);
runner.start();
//StartButton.addActionListener(mandel);
Bottom.add(StartButton);
getContentPane().add(Bottom,BorderLayout.SOUTH );}
public Insets getInsets() {
return new Insets(2,2,2,2);
}
class man extends JComponent implements Runnable {
Graphics offscreen;
Image im;
double xscale,yscale;
boolean running;
double xmax = 2;
double ymax = 2;
double xmin = -1.2;
double ymin = -0.2;
public void paintComponent(Graphics g) {
if (im == null) {
g.setColor(Color.red);
g.fillRect(0,0,getWidth(),getHeight()) ; }
else
{
g.drawImage(im,0,0,null) ;}
}
public void run() {
Dimension d = getSize();
int maxX = d.width - 1;
int maxY = d.height - 1;
im = createImage(maxX,maxY);
offscreen = im.getGraphics();
offscreen.setColor(Color.black);
offscreen.fillRect(0,0,maxX,maxY);
double dx,dy;
xscale = (xmax-xmin)/d.width;
yscale = (ymax-ymin)/ d.height;
for ( int i= 0 ; i<maxX ; i++ ) {
dx= (xmin+ xscale) ;
for ( int j = 0;j<maxY;j++) {
dy = (ymin + yscale) ;
offscreen.setColor(Color.getHSBColor(calculate(dx,dy)/100.0f,1f,1f));
offscreen.fillRect(i,j,10,10);
paintImmediately(i,j,10,10);
try {
Thread.currentThread().sleep(1000) ;
}
catch (InterruptedException e) { }
dy= dy + yscale;
}
dx = dx + xscale;
}
}
int calculate(double a, double bi){
double c,ci,d,z,zi;
int Max = 250;
a= 0;
bi= 0;
int count = 0;
//c=0.2;
//ci=0.2;
d=0;
while ( count < Max && d<4) {
z= a*a- bi*bi + xmin ;
zi = 2*(a*bi) +ymin ;
a=z;
bi=zi;
d = (a*bi);
count++ ; }
return count; }
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {}
canvas1 application = new canvas1();
application.show();
application.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE) ;
}
thanks
}