Advertisement
KrYn0MoRe

text visualiser

Apr 29th, 2021 (edited)
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.92 KB | None | 0 0
  1. BillboardGui0 = Instance.new("BillboardGui")
  2. TextLabel1 = Instance.new("TextBox")
  3. TextLabel2 = Instance.new("TextBox")
  4. BillboardGui0.Name = "gui"
  5. BillboardGui0.Parent = script
  6. BillboardGui0.LightInfluence = 1
  7. BillboardGui0.Size = UDim2.new(20, 0, 10, 0)
  8. BillboardGui0.Active = true
  9. BillboardGui0.ClipsDescendants = true
  10. BillboardGui0.AlwaysOnTop = true
  11. BillboardGui0.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
  12. BillboardGui0.SizeOffset = Vector2.new(0, 0.5)
  13. BillboardGui0.StudsOffset = Vector3.new(0, 1, 0)
  14. TextLabel1.Name = "title"
  15. TextLabel1.Parent = BillboardGui0
  16. TextLabel1.Size = UDim2.new(1, 0, 0.100000001, 0)
  17. TextLabel1.BackgroundColor = BrickColor.new("Black")
  18. TextLabel1.BackgroundColor3 = Color3.new(0.152941, 0.152941, 0.152941)
  19. TextLabel1.Font = Enum.Font.Arial
  20. TextLabel1.FontSize = Enum.FontSize.Size14
  21. TextLabel1.Text = "Text Visualiser"
  22. TextLabel1.TextColor = BrickColor.new("Institutional white")
  23. TextLabel1.TextColor3 = Color3.new(1, 1, 1)
  24. TextLabel1.TextScaled = true
  25. TextLabel1.TextSize = 14
  26. TextLabel1.TextStrokeTransparency = 0
  27. TextLabel1.TextWrap = true
  28. TextLabel1.TextWrapped = true
  29. TextLabel2.Name = "vis"
  30. TextLabel2.Parent = BillboardGui0
  31. TextLabel2.Position = UDim2.new(0, 0, 0.100000001, 0)
  32. TextLabel2.Size = UDim2.new(1, 0, 0.899999976, 0)
  33. TextLabel2.BackgroundColor = BrickColor.new("Really black")
  34. TextLabel2.BackgroundColor3 = Color3.new(0, 0, 0)
  35. TextLabel2.BorderSizePixel = 0
  36. TextLabel2.Font = Enum.Font.Arial
  37. TextLabel2.FontSize = Enum.FontSize.Size24
  38. TextLabel2.Text = ''
  39. TextLabel2.TextColor = BrickColor.new("Institutional white")
  40. TextLabel2.TextColor3 = Color3.new(1, 1, 1)
  41. TextLabel2.TextScaled = true
  42. TextLabel2.TextSize = 24
  43. TextLabel2.TextWrap = true
  44. TextLabel2.TextWrapped = true
  45. TextLabel2.TextYAlignment = Enum.TextYAlignment.Bottom
  46.  
  47. local gui = BillboardGui0
  48. local vis = gui.vis
  49. local music = nil
  50.  
  51. local plr = owner
  52. local char,head
  53.  
  54. local loud = 0
  55. local playing = false
  56. local speed = 1
  57. local saved_pos = 0
  58. local vol = 0.5
  59. local looped = true
  60. local id = ''
  61.  
  62. local st = os.clock()
  63. local last_vols = {}
  64.  
  65. local avgs = {}
  66. local avg = 0
  67. local max_avg = 100
  68.  
  69. local div = 10
  70. local bars = 15
  71.  
  72. function update_average_loud()
  73.     if loud > 25 then else return end
  74.  
  75.     avgs[#avgs+1] = loud
  76.     local m = nil
  77.     if #avgs >= max_avg then
  78.         avgs[1] = nil
  79.         m = 1
  80.     end
  81.     local n = 0
  82.     for i,v in pairs(avgs) do
  83.         if m and i > 1 then
  84.             avgs[i-1] = v
  85.             avgs[i] = nil
  86.         end
  87.         n += v
  88.     end
  89.     n = n/#avgs
  90.     avg = n
  91. end
  92.  
  93. local scroll = 5 -- >=1
  94.  
  95. function get_bar()
  96.     local vols = {}
  97.     for i = bars,1,-1 do
  98.         local int = loud/(avg+400)
  99.         local t = os.clock()-st
  100.        
  101.         local min_size = 0
  102.         local max_size = div
  103.         local add_size = max_size-min_size
  104.         add_size = math.clamp(add_size*int,min_size,max_size)
  105.         local ad2 = 5*int*math.abs(math.cos(i/15+t*5))
  106.         ad2 = math.clamp(ad2,0,5)
  107.         vols[i] = math.floor(add_size+ad2)
  108.        
  109.         --[[
  110.         local max = 500
  111.         local n = 100
  112.         local multi = math.random(0,n)/n
  113.         vols[i] = math.floor(loud/max*div*multi)
  114.         ]]
  115.     end
  116.     return vols
  117. end
  118.  
  119. function gen_text(loud)
  120.     local vols = get_bar(loud)
  121.     last_vols = vols
  122.     local txt = ''
  123.     for y = div,0,-1 do
  124.         for x = 1,bars do
  125.             vols[x] = vols[x] or 0
  126.             if vols[x] > y then
  127.                 txt = txt .. '||'
  128.             elseif y == vols[x] then
  129.                 txt = txt .. '_'
  130.             else
  131.                 txt = txt .. string.rep(' ',2)
  132.             end
  133.             txt = txt .. ' '
  134.         end
  135.         txt = txt .. '\n'
  136.     end
  137.     vis.Text = txt
  138. end
  139.  
  140. local cmds = {}
  141. local cmd = {}
  142.  
  143. function cmd.add(name,func)
  144.     cmds[name] = func
  145. end
  146.  
  147. cmd.add('play',function(i)
  148.     playing = true
  149.     if music then
  150.         music.TimePosition = 0
  151.     end
  152.     saved_pos = 0
  153.     id = i
  154. end)
  155.  
  156. cmd.add('speed',function(s)
  157.     speed = s
  158. end)
  159.  
  160. cmd.add('pos',function(p)
  161.     if music then
  162.         music.TimePosition = p
  163.     end
  164.     saved_pos = p
  165. end)
  166.  
  167. cmd.add('vol',function(v)
  168.     vol = v
  169. end)
  170.  
  171. cmd.add('resume',function()
  172.     playing = true
  173. end)
  174.  
  175. cmd.add('pause',function()
  176.     playing = false
  177. end)
  178.  
  179. cmd.add('stop',function()
  180.     playing = false
  181.     if music then
  182.         music.TimePosition = 0
  183.     end
  184.     saved_pos = 0
  185. end)
  186.  
  187. function cmd.run(id,...)
  188.     if id and cmds[id] then
  189.         local t = ...
  190.         pcall(function()
  191.             cmds[id](t)
  192.         end)
  193.     end
  194. end
  195.  
  196. plr.Chatted:Connect(function(msg)
  197.     if string.sub(msg,1,3) == '/e ' then
  198.         msg = string.sub(msg,4)
  199.     end
  200.     local id = string.split(msg,'/')[1]
  201.     if id then
  202.         local args = string.split(string.sub(msg,string.len(id)+2),'/')
  203.         cmd.run(id,unpack(args))
  204.     end
  205. end)
  206.  
  207. local remote = Instance.new("RemoteEvent")
  208. remote.Parent = plr['PlayerGui']
  209.  
  210. remote.OnServerEvent:Connect(function(lplr,l)
  211.     if plr == lplr then
  212.         loud = l
  213.     end
  214. end)
  215.  
  216. local oval = Instance.new("ObjectValue")
  217. oval.Name = 'objval'
  218. oval.Value = music
  219. oval.Parent = remote
  220.  
  221. local ls = NLS([[
  222. local remote = script.Parent
  223. local oval = remote:WaitForChild('objval')
  224. local music = oval.Value
  225. while wait(0.1) do
  226.     if not music or not music.Parent then
  227.         repeat wait() until oval.Value
  228.         music = oval.Value
  229.     end
  230.     if music and music.Parent then
  231.         remote:FireServer(music.PlaybackLoudness)
  232.     end
  233. end
  234. ]],remote)
  235.  
  236. function get_char()
  237.     if char and char.Parent and head and head.Parent then else
  238.         repeat wait() until plr.Character
  239.         char = plr.Character
  240.         if char then
  241.             head = char:FindFirstChild('Head')
  242.         end
  243.         if char and head then else
  244.             get_char()
  245.         end
  246.     end
  247. end
  248.  
  249. coroutine.wrap(function()
  250.     while true do
  251.         get_char()
  252.         if gui and head then
  253.             gui.Adornee = head
  254.         end
  255.         if not music or not music.Parent then
  256.             music = Instance.new("Sound")
  257.             music.Looped = looped
  258.             music.TimePosition = saved_pos
  259.             music.Parent = head
  260.         end
  261.         if music then
  262.             saved_pos = music.TimePosition
  263.             oval.Value = music
  264.             music.Name = 'text music'
  265.             music.SoundId = 'rbxassetid://' .. id
  266.             music.Volume = vol
  267.             music.PlaybackSpeed = speed
  268.             music.Parent = head
  269.             if playing then
  270.                 music:Resume()
  271.             else
  272.                 music:Pause()
  273.             end
  274.             update_average_loud()
  275.             gen_text()
  276.         end
  277.         task.wait()
  278.     end
  279. end)()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement