const MaxIt = 400;
function getRe(pixel, ReMin, ReMax): real;
begin
result := ( Pixel / (abs(ReMin) + abs(ReMax)) ) + ReMin;
end;
function getIm(Pixel, ImMin, ImMax): real;
begin
result := ( Pixel / (abs(ImMin) + abs(ImMax)) ) - ImMin;
end;
function CalcMandel(xc, yc: real; xalt: real = 0; yalt: real = 0; recurs: integer = 0): integer;
var
x, y: real;
begin
x := xalt*xalt - yalt*yalt + xc;
y := 2 * xalt * yalt + yc;
if (xalt*xalt + yalt*yalt < 4)
and (recurs < MaxIt)
then
result := CalcMandel(xc, yc, x, y, recurs+1)
else
result := recurs;
end;
procedure PaintMandelOnCanvas(ReMin, ReMax, ImMin, ImMax: Real; Canv: TCanvas);
var
xc, yc: real;
n, i, j: integer;
begin
for i := 0
to 800
do
for j := 0
to 600
do
begin
xc := getRe(i, ReMin, ReMax);
yc := getIm(j, ImMin, ImMax);
n := calcmandel(xc, yc);
if n = MaxIt
then
Canv.Pixel[i, j] := clblack
else
//Färb je nach erreichter Iteration, veränderbar
Canv.Pixel[i, j] :=
RGB(n, n
div 2, (n+100)/3);
end;
end;