Home > Programming > Fractals > Cloud |
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 Cloud(ABitmap: TBitmap);
{ compute and display Julia set of function
f(z) = z^2 -0.194 + 0.6557i
}
var
i, j : integer;
{ loop variables}
scale : double;
{ scale factor }
mag : double;
{ square of
magnitude of complex number }
iter : integer;
{ escape iteration counter }
continue : boolean; { continue iteration counter }
x,y : double;
{ double and
complex parts of z }
MaxColor : integer; { maximum number of colors on graphics card }
LightColor,
DarkColor : TColorRef;
Rect : TRect;
MaxX,
MaxY : integer;
MaxY2 : integer;
zoom,
ixScale,
jyScale : double;
begin
SetRect(Rect, 0, 0,
ABitmap.Width, ABitmap.Height);
with Rect do
begin
MaxX := right - left;
MaxY := bottom - top; { find
maximum Y coordinate }
if (MaxX=0) or (MaxY=0) then exit;
MaxY := Max(MaxX,MaxY);
bottom := top + MaxY;
right := left + MaxY;
MaxColor := 15;
{
Maximum number of colors }
zoom:=1.5;
{ create 3 by 3 window }
scale:= 2.0*zoom/MaxY;
{ calculate zoom factor}
LightColor := ABitmap.Canvas.Pen.Color;
DarkColor := RGB(max(GetRValue(ABitmap.Canvas.Pen.Color)-64,0), {Get
dark color }
max(GetGValue(ABitmap.Canvas.Pen.Color)-64,0),
max(GetBValue(ABitmap.Canvas.Pen.Color)-64,0));
MaxY2 := MaxY div 2;
ixScale := 0;
for i := 0 to MaxY2 do
begin
jyScale := 0;
for j := 0 to MaxY 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.194,0.6557,x,y); { add constant }
mag := x*x+y*y;
{
calculate square of magnitude }
if
mag < attract then
continue :=
false { point is an attractor
}
else
if (mag <
100) AND (iter <
MaxColor*2) then { keep iterating function }
inc(iter)
else
{ point escapes, plot it }
begin
case iter
div 2 of
15 : begin
ABitmap.Canvas.Pixels[i+left,j+top] := LightColor;
ABitmap.Canvas.Pixels[right-i,bottom-j] := LightColor;
end;
14 : begin
ABitmap.Canvas.Pixels[i+left,j+top] := DarkColor;
ABitmap.Canvas.Pixels[right-i,bottom-j] := DarkColor;
end
end;
continue :=
false { get out of loop
}
end;
end;
{ while loop}
jyScale := jyScale + scale;
end; {j loop}
ixScale := ixScale + scale;
end{ i
loop}
end;
end;
////////////////////////////////////////////////////////////////////////////////
� 2004 Jim Valavanis