Board index » delphi » Drawing a circle, pixel by pixel
Finn Tolderlund
![]() Delphi Developer |
Mon, 04 Apr 2005 18:37:00 GMT
|
Finn Tolderlund
![]() Delphi Developer |
Mon, 04 Apr 2005 18:37:00 GMT
Drawing a circle, pixel by pixel
Search Google for Bresenham's circle algorithm.
It's very fast and doesn't have that problem. -- Finn Tolderlund "Jon Lennart Berg" <jon...@c2i.net> wrote in message Quote> For some time now i have been using the following routine to calculate a |
Finn Tolderlun
![]() Delphi Developer |
Tue, 05 Apr 2005 15:02:53 GMT
Re:Drawing a circle, pixel by pixelBy the way: The problem with your old procedure is that you always draw 360 pixels (for x:=0 to 359 do) nomatter how big or small the circle is. This means that for small circles you draw too many pixels and for large circles you draw too few pixels. -- Finn Tolderlund "Jon Lennart Berg" <jon...@c2i.net> wrote in message Quote> Thanks! |
Finn Tolderlun
![]() Delphi Developer |
Tue, 05 Apr 2005 22:55:02 GMT
Re:Drawing a circle, pixel by pixelSince the formula for a circle's circumference is 2*Radius*Pi you have draw 2*Radius*Pi pixels. This means that your old procedure should be changed to something like this: procedure Circle(xStart, yStart, Radius: Integer; Canvas: TCanvas; Color: TColor); var {x,}xpos,ypos: Integer; Pix, Pixels: Integer; x: Real; begin Pixels := Round(2* Radius * Pi); //for x:=0 to 359 do for pix := 0 to Pixels-1 do begin x := 360 * pix / Pixels; {calculate a value of 0-359} xpos:=(round(xStart + sin(x*pi/180)*radius)); ypos:=(round(yStart + cos(x*pi/180)*radius)); Canvas.Pixels[xpos,ypos] := Color; end; end; -- Finn Tolderlund "Jon Lennart Berg" <jon...@c2i.net> skrev i en meddelelse Quote> I figured that, but i was unsure about what values i should place there. |
Remco de Kort
![]() Delphi Developer |
Wed, 06 Apr 2005 19:01:22 GMT
Re:Drawing a circle, pixel by pixelQuoteFinn Tolderlund wrote: Canvas: TCanvas; Color: TColor); This way you can use the canvas pen width in your drawing Remco |
Bart Thoma
![]() Delphi Developer |
Wed, 20 Apr 2005 02:24:37 GMT
Re:Drawing a circle, pixel by pixelOkay, a bit late, but: procedure MidPointCircle(iBitmap: TBitmap; iX, iY, iRadius: integer; iValue: procedure CirclePoints(iOriginX,iOriginY,iX, iY: integer; iValue: TColor); var { Introduction to computer graphics (Foley, van Dam, Feiner, Hughes, CirclePoints (iX,iY, x,y, iValue); while (y > x) do "Remco de Korte" <re...@onwijs.com> wrote in message Quote> Finn Tolderlund wrote: |