Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------------------------
- --------------------------------------------------------
- -------------- 'MakeCurves' by StanSpook --------------
- --------------------------------------------------------
- --------------------------------------------------------
- Settings = {}
- Settings.Wave = 0 -- accuracy of the wave
- Settings.Offset = 10 -- the offset of the new points from the original point
- Settings.Start = 0 -- the point starting position
- local script = ofs.Script(ofs.ActiveIdx())
- function init()
- -- this runs once at when loading the extension
- print "How to use:"
- print "-----------"
- print "This script will make something similar to sin waves from your single points"
- end
- function update(delta)
- -- this runs even when the gui is closed
- end
- function gui()
- ofs.Text("How much should the new points vary from the original points")
- Settings.Wave = ofs.SliderInt("+- Position", Settings.Wave, 0, 100)
- ofs.Text("Offset from the point")
- Settings.Offset = ofs.SliderInt("ms", Settings.Offset, 10, 1000)
- --ofs.Text("First point is bottom - 0 / First point is top - 1")
- --Settings.Start = ofs.SliderInt("point", Settings.Start, 0, 1)
- if ofs.Button("Change into waves") then
- binding.addWave()
- end
- end
- function binding.addWave()
- -- prevent invalid numbers
- Settings.Wave = math.floor(clamp(Settings.Wave,0,100))
- Settings.Offset = math.floor(clamp(Settings.Offset, 10, 1000))
- Settings.Start = math.floor(clamp(Settings.Start, 0, 1))
- local Wave = Settings.Wave
- local Offset = Settings.Offset/1000
- local Start = 0
- --local Start = Settings.Start
- local lastAction = 0 -- previous action
- local lastTimestamp = 0 -- last timestamp
- local currentTimestamp = 0 -- current timestamp
- local CurrentScript = ofs.Script(ofs.ActiveIdx())
- -- Count the elements in the object
- for idx, action in ipairs(CurrentScript.actions) do
- if action.selected then
- lastTimestamp = lastTimestamp + 1
- --print(action.pos)
- --print(action.at)
- end
- end
- for idx, action in ipairs(CurrentScript.actions) do
- if action.selected then
- if currentTimestamp == 0 then
- local closest_action = CurrentScript:closestActionAfter(action.at)
- if action.pos > closest_action.pos then
- Start = 1
- print(closest_action.pos)
- end
- end
- if currentTimestamp == lastTimestamp then
- print ("Done adding waves")
- elseif ((currentTimestamp % 2 ~= 0) and Start == 0) or ((currentTimestamp % 2 == 0) and Start == 1) then
- print ("adding waves" .. currentTimestamp)
- local new_action = Action.new(action.at - Offset, action.pos - Wave) -- Adding an action before the point
- CurrentScript.actions:add(new_action)
- local new_action = Action.new(action.at + Offset, action.pos - Wave) -- Adding an action after the point
- CurrentScript.actions:add(new_action)
- print(action.at)
- print("Closest action")
- --print(action.at+0.20)
- currentTimestamp = currentTimestamp + 1
- else
- print ("adding waves" .. currentTimestamp)
- local new_action = Action.new(action.at - Offset, action.pos + Wave) -- Adding action before the point
- CurrentScript.actions:add(new_action)
- local new_action = Action.new(action.at + Offset, action.pos + Wave) -- Adding an action after the point
- CurrentScript.actions:add(new_action)
- --print(action.at)
- --print(action.at+0.20)
- currentTimestamp = currentTimestamp + 1
- end
- end
- end
- CurrentScript:commit()
- end
Advertisement
Add Comment
Please, Sign In to add comment