stom66

Tabletop Simulator Circle Vector Plotter

Apr 23rd, 2019 (edited)
2,439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. //
  2. // This code was written by stom (not davema, who reposted it).
  3. // For more TTS scripts and mods, see my workshop page: https://steamcommunity.com/id/st0m/myworkshopfiles/
  4. //
  5.  
  6.  
  7. function onLoad()
  8.     circle = {
  9.         color             = {0, 0.8, 0.4}, --RGB color of the circle
  10.         radius            = 5,           --radius of the circle around the object
  11.         show              = false,       --should the circle be shown by default?
  12.         steps             = 32,          --number of segments that make up the circle
  13.         thickness         = 0.25,         --thickness of the circle line
  14.         vertical_position = 1,           --vertical height of the circle relative to the object
  15.     }
  16. end
  17.  
  18. function onDrop()
  19.     if circle then toggleCircle() end
  20. end
  21.  
  22. function toggleCircle()
  23.     circle.show = not circle.show
  24.     if circle.show then
  25.         self.setVectorLines({
  26.             {
  27.                 points    = getCircleVectorPoints(circle.radius, circle.steps, circle.vertical_position),
  28.                 color     = circle.color,
  29.                 thickness = circle.thickness,
  30.                 rotation  = {0,0,0},
  31.             }
  32.         })
  33.     else
  34.         self.setVectorLines({})
  35.     end
  36. end
  37.  
  38. function getCircleVectorPoints(radius, steps, y)
  39.     local t = {}
  40.     local d,s,c,r = 360/steps, math.sin, math.cos, math.rad
  41.     for i = 0,steps do
  42.         table.insert(t, {
  43.             c(r(d*i))*radius,
  44.             y,
  45.             s(r(d*i))*radius
  46.         })
  47.     end
  48.     return t
  49. end
Add Comment
Please, Sign In to add comment