Mit Hilfe des folgenden Java-Schnipsels kann eine beliebige Juliamenge in Schwarz-Weiss dargestellt werden. Für die Kompilierung des hier vorliegenden Quelltextes wird allerdings das Java Utility Package von Aegidius Plüss benötigt.
Dazugehörender Artikel: Darstellung einer Julia- und Mandelbrotmenge mittels Java
import ch.aplu.util.*;
import java.awt.Color;
/**
* This class draws a Julia set.
*
* Requires: Java Utility Package
* http://www.aplu.ch/home/apluhomex.jsp?site=65
*
* Author: Pascal Hollenstein <webmaster@zockerade.com>
* Version: 1.0
*/
class JuliaSet {
/**
* The maximum window coordinate for GPanel.
*/
int max = 15;
/**
* The minimum window coordinate for GPanel.
*/
int min = -15;
/**
* Builds a new window with the given name and coordinates.
*/
GPanel window = new GPanel("JuliaSet", min, max, min, max);
/**
* The real part of the result after each iteration step.
*/
double result_real;
/**
* The imaginary part of the result after each iteration step.
*/
double result_imaginary;
/**
* The real part of the constant "c".
*/
double c_real = 0.378;
/**
* The imaginary part of the constant "c".
*/
double c_imaginary = 0.325;
/**
* The constructor of this class.
*
* @see #iteration_step(double, double)
* @see #iteration()
* @see #get_length(double, double)
*/
JuliaSet() {
for (double i = min; i <= max; i = i + 0.05) {
for (double j = min; j <= max; j = j + 0.05) {
double x_coord = i * 0.1;
double y_coord = j * 0.1;
iteration_step(x_coord, y_coord);
iteration();
if (get_length(x_coord, y_coord) < 20) {
window.color(Color.black);
} else {
window.color(Color.white);
}
window.point(i, j);
}
}
}
/**
* This procedure calculates the result of each iteration step.
*
* @param number_1 The real part of the number.
* @param number_2 The imaginary part of the number.
*/
void iteration_step(double number_1, double number_2) {
result_real = (Math.pow(number_1, 2) - Math.pow(number_2, 2)) + c_real;
result_imaginary = (2 * number_1 * number_2) + c_imaginary;
}
/**
* This procedure iterates the calculation.
*
* @see #iteration_step(double, double)
*/
void iteration() {
for (int i = 1; i <= 50; i++) {
iteration_step(result_real, result_imaginary);
}
}
/**
* This method calculates the line segment between a
* complex number and its figure.
*
* @param number_1 The real part of the number.
* @param number_2 The imaginary part of the number.
*
* @return The distance between a complex number
* and its figure as double.
*/
double get_length(double number_1, double number_2) {
return Math.sqrt(
Math.pow(result_real - number_1, 2) +
Math.pow(result_imaginary - number_2, 2)
);
}
/**
* The main procedure.
*
* @param args The command line parameters.
*/
public static void main(String[] args) {
new JuliaSet();
}
}