package view;
/**
*@author theGregg
*/
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Fraktal extends Frame {
public static final double akzeptanz = 2; //Ab wann Zn gegen Unendlich
private static final int height = 600; //Fensterhöhe
private static final int width = 800; //Fensterbreite
public Graphics graph; //Grafikkontext des Frames
public Fraktal() {
super("Fraktale");
this.setSize(width,height);
this.setResizable(false);
this.setVisible(true);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
graph = this.getGraphics();
paint(graph);
}
public static void main(String[] args) {
Fraktal mainFrame = new Fraktal();
System.out.println("fertig");
}
public void paint(Graphics g) {
for(int j = 0; j < height; j++) {
for(int i = 0; i < width; i++) {
int a = getFraktalColor(i,j);
graph.setColor(new Color(a,a,a));
graph.drawLine(i,j,i,j);
}
}
graph.setColor(new Color(0,0,0));
//graph.drawLine(0,height/2,800,height/2); //Koordinaten
//graph.drawLine(width/2,0,width/2,600); //Koordinaten
}
public int getFraktalColor(int posX,int posY) {
double reC = (double)(posX-400)/400;
double imC = (double)(posY-300)/300;
double re = 0;
double im = 0;
//System.out.println(re + " - "+im); //ist gut so --> wird nicht gerundet..
/*
* z^2 = (a+bi)^2 = a^2 - b^2 + 2abi
*
* */
for(int i = 0; i<100; i++) {
double a = re*re - im*im;
im = 2*re*im;
re = a;
re += reC;
im += imC;
/*
* gute parameter sind:
* re += 0.33;
* im += 0.4;
* herumspielen mit den hinteren komma-stellen eignet sich am besten
*
* public static final double akzeptanz zwischen 3 und 1/3
*/
}
double distance = Math.sqrt(im*im + re*re);
if(distance<akzeptanz) {
return 0;
//return (255-(int)(distance*255/akzeptanz));
} else {
return 255;
}
}
}