no more gaps...
Hawke,
Half of your circles will have gaps at 45 degrees, because the 15th line in
your true_circle() code should be
while y >= x do ....
Below is a cleaner and I suspect much faster version of filled_circle().
jiri
ps. Btw, what's the reason for the perverse reverse order of arguments in
your true_pixel()? Very confusing!
procedure filled_circle(integer x, integer y, integer r, object c)
-- draw filled circle with centre coordinates xy, radius r & color c
integer d,m,n,u,v
-- initialize
d=3-2*r
u=0
v=r
pixel(repeat(c,2*r+1),{x-r,y})
while u<v do
if d<0 then
d=d+4*u+6
else
d=d+4*(u-v)+10
pixel(repeat(c,2*u+1),{x-u,y-v})
pixel(repeat(c,2*u+1),{x-u,y+v})
v=v-1
end if
u=u+1
pixel(repeat(c,2*v+1),{x-v,y-u})
pixel(repeat(c,2*v+1),{x-v,y+u})
end while
end procedure
-----Original Message-----
From: Hawke <mdeland at NWINFO.NET>
To: EUPHORIA at LISTSERV.MUOHIO.EDU <EUPHORIA at LISTSERV.MUOHIO.EDU>
Date: Monday, October 26, 1998 2:25 AM
Subject: Re: xor_line
>Hawke wrote:
>>>i've been goofing around with bresenham's circle algorithm...
>>>it seems to miss a couple dots around the circle...
>
>Ad Rienks wrote:
>>I think I know the reason: look at the round() function
>>you posted the other day.
>> Hope this helps
>well, heh, bresenham's algorithms don't use round...
>but!, thanks for spotting a potential defect in round() :)
>
>here is the adaptation of bresenham's circle
>algorithm i've been playing with:
>-------------begin code
>
>procedure true_plot4(sequence cntr, integer x,
> integer y, sequence clr)
>--this is the 'negating' part of the algorithm
> true_pixel( cntr + { x, y}, clr ) --behaves just like
> true_pixel( cntr + { x,-y}, clr ) --pixel() in EU
> true_pixel( cntr + {-x, y}, clr )
> true_pixel( cntr + {-x,-y}, clr )
>end procedure
>
>global procedure true_circle(sequence cntr, integer rad, sequence clr)
>--Bresenham's algorithm for circles, interpreted for truecolor
>--with optimizations for speed
>--based upon the premise that a circle is symmetric every 45
>--degrees which means you only calculate 0..45 and plot the
>--other 8 segments via x,y flipping and negating
>--cntr=center, rad=radius, clr=BGR color value {B,G,R}
>integer x,y,d,tmp
>
> x = 0
> y = rad
> d = 3 - rad
> d = d - rad
>
> while y > x do
> --Draw the 8 circle pixels
> true_plot4( cntr, x, y, clr) --this is the flipping
> true_plot4( cntr, y, x, clr) --part of the algorithm
> if d < 0 then
> --d = d + (4 * x) + 6
> tmp = x * 4
> d = d + tmp
> d = d + 6
> else
> --d = d + 4 * (x - y) + 10
> tmp = x - y
> tmp = tmp * 4
> d = d + tmp
> d = d + 10
> y = y - 1
> end if
> x = x + 1
> end while
>end procedure
>
>-------------end code
>
>when i do something like:
> for r=1 to 50 do
> --plot a bright green circle, near mid screen
> true_circle({320,240},r,{100,200,100})
> end for
>well, it's like a filled, 100pixel diameter circle, but
>there are 'spots' in it... now, if you don't wanna run
>this code in truecolor, just change the 4 lines in
>true_plot4, alter the arguments for color (clr) to
>accept integers and test away...
>
>*watches thinking caps begin to smolder*
>--Hawke'
>
|
Not Categorized, Please Help
|
|