Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.63 KB | None | 0 0
  1.  
  2. function polygon( x, y, radius, sides, rotation)
  3.     local triangles = {}; //each triangle holds 3 points. each point is {x,y}
  4.     rotation = rotation or 0;
  5.    
  6.     for i=0, 360, 360/sides do
  7.        
  8.         local p1,p2,p3 = {},{},{};
  9.        
  10.         p1[0] = x + math.cos(i/360 + rotation) * radius;
  11.         p1[1] = y + math.sin(i/360 + rotation) * radius;
  12.        
  13.         p2[0] = x;
  14.         p2[1] = y;
  15.        
  16.         p3[0] = x + math.cos((i+360/sides)/360 + rotation) * radius;
  17.         p3[1] = y + math.sin((i+360/sides)/360 + rotation) * radius;
  18.        
  19.         local tri = {p1,p2,p3};
  20.         table.insert(triangles, tri);
  21.        
  22.     end
  23.    
  24.     for k,v in pairs(triangles) do
  25.        
  26.         //Draw your polygon.
  27.        
  28.     end
  29. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement