I tried to make a temporary filled circle function until the next version of LuaZM comes out, but all it does is draws a box. Could someone help me out?


Code:

local function drawCircleFill(centerx, centery, radius, color)
   f = 1 - radius
   ddF_x = 1
   ddF_y = -2 * radius
   x = 0
   y = radius

   drawLine(centerx, centery + radius, centerx, centery - radius, color)
   drawLine(centerx + radius, centery, centerx - radius, centery, color)

   while x < y do
      if f >= 0 then
         y = y - 1
         ddF_y = ddF_y + 2
         f = f + ddF_y
      end

      x = x + 1
      ddF_x = ddF_x + 2
      
      drawLine(centerx + x, centery + y, centerx - x, centery + y, color)
      drawLine(centerx + x, centery - y, centerx - x, centery - y, color)
      drawLine(centerx + y, centery + x, centerx - y, centery + x, color)
      drawLine(centerx + y, centery - x, centerx - y, centery - x, color)
   end
end


Algorithm shamelessly stolen from _player1537
That's actually Bresenham's circle-drawing algorithm. I'd recommend checking against the original algorithm first:

http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement