Advertisement
ThatOneGuy561

Untitled

Jun 15th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.23 KB | None | 0 0
  1. -- Made by PPATTA/Cass/Inkyy/lynks - I name change alot ---
  2. -- 299530855
  3. -- [[ CONFIG ]] --
  4. local Color1 = Color3.fromRGB(178, 76, 255)
  5. local Color2 = Color3.fromRGB(255, 76, 178)
  6. local PI = math.pi
  7. local HALF_PI = PI * 0.5
  8. local TAU = PI * 2
  9.  
  10. local PREFIX = "!"
  11.  
  12. -- 574538568
  13. local RING = {
  14. SECTIONS = 25,
  15. RADIUS = 5,
  16. AMPLITUDE = 2
  17. }
  18.  
  19. -- 574538568
  20. -- [[ CONSTANTS ]] --
  21.  
  22. local Players = game:GetService("Players")
  23. local RunService = game:GetService("RunService")
  24.  
  25. local Player = Players.LocalPlayer
  26. local Color = Color3.new(1,1,1)
  27.  
  28. -- [[ UTIL ]] --
  29.  
  30. local function NewInstance(class, parent, properties)
  31. local hasParent = true
  32.  
  33. if (not properties) then
  34. properties = parent
  35. hasParent = false
  36. end
  37.  
  38. local Instance = Instance.new(class, hasParent and parent)
  39.  
  40. if (not properties) then return Instance end
  41.  
  42. for property, value in pairs(properties) do
  43. Instance[property] = value
  44. end
  45.  
  46. return Instance
  47. end
  48.  
  49. local function rand(min, max)
  50. return (min + (math.random() * (max - min)))
  51. end
  52.  
  53.  
  54. -- [[ VISUALIZER ]] --
  55.  
  56. local Cache = {}
  57. local CacheMetatable = {__index = Cache}
  58.  
  59. function Cache:new(size)
  60. local self = setmetatable({}, CacheMetatable)
  61.  
  62. self.Size = size
  63. self.Table = {}
  64.  
  65. return self
  66. end
  67.  
  68. function Cache:push(value)
  69. table.insert(self.Table, value)
  70.  
  71. if (#self.Table > self.Size) then table.remove(self.Table, 1) end
  72. end
  73.  
  74. function Cache:get(i)
  75. return self.Table[i]
  76. end
  77.  
  78. local RingSection = {}
  79. local RingSectionMetatable = {__index = RingSection}
  80.  
  81. function RingSection:new(Ring, id)
  82. local self = setmetatable({}, RingSectionMetatable)
  83.  
  84. self.Ring = Ring
  85. self.ID = id
  86. self.Part = NewInstance("Part", Ring.Container, {
  87. Name = string.format("%x", id),
  88. Size = Vector3.new((TAU / RING.SECTIONS) * RING.RADIUS, 0.25, 0.25),
  89. CFrame = Ring.Position,
  90. Anchored = true,
  91. CanCollide = false,
  92. Material = Enum.Material.Neon,
  93. BrickColor = BrickColor.new(Color.r,Color.b,Color.g),
  94. TopSurface = Enum.SurfaceType.SmoothNoOutlines,
  95. BottomSurface = Enum.SurfaceType.SmoothNoOutlines
  96. })
  97.  
  98.  
  99. self.Transparency = 1
  100.  
  101. return self
  102. end
  103.  
  104. function RingSection:SetOffset(cframe)
  105. self.Part.CFrame = self.Ring.Position * cframe
  106. end
  107.  
  108. function RingSection:Render()
  109. local Part = self.Part
  110. local Ring = self.Ring
  111. local Center = Ring.Position.p
  112.  
  113. local sections = RING.SECTIONS
  114. local aint = (TAU / sections)
  115. local radius = RING.RADIUS
  116. local yrange = RING.AMPLITUDE
  117. local id1 = self.ID
  118. local id2 = id1 + 1
  119. if (id2 > sections) then id2 = id2 - sections end
  120.  
  121. local volume1 = (self.Ring.VolumeCache:get(id1) or 0) * 0.0025
  122. local volume2 = (self.Ring.VolumeCache:get(id2) or 0) * 0.0025
  123.  
  124. local theta1 = aint * id1
  125. local theta2 = aint * id2
  126.  
  127. local seedmult = 1000000
  128.  
  129. local y1 = Ring.HeightDict[id1]
  130. local y2 = Ring.HeightDict[id2]
  131.  
  132. local radius1 = radius + math.pow(volume1, 2)
  133. local radius2 = radius + math.pow(volume2, 2)
  134.  
  135. local position1 = Vector3.new(math.cos(theta1) * radius1, y1, math.sin(theta1) * radius1)
  136. local position2 = Vector3.new(math.cos(theta2) * radius2, y2, math.sin(theta2) * radius2)
  137.  
  138. local distance = (position1 - position2).magnitude
  139. local position = CFrame.new(position1, position2) * CFrame.new(0, 0, -distance * 0.5)
  140.  
  141. Part.Transparency = self.Transparency
  142. Part.Size = Vector3.new(0.25, 0.25, distance)
  143. self:SetOffset(position)
  144. end
  145.  
  146. local LightningRing = {}
  147. local LightningRingMetatable = {__index = LightningRing}
  148.  
  149. function LightningRing:new(Visualizer)
  150. local self = setmetatable({}, LightningRingMetatable)
  151.  
  152. self.Visualizer = Visualizer
  153. self.Container = NewInstance("Model", Player.Character, {
  154. Name = "RingVisualizer"
  155. })
  156.  
  157. self.Speed = 0
  158. self.Amplitude = 0
  159. self.Frames = 0
  160. self.Seed = math.random()
  161.  
  162. self.Offset = CFrame.new(0, 0, 0)
  163.  
  164. self:UpdatePosition()
  165.  
  166. self.Sections = {}
  167. self.Ghosts = {}
  168. self.HeightDict = {}
  169.  
  170. self.VolumeCache = Cache:new(RING.SECTIONS)
  171.  
  172. self.TargetTransparency = {
  173. init = 0,
  174. stopping = 1
  175. }
  176.  
  177. return self
  178. end
  179.  
  180. function LightningRing:Init()
  181. for i = 1, RING.SECTIONS do
  182. self.Sections[i] = RingSection:new(self, i)
  183. end
  184. end
  185.  
  186. function LightningRing:GetCFrame()
  187. return Player.Character.HumanoidRootPart.CFrame * self.Offset
  188. end
  189.  
  190. function LightningRing:UpdatePosition()
  191. local cf = self:GetCFrame()
  192.  
  193. self.CFrame = cf
  194. self.Position = CFrame.new(cf.p)
  195. end
  196.  
  197. function LightningRing:UpdateHeightDict()
  198. self.HeightDict = {}
  199. for i = 1, RING.SECTIONS do
  200. self.HeightDict[i] = (math.noise(self.Seed, (tick() * self.Speed) % 60, i) + 0.5) * self.Amplitude * RING.AMPLITUDE
  201. end
  202. end
  203.  
  204. function LightningRing:Render()
  205. self.Frames = self.Frames + 1
  206.  
  207. if (self.Visualizer.State == "playing") then
  208. local PlaybackLoudness = self.Visualizer.Sound.PlaybackLoudness
  209.  
  210. self.Speed = PlaybackLoudness * 0.005
  211. self.Amplitude = PlaybackLoudness * 0.0025
  212.  
  213. self.VolumeCache:push(PlaybackLoudness)
  214. self.VolumeCache:push(PlaybackLoudness)
  215.  
  216. self.Offset = CFrame.new(0, PlaybackLoudness * 0.0025, 0)
  217. elseif (self.Visualizer.State == "stopping") then
  218. self.Speed = 0
  219. self.Amplitude = 0
  220.  
  221. self.VolumeCache:push(0)
  222. end
  223.  
  224. self:UpdatePosition()
  225. self:UpdateHeightDict()
  226.  
  227. for _, Ghost in pairs(self.Ghosts) do
  228. Ghost.Transparency = math.min(1, Ghost.Transparency + 0.05)
  229.  
  230. if (Ghost.Transparency == 1) then Ghost:Destroy() end
  231. end
  232.  
  233. for _, Section in pairs(self.Sections) do
  234. local targetTransparency = self.TargetTransparency[self.Visualizer.State]
  235. if (targetTransparency and Section.Transparency ~= targetTransparency) then
  236. Section.Transparency = math.max(0, math.min(1, Section.Transparency + ((targetTransparency - Section.Transparency) * math.random() * 0.1)))
  237. end
  238.  
  239. Section:Render()
  240.  
  241. if (self.Visualizer.State == "playing" and (self.Frames % 5 == 0)) then
  242. local Ghost = Section.Part:Clone()
  243. Ghost.Parent = self.Container
  244. Ghost.Transparency = 0.5
  245. table.insert(self.Ghosts, Ghost)
  246. end
  247. end
  248. end
  249.  
  250. function LightningRing:Destroy()
  251. self.Container:Destroy()
  252. end
  253.  
  254. local Visualizer = {}
  255. local VisualizerMetatable = {__index = Visualizer}
  256.  
  257. function Visualizer:new(options)
  258. local self = setmetatable({}, VisualizerMetatable)
  259.  
  260. self.SoundID = soundID
  261. self.State = "init"
  262.  
  263. self.Ring = LightningRing:new(self)
  264.  
  265. self.Sound = NewInstance("Sound", Player.Character.HumanoidRootPart, options)
  266.  
  267. self.EndedListener = self.Sound.Ended:connect(function()
  268. self:Stop()
  269. end)
  270.  
  271. return self
  272. end
  273.  
  274. function Visualizer:Init()
  275. self.Ring:Init()
  276.  
  277. delay(2, function()
  278. self:Start()
  279. end)
  280.  
  281. self.Heartbeat = RunService.Heartbeat:connect(function()
  282. self:Render()
  283. end)
  284. end
  285.  
  286. function Visualizer:Start()
  287. self.State = "playing"
  288. self.Sound:Play()
  289. end
  290.  
  291. function Visualizer:Stop()
  292. self.State = "stopping"
  293. self.Sound:Stop()
  294.  
  295. wait(2)
  296. self:Destroy()
  297. end
  298.  
  299. function Visualizer:Destroy()
  300. self.State = "destroyed"
  301. self.Sound:Destroy()
  302.  
  303. self.Ring:Destroy()
  304.  
  305. self.EndedListener:disconnect()
  306. self.Heartbeat:disconnect()
  307. end
  308.  
  309. function Visualizer:Render()
  310. self.Ring:Render()
  311. end
  312.  
  313.  
  314. -- [[ COMMANDS ]] --
  315.  
  316. local visualizer
  317. local playbackVolume = 2
  318. local playbackSpeed = 1
  319.  
  320. local Commands = {}
  321.  
  322. function Commands.play(args)
  323. local soundID = args[1]
  324. local option = args[2]
  325.  
  326. if (visualizer) then visualizer:Stop() end
  327.  
  328. local options = {
  329. SoundId = "rbxassetid://" .. soundID,
  330. Volume = playbackVolume,
  331. PlaybackSpeed = playbackSpeed
  332. }
  333.  
  334. if (option == "-l") then
  335. options.Looped = true
  336. end
  337.  
  338. visualizer = Visualizer:new(options)
  339. visualizer:Init()
  340. end
  341.  
  342. function Commands.stop()
  343. if (visualizer) then visualizer:Stop() end
  344. end
  345.  
  346. function Commands.audiovolume(args)
  347. local volume = tonumber(args[1])
  348. playbackVolume = volume
  349.  
  350. if (visualizer) then visualizer.Sound.Volume = playbackVolume end
  351. end
  352. function Commands.color1(args)
  353. Color1 = Color3.fromRGB(args[1],args[2],args[3])
  354. print(Color1.r,Color1.g,Color1.b)
  355. end
  356. function Commands.color2(args)
  357. Color2 = Color3.fromRGB(args[1],args[2],args[3])
  358. print(Color2.r,Color2.g,Color2.b)
  359. end
  360. function Commands.audiospeed(args)
  361. local speed = tonumber(args[1])
  362. playbackSpeed = speed
  363.  
  364. if (visualizer) then visualizer.Sound.PlaybackSpeed = playbackSpeed end
  365. end
  366.  
  367. Player.Chatted:connect(function(message)
  368. if (string.sub(message, 1, 1) ~= PREFIX) then return end
  369.  
  370. local rawCommand = string.sub(message, 2)
  371.  
  372. local command
  373. local args = {}
  374.  
  375. for carg in rawCommand:gmatch("%S+") do
  376. if (not command) then
  377. command = carg
  378. else
  379. args[#args + 1] = carg
  380. end
  381. end
  382.  
  383. local chatCommand = Commands[command]
  384. if (not chatCommand) then return end
  385. chatCommand(args)
  386. end)
  387.  
  388. --- 461736208
  389. while wait(.01) do
  390. if Player.Character.HumanoidRootPart:FindFirstChild("Sound") then
  391. s = Player.Character.HumanoidRootPart:FindFirstChild("Sound")
  392. Color = Color1:lerp(Color2,.2*math.sqrt(math.floor(s.PlaybackLoudness/6)))
  393. for b,n in pairs(Player.Character.RingVisualizer:GetChildren())do
  394. n.BrickColor = BrickColor.new(Color.r,Color.g,Color.b)
  395. end
  396. end
  397. end
  398.  
  399. -- 299530855
  400.  
  401. -- 570351814
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement