Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- globalAudio = globalAudio or nil
- if (globalAudio) then
- globalAudio:Stop()
- end
- sound.PlayURL("http://localhost/test/file.mp3", "", function(audio, __, err)
- globalAudio = audio
- audio:Play()
- timer.Create("fft", 0.01, 0, function()
- fftAnal(audio)
- end)
- end)
- local lastFFT = {}
- local maxs = {}
- local kickThreshold = 0.3;
- function maxAmps(freqs)
- local max = 0
- for i=freqs[1], freqs[2] do
- if (lastFFT[i] and max and lastFFT[i] > max) then
- max = lastFFT[i]
- end
- end
- return max
- end
- function fftAnal(audio)
- audio:FFT(lastFFT, FFT_256)
- for k, v in pairs(lastFFT) do
- if (!maxs[k] or v > maxs[k]) then
- maxs[k] = v
- end
- end
- if (maxAmps({1, 11}) >= kickThreshold) then
- kickThreshold = maxAmps({1, 11})
- kick(maxAmps({1, 11}))
- else
- kickThreshold = kickThreshold - 0.02
- end
- end
- local colors = {}
- local baseColor = Color(0, 146, 185, 200)
- for i=1, 128 do
- colors[i] = Color(baseColor.r + math.random(0, 10), baseColor.g + math.random(-10, 10), baseColor.b + math.random(-10, 10))
- end
- local paintValues = {}
- local drawColor = Color(255, 255, 255, 0)
- hook.Add("HUDPaint", "test", function()
- local w = ScrW() / 128
- surface.SetDrawColor(drawColor)
- surface.DrawRect(0, 0, ScrW(), ScrH())
- for k, v in pairs(lastFFT) do
- if (!paintValues[k]) then
- paintValues[k] = (200 / maxs[k]) * v
- else
- if (paintValues[k] < (200 / maxs[k]) * v) then
- paintValues[k] = math.Approach(paintValues[k], (200 / maxs[k]) * v, FrameTime() * 3000)
- else
- paintValues[k] = math.Approach(paintValues[k], (200 / maxs[k]) * v, -FrameTime() * 3000)
- end
- end
- //surface.SetDrawColor(0, 255/128 * k, 255 - (255/128 * k ))
- surface.SetDrawColor(colors[k])
- surface.DrawRect((k - 1) * w, 0, w, paintValues[k])
- end
- end)
- function kick(mag)
- drawColor = Color(math.random(0, 255), math.random(0, 255), math.random(0, 255), 100)
- local ang = AngleRand() * mag
- LocalPlayer():ViewPunch(ang)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement