Home > Programming > Fractals > Siegel

 Previous Next

```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 Siegel(ABitmap: TBitmap); { compute and display a Siegel disk -- the Julia set of f(z) = z^2 -0.39054 -0.58679i } var    i, j      : integer;       { loop variables}    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;          { real and complex parts of z }    MaxColor  : byte;          { maximum number of colors }    MaxColor2 : byte;    curColor   : TColorRef;    Rect: TRect;    color      : byte;    zoom,    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;     MaxColor := 15; { Maximum number of colors }     MaxColor2 := MaxColor*2;     scale:= 2.0*zoom/MaxY;   { calculate zoom factor}     colorLimit := -1;     ixScale := 0;     for i := 0 to MaxX do    { MaxY is usually smaller than MaxX }     begin       jyScale := 0;       for j := 0 to MaxY2 do       begin         x := ixScale-zoom;             { set starting value of real(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.390540,-0.58679,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 < MaxColor2) then { keep iterating function }               inc(iter)             else                      { point escapes, plot it }             begin               color := iter div 2;               if color>colorLimit then               begin                 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;  { while loop}         jyScale := jyScale + scale;       end;  {j loop}       ixScale := ixScale + scale;     end;{ i loop}   end; end; //////////////////////////////////////////////////////////////////////////////// ```

© 2004 Jim Valavanis

 Previous Next