stom66

Tabletop Simulator Circle Vector Plotter

Apr 23rd, 2019
1,315
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function onLoad()
  2.     circle = {
  3.         color             = {0, 0.8, 0.4}, --RGB color of the circle
  4.         radius            = 5,           --radius of the circle around the object
  5.         show              = false,       --should the circle be shown by default?
  6.         steps             = 32,          --number of segments that make up the circle
  7.         thickness         = 0.25,         --thickness of the circle line
  8.         vertical_position = 1,           --vertical height of the circle relative to the object
  9.     }
  10. end
  11.  
  12. function onDrop()
  13.     if circle then toggleCircle() end
  14. end
  15.  
  16. function toggleCircle()
  17.     circle.show = not circle.show
  18.     if circle.show then
  19.         self.setVectorLines({
  20.             {
  21.                 points    = getCircleVectorPoints(circle.radius, circle.steps, circle.vertical_position),
  22.                 color     = circle.color,
  23.                 thickness = circle.thickness,
  24.                 rotation  = {0,0,0},
  25.             }
  26.         })
  27.     else
  28.         self.setVectorLines({})
  29.     end
  30. end
  31.  
  32. function getCircleVectorPoints(radius, steps, y)
  33.     local t = {}
  34.     local d,s,c,r = 360/steps, math.sin, math.cos, math.rad
  35.     for i = 0,steps do
  36.         table.insert(t, {
  37.             c(r(d*i))*radius,
  38.             y,
  39.             s(r(d*i))*radius
  40.         })
  41.     end
  42.     return t
  43. end
RAW Paste Data