colddddda

Untitled

Oct 17th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. local Height=10 -- Max height of the bars
  2. local plr=game.Players.LocalPlayer
  3. local Soundbar=workspace.Soundbar
  4. local Sound=Soundbar.Sound
  5. local Bars={} for i,v in next,Soundbar:children() do
  6. if v:IsA'BasePart' then
  7. table.insert(Bars,v)
  8. end
  9. end Height=Height*2
  10. local nBars,Tweens=#Bars-1,{}
  11.  
  12. -- EASING FUNCTIONS --
  13. local function quadIn(t,b,c,d) t=t/d; return c*t*t+b; end;
  14. local function quadOut(t,b,c,d) t=t/d; return -c*t*(t-2)+b; end;
  15. local function Quad(obj,val,ease,d)
  16. local t,f,con,nt,st,sd=tick()
  17. Tweens[obj]=t -- Set identifier
  18. st=obj.Scale.Y -- Start Value
  19. sd=val-st -- Change in Value
  20. f=ease=='In' and quadIn or quadOut -- Choose between Out/In
  21. con=game:GetService'RunService'.RenderStepped:connect(function() nt=tick()-t
  22. if Tweens[obj]~=t then -- Check for override
  23. con:disconnect()
  24. return
  25. end
  26. local nv=math.max(.2,f(math.min(d,nt),st,sd,d)) -- New Value
  27. obj.Scale=Vector3.new(.9,nv,.9)
  28. obj.Offset=Vector3.new(0,nv/4,0)
  29. obj.VertexColor=Vector3.new(.7,.3,1):lerp(Vector3.new(.3,1,.7),nv/Height)
  30. if nt>d then -- Easing done?
  31. con:disconnect()
  32. if ease~='In' then
  33. Quad(obj,.2,'In',.3) -- Drop the bar
  34. end
  35. end
  36. end)
  37. end
  38.  
  39. -- BAR MANIPULATION --
  40. local function CheckSet(N,S,D) -- Number, Scale, Direction
  41. local nS=Soundbar[tostring(N)].Mesh.Scale.Y
  42. if S>nS then
  43. Set(N,nS+(S-nS)/3,D)
  44. end
  45. end
  46.  
  47. function Set(N,S,D) -- Number, Scale, Direction
  48. Quad(Soundbar[tostring(N)].Mesh,S,'Out',.1) -- Grabs the bar and tweens
  49. if N>0 and D~=1 then -- Checks left for smaller bars to manipulate
  50. CheckSet(N-1,S,-1)
  51. end
  52. if N<nBars and D~=-1 then -- Checks right...
  53. CheckSet(N+1,S,1)
  54. end
  55. end
  56.  
  57. -- RENDER LOOP --
  58. local MPL,PL,curr=0 curr=Sound.SoundId
  59. game:service'RunService'.RenderStepped:connect(function()
  60. PL=Sound.PlaybackLoudness
  61. if Sound.IsPlaying and PL==PL then -- Sound is playing & PlaybackLoudness is not undefined
  62. if curr~=Sound.SoundId then MPL=0 -- Reset the relative Max PlaybackLoudness on song change
  63. curr=Sound.SoundId
  64. end
  65. MPL=math.max(PL,MPL) PL=PL/MPL -- Normalize PL based on relative Max PlaybackLoudness
  66. if PL==PL then
  67. Set(math.floor(PL*nBars),PL*Height) -- Modify bar relative to PlaybackLoudness
  68. end
  69. end
  70. end)
Add Comment
Please, Sign In to add comment