Home > Programming > Fractals > Ameboa |
const
escape=4.0;
{ escape value }
attract=0.0001;
{
attractor sensitivity }
const
Black = 0;
Blue = 1;
Green = 2;
Cyan = 3;
Red = 4;
Magenta = 5;
Brown = 6;
LightGray = 7;
DarkGray = 8;
LightBlue = 9;
LightGreen =10;
LightCyan =11;
LightRed =12;
LightMagenta =13;
Yellow =14;
White =15;
function GetRGBColor(color:byte):longint;
begin
case Color of
black : GetRGBColor := RGB(0,0,0);
blue : GetRGBColor := RGB(0,0,128);
green : GetRGBColor := RGB(0,128,0);
cyan : GetRGBColor := RGB(0,255,255);
red : GetRGBColor := RGB(128,0,0);
magenta : GetRGBColor := RGB(128,0,128);
brown : GetRGBColor := RGB(128,128,0);
lightgray : GetRGBColor := RGB(192,192,192);
darkgray : GetRGBColor := RGB(128,128,128);
lightBlue : GetRGBColor := RGB(0,0,255);
lightGreen : GetRGBColor := RGB(0,255,0);
lightcyan : GetRGBColor := RGB(0,255,255);
lightRed : GetRGBColor := RGB(255,0,0);
lightmagenta : GetRGBColor := RGB(255,0,255);
yellow: GetRGBColor := RGB(255,255,0);
white : GetRGBColor := RGB(255,255,255);
else
GetRGBColor := RGB(0,0,255);
end;
end;
////////////////////////////////////////////////////////////////////////////////
procedure Ameboa(ABitmap: TBitmap);
var
i, j : integer;
{ loop variables}
zoom : double;
MaxX,
MaxY : integer; { Maximum Y coordinate}
MaxY2 : integer;
scale : double;
{ scale factor }
mag : double;
{ square of
magnitiude of complex number }
iter : integer;
{ escape iteration counter
}
continue : boolean; { continue iteration counter }
x,y : double;
{ double and
complex parts of z }
MaxColor : byte;
{ maximum
number of colors }
MaxColor2 : byte;
curColor : TColorRef;
Rect: TRect;
color : byte;
ixScale,
jyScale : double;
ColorLimit : integer;
begin
SetRect(Rect, 0, 0,
ABitmap.Width, ABitmap.Height);
with Rect do
begin
zoom := 2.0;
MaxY := bottom - top; {
find maximum Y coordinate }
MaxX := right - left;
if (MaxX=0)
or (MaxY=0) then exit;
MaxX := Max(MaxX,MaxY);
MaxY := MaxX;
right := left + MaxX;
bottom := top + MaxY;
MaxY2 := MaxY div 2;
if MaxY<100
then
MaxColor := 5
else if MaxY<200 then
MaxColor := 8
else
MaxColor := 15; { Maximum number of colors }
MaxColor2 := MaxColor*2;
scale:= 2.0*zoom/MaxY; { calculate zoom factor}
ixScale := 0;
ColorLimit := 0;
for i := 0 to MaxX do { MaxY is usually smaller than MaxX }
begin
j := 0;
jyScale := 0;
while j<= MaxY2 do
begin
x := ixScale-zoom;
{
set starting value of double(z) }
y := zoom-jYScale;
{
set starting value of imag(z) }
continue := TRUE;
{ assume point does not escape }
iter :=0;
while continue
do
begin
mult(x,y,x,y,x,y);
{ square z }
add(x,y,0.3,-0.4,x,y); { add 0.3 -0.4i }
mag := x*x+y*y;
{
calculate square of magnitude }
if
mag < attract then
continue :=
false { point is an attractor
}
else
begin
if (mag <
100) and (iter <
MaxColor2) then { keep
iterating function }
inc(iter)
else
{ point escapes, plot it }
begin
color
:= iter div 2;
if color > colorLimit then
begin
if
color = MaxColor then
CurColor
:= RGB(255,255,255)
else
CurColor
:= GetRGBColor(color);
ABitmap.Canvas.Pixels[i
+ Left,j+top] := curColor;
ABitmap.Canvas.Pixels[right-i,bottom-j]
:= curColor;
end;
continue :=
false; { get out of
loop }
end;
end;
end; { while loop}
inc(j);
jyScale := jYScale + scale;
end; {j loop}
ixScale := ixScale + scale;
end;{ i
loop}
end;
end;
////////////////////////////////////////////////////////////////////////////////
� 2004 Jim Valavanis