Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function polygon( x, y, radius, sides, rotation)
- local triangles = {}; //each triangle holds 3 points. each point is {x,y}
- rotation = rotation or 0;
- for i=0, 360, 360/sides do
- local p1,p2,p3 = {},{},{};
- p1[0] = x + math.cos(i/360 + rotation) * radius;
- p1[1] = y + math.sin(i/360 + rotation) * radius;
- p2[0] = x;
- p2[1] = y;
- p3[0] = x + math.cos((i+360/sides)/360 + rotation) * radius;
- p3[1] = y + math.sin((i+360/sides)/360 + rotation) * radius;
- local tri = {p1,p2,p3};
- table.insert(triangles, tri);
- end
- for k,v in pairs(triangles) do
- //Draw your polygon.
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement