Hallo zusammen,
ich habe eine Aufgabe bekommen, in der man ein Mandelbrot mit BigDecimal einsetzen und viele komplexer Zeuge wie z.B. Iterator anwenden muss. Ich benötige wieder eure Hilfsstellung.
Leider hat es bei mir nicht geklappt. Mein Bigdecimal-Mandelbrot ist so schüchtern, lässt sich nicht in der UI anzeigen:
Anbei mein Code. Ich habe stundenlang probiert um ImageView/Image umzusetzen oder neu schreiben usw, hat nichts mir geholfen. Wäre schön, wenn jemand mir Tipps geben kann.
ich habe eine Aufgabe bekommen, in der man ein Mandelbrot mit BigDecimal einsetzen und viele komplexer Zeuge wie z.B. Iterator anwenden muss. Ich benötige wieder eure Hilfsstellung.
Leider hat es bei mir nicht geklappt. Mein Bigdecimal-Mandelbrot ist so schüchtern, lässt sich nicht in der UI anzeigen:
Anbei mein Code. Ich habe stundenlang probiert um ImageView/Image umzusetzen oder neu schreiben usw, hat nichts mir geholfen. Wäre schön, wenn jemand mir Tipps geben kann.
Java:
Public class MainKlasse{
public void start(Stage stage) {
BorderPane root = new BorderPane();
/*
Dazwischen gibt es Zeilen für UI-Komponenten wie z.B. Labels, Statusbar, Textfeld
*/
//Mandelbrot-Image abrufen
Image bigdecimalMandelbrotImage = createBigDecimalMandelBrot();
ImageView imgView = new ImageView(bigdecimalMandelbrotImage);
//Mandelbrot anzeigen lassen
root.setCenter(imgView);
root.setBottom(statusBar);
Scene scene = new Scene(root, WIDTH, 1000);
stage.setScene(scene);
stage.setTitle("Mandelbrot Canvas");
stage.show();
stage.setOnCloseRequest(we -> System.out.println("Closing application!"));
}
}
}
public class FractalTestResult{
/*andere variablen, methoden usw*/
}
class MandelbrotIterator implements Iterator<FractalTestResult> {
public static final int WIDTH = 640;
public static final int HEIGHT = 480;
public static final double MAX_ITERARIONS = 50;
private static final double REAL_MIN = -2.0;
private static final double REAL_MAX = 2.0;
private static final double IMAGINARY_MIN = -2.0;
private static final double IMAGINARY_MAX = 2.0;
private final Complex min;
private final Complex max;
private final int maxIterations;
private final Arithmetics arithmetic;
private int currentX;
private int currentY;
public MandelbrotIterator(Complex min, Complex max, int maxIterations, Arithmetics arithmetic) {
this.min = min;
this.max = max;
this.maxIterations = maxIterations;
this.arithmetic = arithmetic;
this.currentX = 0;
this.currentY = 0;
}
@Override
public boolean hasNext() {
return currentX < WIDTH && currentY < HEIGHT;
}
@Override
public FractalTestResult next() {
double realStep = (REAL_MAX - REAL_MIN) / WIDTH;
double imaginaryStep = (IMAGINARY_MAX - IMAGINARY_MIN) / HEIGHT;
if (!hasNext()) {
throw new NoSuchElementException("keine Elementen in der Iteration mehr");
}
BigDecimal real = BigDecimal.valueOf(REAL_MIN + currentX * realStep);
BigDecimal imaginary = BigDecimal.valueOf(IMAGINARY_MIN + currentY * imaginaryStep);
Complex c = new Complex(real, imaginary);
boolean isPartOfMandelbrot = isPartOfMandelBrot(c);
currentX++;
if (currentX >= WIDTH) {
currentX = 0;
System.out.println("progress: " + String.valueOf(100.0* currentY / HEIGHT) + "%");
currentY++;
}
return new FractalTestResult(isPartOfMandelbrot ? maxIterations : 0);
}
private boolean isPartOfMandelBrot(Complex c) {
int maxIterations = 50;
Complex z = new Complex(BigDecimal.valueOf(0), BigDecimal.valueOf(0));
for (int i = 0; i < maxIterations; i++) {
z = z.mul(z).add(c);
if (z.abs().compareTo(BigDecimal.valueOf(2)) >= 0) { //was z2 as an arg
return false;
}
}
return true;
}
public int getCurrentX() {
return 50;
}
public int getCurrentY(){
return 50;
}
}