Board index » delphi » Drawing Circles

Drawing Circles

On Mon, 27 Sep 1999 10:47:23 +1000, "Paul Nicholls"

Quote
<phan...@southcom.com.au> wrote:
>If anywone is interested here's a circle drawing algorithm I came up with (I
>believe it's the simplest one around?).

Why not just use TCanvas.Ellipse, or the Ellipse API function?

-Steve

 

Re:Drawing Circles


Steve, this routine is for someone who wants to do their own low-level
drawing and dispense with TCanvas.Ellipse or the API function perhaps for
speed or customization reasons :-)  It's also fun finding out how to do
certain functions/procedures yourself!

--
Paul Nicholls,
Live long and optimise.
--------------------------------
Web Page : www.southcom.com.au/~phantom
E-Mail        : phan...@southcom.com.au

Re:Drawing Circles


On Mon, 27 Sep 1999 12:41:35 +1000, "Paul Nicholls"

Quote
<phan...@southcom.com.au> wrote:
>perhaps for speed

Not to dissuade you, but I suspect the Ellipse function runs _much_
faster than yours, for a variety of reasons.

-Steve

Re:Drawing Circles


I did ask for a can of worms when asking for comments ;-)
Steve, I don't suppose you could tell me some of the reasons the Ellipse
function would run faster than mine? - not that I was really going for
speed, just simplicity at the time...
Apart from that, what do you think of my routine?

--
Paul Nicholls,
Live long and optimise.
--------------------------------
Web Page : www.southcom.com.au/~phantom
E-Mail        : phan...@southcom.com.au

Re:Drawing Circles


Quote
Paul Nicholls <phan...@southcom.com.au> wrote in message

news:7smejf$pt116@forums.borland.com...

Quote
> If anywone is interested here's a circle drawing algorithm I came up with (I
> believe it's the simplest one around?).
> Comments are welcome.

How does your algorithm compare to the Bresenham's circle drawing algorithm?

(There a link and some C code for Bresenham's circle drawing algorithm at
http://www.efg2.com/Lab/Library/Graphics.htm#Algorithms )

___
efg

Earl F. Glynn     E-Mail:  EarlGl...@att.net
Overland Park, KS  USA

efg's Computer Lab:  http://www.efg2.com/Lab

Re:Drawing Circles


After looking at the Bresenham algorithms [which I didn't really understand
:-) ], mine seemed simpler though maybe not as flexible...

--
Paul Nicholls,
Live long and optimise.
--------------------------------
Web Page : www.southcom.com.au/~phantom
E-Mail        : phan...@southcom.com.au

Re:Drawing Circles


On Mon, 27 Sep 1999 13:47:39 +1000, "Paul Nicholls"

Quote
<phan...@southcom.com.au> wrote:
>Steve, I don't suppose you could tell me some of the reasons the Ellipse
>function would run faster than mine?

Your function calls another function for every pixel to be painted.
There's a lot of overhead in that. The Ellipse function does
everything within the device driver itself.

-Steve

Re:Drawing Circles


As an exercise, I examined your code, and found the following optimizations.

Quote
>    value := value+(y shl 1)+1;

Use Inc(value,(y shl 1)+1);

and the same for x shl 1

Quote
>   value := value-(x shl 1)+1;

Dec(Value,(x shl 1) -1);

Quote
>    PlotPixel(xc+x,yc+y,Col);

should become PlotPixelQuad(xc,yc,col)

and PlotPixelQuad should use display all four points. Easier to use in the
code, and col only needs to be passed once.

Also xd:=xc+x; saves one calculation, etc.

--
Jon Perry
pe...@globalnet.co.uk
--

Quote
Paul Nicholls <phan...@southcom.com.au> wrote in message

news:7smejf$pt116@forums.borland.com...
Quote
> If anywone is interested here's a circle drawing algorithm I came up with
(I
> believe it's the simplest one around?).
> Comments are welcome.

> procedure PlotCircle(xc,yc,radius:Integer;Col:TColor);
> Var
>  x   : Integer;
>  y   : Integer;
>  value : Integer;
> Begin
>  y := 0;
>  value := 0;
>  For x := radius downto 0 do
>  Begin
>   While(Value<0)do
>   Begin
>    // PLOT PIXEL FOR EACH QAUDRANT; USE YOUR OWN PLOTTING ROUTINE
>    PlotPixel(xc+x,yc+y,Col);
>    PlotPixel(xc+x,yc-y,Col);
>    PlotPixel(xc-x,yc+y,Col);
>    PlotPixel(xc-x,yc-y,Col);
>    Inc(y);
>    value := value+(y shl 1)+1;
>   End;
>   value := value-(x shl 1)+1;
>   // PLOT PIXEL FOR EACH QAUDRANT; USE YOUR OWN PLOTTING ROUTINE
>   PlotPixel(xc+x,yc+y,Col);
>   PlotPixel(xc+x,yc-y,Col);
>   PlotPixel(xc-x,yc+y,Col);
>   PlotPixel(xc-x,yc-y,Col);
>  End;
> End;

> --
> Paul Nicholls,
> Live long and optimise.
> --------------------------------
> Web Page : www.southcom.com.au/~phantom
> E-Mail        : phan...@southcom.com.au

Re:Drawing Circles


Thanks for all the ideas guys :)

--
Paul Nicholls,
Live long and optimise.
--------------------------------
Web Page : www.southcom.com.au/~phantom
E-Mail        : phan...@southcom.com.au

Other Threads