fatboychummy

Bresenham Circle Library

Apr 10th, 2020 (edited)
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None | 0 0
  1. --[[
  2.   Made by fatboychummy
  3.  
  4.   Edit, use, abuse, and program with anything you wish, Open Source is Open Source.
  5. ]]
  6.  
  7. local function displayBresenhamCircle(xc_, yc_, x, y, func)
  8.   func(xc_+x, yc_+y);
  9.   func(xc_-x, yc_+y);
  10.   func(xc_+x, yc_-y);
  11.   func(xc_-x, yc_-y);
  12.   func(xc_+y, yc_+x);
  13.   func(xc_-y, yc_+x);
  14.   func(xc_+y, yc_-x);
  15.   func(xc_-y, yc_-x);
  16. end
  17.  
  18. local function drawBresenhamCircle(radius_, xc, yc, func)
  19.   local x = 0
  20.   local y = radius_
  21.   local decisionParameter = 3 - 2 * radius_
  22.   displayBresenhamCircle(xc, yc, x, y, func)
  23.  
  24.   while y >= x do
  25.     x = x + 1
  26.     if decisionParameter > 0 then
  27.       y = y - 1
  28.       decisionParameter = decisionParameter + 4 * (x - y) + 10
  29.     else
  30.       decisionParameter = decisionParameter + 4 * x + 6
  31.     end
  32.     displayBresenhamCircle(xc, yc, x, y, func)
  33.   end
  34. end
  35.  
  36. return drawBresenhamCircle
Add Comment
Please, Sign In to add comment