J'essaye actuellement de coder un programme qui génère un ensemble mandelbrot. Cependant, même si j'ai fait beaucoup de tests avec chaque méthode unique. La forme de l'ensemble semble être fausse. Je cherche de l'aide et serait vraiment heureux si quelqu'un sait comment y remédier.Mandelbrot Set Wrong Shape
import java.awt.*;
import javax.swing.*;
public class MandelbrotMenge extends JComponent {
int WIDTH = 600;
int HEIGHT = 600;
static int n = 1; // anzahl iterationen
static double a; // reeller Anteil von komplexer Zahl
static double b; // imaginärer Anteil
public MandelbrotMenge(int p_n) {
setSize(WIDTH, HEIGHT);
n = p_n;
}
public static boolean isMandelbrot(double a_n, double b_n, int n) { // prüft
// ob
// komplexe
// zahl
// divergiert
a = a_n;
b = b_n;
double a2 ;
for (int i = 0; i < n; i++) {
a2 = a * a - b * b + a;
b = 2 * a * b + b;
a=a2;
if (a * a + b * b >= 4)
return false;
}
return true;
}
public static void zeichneMandelbrot(Graphics g,int n) {
for (int i = 100; i <= 600; i++) {
for (int j = 0; j <= 600; j++) {
// i ist pixel und j auch
// komplexe zahl:
a = -3 + 0.01 * i; // x min = -3 x max = 6 pixel =600 --> 0.01*i
b = 3 - 0.01 * j;
if (isMandelbrot(a, b, n)) {
g.setColor(Color.white);
} else {
g.setColor(Color.black);
}
g.drawLine(i, j, i, j);
}
}
}
protected void paintComponent(Graphics g) {
zeichneMandelbrot(g, n);
}
}
Les regards de forme (pas complètement) mal:
Quelle est la valeur de 'n' que vous utilisez? –