Guest User

Untitled

a guest
Feb 22nd, 2023
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1.  
  2. --------------------------------------------------------
  3. --------------------------------------------------------
  4. -------------- 'MakeCurves' by StanSpook --------------
  5. --------------------------------------------------------
  6. --------------------------------------------------------
  7. Settings = {}
  8. Settings.Wave = 0 -- accuracy of the wave
  9. Settings.Offset = 10 -- the offset of the new points from the original point
  10. Settings.Start = 0 -- the point starting position
  11. local script = ofs.Script(ofs.ActiveIdx())
  12.  
  13. function init()
  14. -- this runs once at when loading the extension
  15. print "How to use:"
  16. print "-----------"
  17. print "This script will make something similar to sin waves from your single points"
  18. end
  19.  
  20. function update(delta)
  21. -- this runs even when the gui is closed
  22. end
  23.  
  24. function gui()
  25. ofs.Text("How much should the new points vary from the original points")
  26. Settings.Wave = ofs.SliderInt("+- Position", Settings.Wave, 0, 100)
  27.  
  28. ofs.Text("Offset from the point")
  29. Settings.Offset = ofs.SliderInt("ms", Settings.Offset, 10, 1000)
  30.  
  31. --ofs.Text("First point is bottom - 0 / First point is top - 1")
  32. --Settings.Start = ofs.SliderInt("point", Settings.Start, 0, 1)
  33.  
  34. if ofs.Button("Change into waves") then
  35. binding.addWave()
  36. end
  37. end
  38.  
  39. function binding.addWave()
  40. -- prevent invalid numbers
  41. Settings.Wave = math.floor(clamp(Settings.Wave,0,100))
  42. Settings.Offset = math.floor(clamp(Settings.Offset, 10, 1000))
  43. Settings.Start = math.floor(clamp(Settings.Start, 0, 1))
  44. local Wave = Settings.Wave
  45. local Offset = Settings.Offset/1000
  46. local Start = 0
  47. --local Start = Settings.Start
  48. local lastAction = 0 -- previous action
  49.  
  50. local lastTimestamp = 0 -- last timestamp
  51. local currentTimestamp = 0 -- current timestamp
  52. local CurrentScript = ofs.Script(ofs.ActiveIdx())
  53.  
  54. -- Count the elements in the object
  55. for idx, action in ipairs(CurrentScript.actions) do
  56. if action.selected then
  57. lastTimestamp = lastTimestamp + 1
  58. --print(action.pos)
  59. --print(action.at)
  60. end
  61. end
  62.  
  63. for idx, action in ipairs(CurrentScript.actions) do
  64. if action.selected then
  65. if currentTimestamp == 0 then
  66. local closest_action = CurrentScript:closestActionAfter(action.at)
  67. if action.pos > closest_action.pos then
  68. Start = 1
  69. print(closest_action.pos)
  70. end
  71. end
  72. if currentTimestamp == lastTimestamp then
  73. print ("Done adding waves")
  74. elseif ((currentTimestamp % 2 ~= 0) and Start == 0) or ((currentTimestamp % 2 == 0) and Start == 1) then
  75. print ("adding waves" .. currentTimestamp)
  76.  
  77. local new_action = Action.new(action.at - Offset, action.pos - Wave) -- Adding an action before the point
  78. CurrentScript.actions:add(new_action)
  79. local new_action = Action.new(action.at + Offset, action.pos - Wave) -- Adding an action after the point
  80. CurrentScript.actions:add(new_action)
  81. print(action.at)
  82.  
  83. print("Closest action")
  84.  
  85. --print(action.at+0.20)
  86.  
  87. currentTimestamp = currentTimestamp + 1
  88. else
  89. print ("adding waves" .. currentTimestamp)
  90. local new_action = Action.new(action.at - Offset, action.pos + Wave) -- Adding action before the point
  91. CurrentScript.actions:add(new_action)
  92. local new_action = Action.new(action.at + Offset, action.pos + Wave) -- Adding an action after the point
  93. CurrentScript.actions:add(new_action)
  94. --print(action.at)
  95. --print(action.at+0.20)
  96.  
  97. currentTimestamp = currentTimestamp + 1
  98. end
  99. end
  100. end
  101. CurrentScript:commit()
  102. end
Advertisement
Add Comment
Please, Sign In to add comment