Delphi Tutorial


 

Draw spiral

 

Download this example

               Use following ButtonClick event to draw spiral.

procedure TForm1.Button1Click(Sender: TObject);
      

      Procedure SpiralDraw(Count:Integer);
      var
            cs, co, sn, si, cx, cy, x, y, ad, sf, xo: real;
            Counter:Integer;
            j, i: byte;
            xp, yp, color: Integer;
      begin
            cs := Cos(pi / 3);
            co := Cos(pi / 36);
            sn := Sin(pi / 3);
            si := Sin(pi / 36);
            cx := Round(Form1.Width/2);
            cy := Round(Form1.Height/2);
            ad := 1.16;
            sf := 1.06;
            Color:=20200;
            Counter:=0;
            xp := trunc(cx + 12 * ad);
            yp := trunc(cy + 0);
            Form1.Canvas.MoveTo(Xp,Yp);
            repeat
                  Inc(Counter);
                  x := 12;
                  y := 0;
                  For j := 0 to 70 do begin
                        For i := 0 to 6 do begin
                              Form1.Canvas.Pen.Color:=Color;
                              Color:=Color+1;
                              xp := trunc(cx + x * ad);
                              yp := trunc(cy + y);
                              If (i = 0) Then                                     Form1.Canvas.MoveTo(xp, yp);
                              Form1.Canvas.LineTo(xp, yp);
                              xo := x * cs - y * sn;
                              y := x * sn + y * cs;
                              x := xo;
                        End;
                        xo := sf * (x * co - y * si);
                        y := sf * (x * si + y * co);
                        x := xo;
                  End;
            until Counter>Count;
      End;

begin
      SpiralDraw(500);
end;

 

DOWNLOAD this example

Click here to download this complete example for Delphi 6. (File size 4KB)

 

 

Go top

 


Previous Page First Page Next Page
 
Copyright © 2002 digitalcoding.com. All rights reserved.