• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

mandelbrot casse tete

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello there
i have been trying to produce a mandelbrot set java apps
and i keep banging my head to the wall
can anybody tell me what is wrong with my code?

import java.awt.*;
import java.awt.event.*;
import java.util.EventListener;
import javax.swing.*;




public class display extends JFrame {


public display(){
setTitle("MandelbrotSet");
setSize(300,300);
setBackground(Color.white);
mandelbrot mandel;
getContentPane().setLayout(new BorderLayout() );
JPanel Bottom = new JPanel();
JButton StartButton = new JButton("START");
StartButton.setEnabled(true);
mandel= new mandelbrot();
getContentPane().add(mandel , BorderLayout.CENTER);
//Thread t = new Thread(mandel);
//t.start();
StartButton.addActionListener(mandel);
Bottom.add(StartButton);
getContentPane().add(Bottom,BorderLayout.SOUTH);


}
class Complex {
double real,imag ;

Complex() {
real= 0.0;
imag= 0.0;
}
Complex(double x, double y) {

real= x;
imag= y;
}
double length(Complex z){
return (z.real*z.imag);
}
};



class mandelbrot extends JPanel implements Runnable,ActionListener {

Graphics offscreen ;
Image im;
// offscreen = im.getGraphics();
Thread runner ;

double xscale,yscale;
double xmin = -2;
double xmax = 2.5;
double ymin = -2;
double ymax = 2.5;
int width =300; //getSize().width;
int height = 300;//getSize().height;


//private int width = 300;
//private int height = 300;
Complex z = new Complex();
public void actionPerformed(ActionEvent event){
String command = event.getActionCommand();
if (command.equals("START")) {
startRunning();
}
}
void startRunning() {
//coloredCoordinates();
//update(offscreen);}
runner = new Thread(this);
runner.start();
}


public void paint(Graphics g) {
if (im == null) {

g.setColor(Color.blue);
g.fillRect(0,0,getWidth(),getHeight());
}
else {
g.drawImage(im,0,0,null);
}


}


int caliter(){

Complex c;
c= new Complex(0,0);
z.real= c.real;
z.imag= c.imag;
int count;
count=0;

while (count< 256 && z.length(z)<4) {
z.real= (z.real*z.real) - (z.imag*z.imag) + c.real;
z.imag = 2*(z.real*z.imag)+ c.imag;
c.real=z.real;
c.imag= z.imag;
}
count++;
return count;
}

void coloredCoordinates(){
//int width = getSize().width;
//int height = getSize().height;

xscale= (xmax - xmin)/width;
yscale = (ymax - ymin)/height;


for (int x = 0 ;x<width;x++) {
x=(int)(xmin+ (x*xscale)) ;
for (int y =0 ; y<height;y++) {

y= (int)(ymin + (y*yscale));
int index = caliter();

setPixel(offscreen ,x,y,index);
}
}
}

void setPixel( Graphics g,int x, int y,int colour) {

g.setColor(Color.getHSBColor(colour,0f,1f));

g.fillRect( x, y, 1,1);

}


public void run()
{
//int width = getSize().width;
//int height = getSize().height;
Image im = createImage(width,height);
offscreen = im.getGraphics();

offscreen.setColor(Color.white);
offscreen.fillRect(0,0,width,height);


coloredCoordinates();

repaint();


}
}

public static void main (String[] args) {

try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());


catch (Exception e) {}

display application = new display();
application.show();

application.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE) ;

}
}


i'd appreciate
reply
    Bookmark Topic Watch Topic
  • New Topic