# Graphics2D Julia Set Applet

This is based on Pascal code for the Julia set for quadratic polynomials. From another page on the ThinkQuest website is this information: "The main difference between the Julia set and the Mandelbrot set is the way in which the function is iterated. The Mandelbrot set iterates z = z2 + c with z always starting at 0 and varying the c value. The Julia set iterates z = z2 + c for a fixed c value and varying z values. In other words, the Mandelbrot set is in the parameter space, or the c-plane, while the Julia set is in the dynamical space, or the z-plane." See our introduction to fractals from the Mandelbrot set.

In the code we recycle the colours, but you could easily extend the range with code such as setColor(new Color(80, 240, 60)), where you supply as parameters the red, green and blue components of each customised colour.

Remember that in Oxygene for Java, it is necessary to cast an Integer to a real number to prevent integer division from being carried out. e.g.
`za := (Double(i) / xsize) * (x2corner - xcorner) + xcorner;`

The code below generates the following graphic. A Julia set fractal from code below

It is interesting to change the values of variables. Changing ca to 0.4 resulted in this very different fractal. Julia set fractal with ca = 0.4

By changing instead the values of cornerx, connery, cornerx2 and cornery2 to -0.5, -0.5, 0.5 and 0.5, respectively, we obtained this close-up of a portion of the first graphic. Julia set fractal with corners set to -0.5 and +0.5

```namespace julia;

interface

uses
java.util,
java.applet.*,
java.awt.*;

type
private
xcorner, y2corner, x2corner, ycorner, ca, cb, za2, za1, za, zb : Double;
xsize, ysize, k, i, xgap, ygap, max, count : Integer;
public
method init; override;
method paint(g: Graphics); override;
method iterate;
end;
implementation

begin
count := 0;
za2 := za;
while true do
begin
za1 := za2;
za2 := (za1 * za1 - zb * zb) + ca;
zb := za1 * zb * 2 + cb;
if za2 * za2 + zb * zb > 4 then
exit;
count := count + 1;
if count > max  then
exit;
end;
end;

begin
xsize := getSize.width;
ysize := getSize.height;
xcorner := -1.5;
ycorner := -1.5;
x2corner := 1.5;
y2corner := 1.5;
max := 50;
xgap := 10;
ygap := 10;
ca := 0.360284; //Try ca := 0.365;
cb := 0.100376; //Try cb := 0.095;
end;

var
g2 : Graphics2D;
begin
g2 := Graphics2D(g);
for k := ysize downTo 1 do
for i := 1 to xsize do
begin
za := (Double(i) / xsize) * (x2corner - xcorner) + xcorner;
zb := (Double(k) / ysize) * (y2corner - ycorner) + ycorner;
iterate;
if count > max then
count := 0;
case count mod 10  of
0 : g2.setColor(Color.darkGray);
1 : g2.setColor(Color.red);
2 : g2.setColor(Color.orange);
3 : g2.setColor(Color.yellow);
4 : g2.setColor(Color.green);
5 : g2.setColor(Color.cyan);
6 : g2.setColor(Color.blue);
7 : g2.setColor(Color.magenta);
8 : g2.setColor(Color.black);
9 : g2.setColor(Color.white);
end;
g2.drawLine(xgap + i, ygap + ysize - k, xgap + i, ygap + ysize - k);
end;
end;

end.

```
Programming - a skill for life!

Applets using Graphics2D for transforms, gradient painting and pixel drawing in Oxygene for Java