Hey!
So, after reading another forum post, I realised that I might need to create a chain body for a circle in one of my projects at some point, so I decided to write a function for doing so and share it here.
Feel free to play around with the function and use it as you see fit. The function requires two inputs, r and n , where r stands for the circle radius and n stands for how many sides you want to create for the circle. The more sides, the more accurate the resulting circle will be. The function needs a minimum of 3 sides to work properly.
-- r = radius, n = number of sides local function circleVertices(r,n) if n \>= 3 then local mathCos, mathSin, pi = math.cos, math.sin, math.pi local angle = 360/n local v = {} for i = 1, n do v[i\*2-1] = mathCos(angle\*(i-1)\*(pi/180))\*r v[i\*2] = -1\*mathSin(angle\*(i-1)\*(pi/180))\*r end return v end end local t = circleVertices(120,32) local circle = display.newPolygon(240,160,t)
Finally, I’ve been thoroughly inspired by a few Corona developers, like roaminggamer and horacebury, who freely share numerous functions, modules and more on GitHub and I will very likely follow in suite and create myself a GitHub account and start sharing some more cool things with everyone.