whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

26 Visitors Online


 
...Draw the Mandelbrot Fractal?
Autor: Max Kleiner
Homepage: http://max.kleiner.com
[ Print tip ]  

Tip Rating (30):  
     




procedure DrawMandelbrot(ACanvas: TCanvas; X, Y, au, bu: Double; X2, Y2: Integer);
var
  
c1, c2, z1, z2, tmp: Double;
  i, j, Count: Integer;
begin
  
c2 := bu;
  for i := 10 to X2 do 
  begin
    
c1 := au;
    for j := 0 to Y2 do 
    begin
      
z1 := 0;
      z2 := 0;
      Count := 0;
     {count is deep of iteration of the mandelbrot set
      if |z| >=2 then z is not a member of a mandelset}
      
while (((z1 * z1 + z2 * z2 < 4) and (Count <= 90))) do 
      begin
        
tmp := z1;
        z1 := z1 * z1 - z2 * z2 + c1;
        z2 := 2 * tmp * z2 + c2;
        Inc(Count);
      end;
      //the color-palette depends on TColor(n*count mod t)
      {$IFDEF LINUX}
      
ACanvas.Pen.Color := (16 * Count mod 255);
      ACanvas.DrawPoint(j, i);
      {$ELSE}
      
ACanvas.Pixels[j, i] := (16 * Count mod 255);
      {$ENDIF}
      
c1 := c1 + X;
    end;
    c2 := c2 + Y;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  
R: TRect;
  au, ao: Integer;
  dX, dY, bo, bu: Double;
begin
  
// Initialize Mandelbrot
  
R.Left := 0;
  R.Right := 200;
  R.Top := 0;
  R.Bottom := 205;
  ao := 1;
  au := -2;
  bo := 1.5;
  bu := -1.5;
  //direct scaling cause of speed
  
dX := (ao - au) / (R.Right - R.Left);
  dY := (bo - bu) / (R.Bottom - R.Top);
  DrawMandelbrot(Self.Canvas, dX, dY, au, bu, R.Right, R.Bottom);
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners