Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local plr = owner
- local char,root
- --
- function sleep(n)
- return task.wait(n or 0)
- end
- function wrap(f)
- return coroutine.wrap(f)()
- end
- -- setup bricks
- local pfolder = Instance.new("Model")
- pfolder.Name = 'Visualizer'
- pfolder.Parent = script
- local loudness = 0
- local id = 0
- local volume = 1
- local speed = 1
- local timepos = 0
- local gradient_color = BrickColor.new("Royal purple").Color
- local part_amount = 25
- local bricks = {}
- --[[
- for i = 1,part_amount do
- local p = Instance.new("Part")
- p.Color = Color3.new(0,0,0)
- p.Material = Enum.Material.SmoothPlastic
- p.CanCollide = false
- p.Locked = true
- p.CanTouch = false
- p.CanQuery = false
- p.Anchored = true
- p.Parent = pfolder
- bricks[#bricks+1] = p
- if i == part_amount then
- p.Name = 'main'
- end
- end
- ]]
- local music = Instance.new("Sound")
- music.Name = 'vismusic'
- music.SoundId = 'rbxassetid://' .. id
- music.Volume = volume
- music.Parent = bricks[#bricks]
- local st = os.clock()
- local avgs = {}
- local avg = 0
- local max_avg = 100
- function update_average_loud()
- if loudness > 10 then else return end
- avgs[#avgs+1] = loudness
- local m = nil
- if #avgs >= max_avg then
- avgs[1] = nil
- m = 1
- end
- local n = 0
- for i,v in pairs(avgs) do
- if m and i > 1 then
- avgs[i-1] = v
- avgs[i] = nil
- end
- n += v
- end
- n = n/#avgs
- avg = n
- end
- local t = 0
- local brick_i = 0
- local brick_clock = 0
- function update()
- local int = loudness/math.clamp(avg+150,0,500) -- make it divide by the average so intensity is consistent even when quiet
- local multi = 0.5 --+ int*1.5
- t += 1/20 * multi
- sleep()
- local que = false
- if os.clock()-brick_clock >= 0.1*(1-int) then
- brick_clock = os.clock()
- que = true
- if brick_i == 0 then
- que = 1
- end
- brick_i += 1
- if brick_i > #bricks then
- brick_i = 1
- end
- end
- for i = 1,part_amount do
- local p = bricks[i]
- local refit = (que == 1)
- if not p then
- p = Instance.new("Part")
- p.Color = Color3.new(0,0,0)
- p.Material = Enum.Material.SmoothPlastic
- p.CanCollide = false
- p.Locked = true
- p.CanTouch = false
- p.CanQuery = false
- p.Anchored = true
- p.Parent = pfolder
- bricks[i] = p
- if i == part_amount then
- p.Name = 'main'
- end
- refit = true
- end
- if not music or not music.Parent then
- music = Instance.new("Sound")
- music.SoundId = 'rbxassetid://' .. id
- end
- music.Name = 'vismusic'
- music.Volume = volume
- music.PlaybackSpeed = speed
- music.Looped = true
- wrap(function()
- music.Parent = bricks[#bricks]
- end)
- if music and music.Parent and music.Playing then
- timepos = music.TimePosition
- end
- local min_size = 1
- local max_size = 7
- local add_size = max_size-min_size
- local xi = math.pi*#bricks/2
- local ni = i*xi/#bricks
- add_size = math.clamp(add_size*int,0,add_size)--*math.abs(math.cos(ni/#bricks*2+t))
- local div = math.clamp(add_size/(max_size-min_size),0,1)
- local c = div
- c = Color3.new(gradient_color.R*c,gradient_color.G*c,gradient_color.B*c)
- local cpos = p.CFrame
- if root then
- cpos = CFrame.new(root.Position)
- end
- local cf = cpos*CFrame.Angles(0,math.rad(360/part_amount*i),0)*CFrame.new(min_size/2+add_size/2+0.1+5,0,0)--*CFrame.Angles(0,math.rad(90),0)
- local cf2 = cpos*CFrame.Angles(0,math.rad(360/part_amount*i),0)*CFrame.new(p.Size.X/2+0.1+5,0,0)
- if (que and i == brick_i) or refit then
- game:GetService("TweenService"):Create(p,TweenInfo.new(0.1),{
- CFrame = cf,
- Color = c,
- Size = Vector3.new(min_size+add_size,1,1),
- }):Play()
- task.delay(0.1,function()
- game:GetService("TweenService"):Create(p,TweenInfo.new(1),{
- Color = Color3.new(0,0,0),
- Size = Vector3.new(1,1,1),
- }):Play()
- end)
- else
- game:GetService("TweenService"):Create(p,TweenInfo.new(0.1),{
- CFrame = cf2,
- }):Play()
- end
- end
- end
- -- nls poopy
- local remote = Instance.new("RemoteEvent")
- remote.Parent = pfolder
- local objredir = Instance.new("ObjectValue")
- objredir.Value = remote
- objredir.Parent = plr.PlayerGui
- local network = {}
- network.funcs = {}
- function network.add(n,f)
- network.funcs[n] = f
- end
- function network.run(n,...)
- local f = network.funcs[n]
- if f then
- f(...)
- end
- end
- remote.OnServerEvent:Connect(function(lplr,n,...)
- if lplr.Name == plr.Name then else
- return
- end
- network.run(n,...)
- end)
- network.add('loud',function(v)
- loudness = v
- end)
- local code = [[
- local plr = game:GetService("Players").LocalPlayer
- local char = plr.Character
- local root = char:FindFirstChild("HumanoidRootPart")
- local objredir = script.Parent
- repeat wait() until objredir.Value
- local remote = objredir.Value
- local pfolder = remote.Parent
- local sound = pfolder:WaitForChild("main"):WaitForChild("vismusic")
- while true do
- if pfolder and pfolder.Parent then else
- break
- end
- if not sound or not sound.Parent then
- sound = pfolder:WaitForChild("main"):WaitForChild("vismusic")
- end
- if sound then
- remote:FireServer('loud',sound.PlaybackLoudness)
- end
- task.wait(1/20)
- end
- ]]
- NLS = NLS or function() error('NLS fail') end
- NLS(code,objredir)
- --
- local msgs = {}
- msgs.funcs = {}
- msgs.add = function(n,f)
- msgs.funcs[n] = f
- end
- msgs.add('play',function(n)
- id = n
- music.SoundId = 'rbxassetid://' .. id
- music:Play()
- end)
- msgs.add('vol',function(n)
- if n then else return end
- volume = n
- music.Volume = volume
- end)
- msgs.add('speed',function(n)
- if n then else return end
- speed = n
- music.PlaybackSpeed = speed
- end)
- msgs.add('pos',function(n)
- if n then else return end
- timepos = n
- music.TimePosition = timepos
- end)
- msgs.add('pause',function()
- music:Pause()
- end)
- msgs.add('resume',function()
- music.TimePosition = timepos
- music:Resume()
- end)
- msgs.add('color',function(grad)
- if grad and BrickColor.new(grad) then
- gradient_color = BrickColor.new(grad).Color
- end
- end)
- warn([[
- Commands:
- play/id
- vol/n
- speed/n
- pos/n
- pause/
- resume/
- color/str
- ]])
- plr.Chatted:Connect(function(msg)
- if string.sub(msg,1,3) == '/e ' then
- msg = string.sub(msg,4)
- end
- local md = string.split(msg,'/')
- if md[1] then
- local f = msgs.funcs[md[1]]
- if f then
- table.remove(md,1)
- f(table.unpack(md))
- end
- end
- end)
- while true do
- if pfolder and pfolder.Parent then else
- break
- end
- task.spawn(function()
- char = plr.Character
- if char then
- root = char:FindFirstChild("HumanoidRootPart")
- end
- end)
- update_average_loud()
- update()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement