Re: xor_line

new topic     » topic index » view thread      » older message » newer message

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'

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu