Skip to content

Instantly share code, notes, and snippets.

@kuccello
Last active September 5, 2015 18:43
Show Gist options
  • Select an option

  • Save kuccello/9c6fefb2df5cac1f9b64 to your computer and use it in GitHub Desktop.

Select an option

Save kuccello/9c6fefb2df5cac1f9b64 to your computer and use it in GitHub Desktop.
function roundm(n, m) return math.floor(((n + m - 1)/m))*m end
-- Now we can change the returned value from getRandomPointInCircle to:
function getRandomPointInCircle(radius)
local t = 2*math.pi*math.random()
local u = math.random()+math.random()
local r = nil
if u > 1 then r = 2-u else r = u end
return roundm(radius*r*math.cos(t), tile_size),
roundm(radius*r*math.sin(t), tile_size)
end
function getRandomPointInEllipse(ellipse_width, ellipse_height)
local t = 2*math.pi*math.random()
local u = math.random()+math.random()
local r = nil
if u > 1 then r = 2-u else r = u end
return roundm(ellipse_width*r*math.cos(t)/2, tile_size),
roundm(ellipse_height*r*math.sin(t)/2, tile_size)
end
@kuccello
Copy link
Copy Markdown
Author

kuccello commented Sep 5, 2015

@kuccello
Copy link
Copy Markdown
Author

kuccello commented Sep 5, 2015

@kuccello
Copy link
Copy Markdown
Author

kuccello commented Sep 5, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment