Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. globalAudio = globalAudio or nil
  2.  
  3. if (globalAudio) then
  4. globalAudio:Stop()
  5. end
  6.  
  7.  
  8. sound.PlayURL("https://matt-walton.net/lol/file.mp3", "", function(audio, __, err)
  9. globalAudio = audio
  10. audio:Play()
  11.  
  12. timer.Create("fft", 0.01, 0, function()
  13. fftAnal(audio)
  14. end)
  15. end)
  16.  
  17.  
  18. local lastFFT = {}
  19. local maxs = {}
  20.  
  21. local kickThreshold = 0.3;
  22.  
  23. function maxAmps(freqs)
  24. local max = 0
  25.  
  26. for i=freqs[1], freqs[2] do
  27. if (lastFFT[i] and max and lastFFT[i] > max) then
  28. max = lastFFT[i]
  29. end
  30. end
  31.  
  32. return max
  33. end
  34.  
  35. function fftAnal(audio)
  36. audio:FFT(lastFFT, FFT_256)
  37. for k, v in pairs(lastFFT) do
  38. if (!maxs[k] or v > maxs[k]) then
  39. maxs[k] = v
  40. end
  41. end
  42.  
  43. if (maxAmps({1, 11}) >= kickThreshold) then
  44. kickThreshold = maxAmps({1, 11})
  45. kick(maxAmps({1, 11}))
  46. else
  47. kickThreshold = kickThreshold - 0.05
  48. end
  49. end
  50.  
  51. local colors = {}
  52.  
  53. local baseColor = Color(0, 146, 185, 200)
  54.  
  55. for i=1, 128 do
  56. colors[i] = Color(baseColor.r + math.random(0, 10), baseColor.g + math.random(-10, 10), baseColor.b + math.random(-10, 10))
  57. end
  58.  
  59. local paintValues = {}
  60. local drawColor = Color(255, 255, 255, 0)
  61.  
  62.  
  63. hook.Add("HUDPaint", "test", function()
  64. local w = ScrW() / 128
  65.  
  66. surface.SetDrawColor(drawColor)
  67. //surface.DrawRect(0, 0, ScrW(), ScrH())
  68.  
  69. for k, v in pairs(lastFFT) do
  70. if (!paintValues[k]) then
  71. paintValues[k] = (200 / maxs[k]) * v
  72. else
  73. if (paintValues[k] < (200 / maxs[k]) * v) then
  74. paintValues[k] = math.Approach(paintValues[k], (200 / maxs[k]) * v, FrameTime() * 500)
  75. else
  76. paintValues[k] = math.Approach(paintValues[k], (200 / maxs[k]) * v, -FrameTime() * 500)
  77. end
  78. end
  79.  
  80. surface.SetDrawColor(0, 255/128 * k, 255 - (255/128 * k ))
  81. surface.SetDrawColor(colors[k])
  82. surface.DrawRect((k - 1) * w, 0, w, paintValues[k])
  83. end
  84. end)
  85.  
  86.  
  87. local white = Material("models/debug/debugwhite")
  88.  
  89. hook.Add("PostDrawTranslucentRenderables", "3dpenis", function()
  90.  
  91. local avgs = {}
  92. for k, v in pairs(paintValues) do
  93. if (k % 9 == 0) then
  94. local avg = 0
  95. for i=1, 8 do
  96. print(k-i)
  97. avg = avg + paintValues[k - i]
  98. end
  99.  
  100. avg = avg/8
  101. table.insert(avgs, avg)
  102. end
  103. end
  104.  
  105. cam.Start3D(EyePos(), EyeAngles())
  106. render.SuppressEngineLighting(true)
  107. render.SetColorMaterial()
  108. render.SetBlend(0.5)
  109. for i, v in pairs(avgs) do
  110. render.DrawBox(Vector(-756 + (i * 70), -341, 83), Angle(0, 0, 0), Vector(-32, -32, -202), Vector(32, 32, -202 + v), colors[i * 8], false)
  111. end
  112. render.SetBlend(1)
  113. render.SuppressEngineLighting(false)
  114. cam.End3D()
  115. end)
  116.  
  117.  
  118. function kick(mag)
  119. drawColor = Color(math.random(0, 255), math.random(0, 255), math.random(0, 255), math.min(200, mag * 500))
  120. local ang = AngleRand() * (mag * 0.2)
  121.  
  122. if (mag > 0.3) then
  123. //net.Start("viewpunchy")
  124. // net.WriteAngle(ang)
  125. //net.SendToServer()
  126. end
  127.  
  128. if (mag > 0.2) then
  129. LocalPlayer():ConCommand("+duck")
  130. timer.Simple(0.05, function() LocalPlayer():ConCommand("-duck") end)
  131. end
  132.  
  133. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement