Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Visualizer = {
- AudioChannel = nil,
- Data = {},
- SmoothData = {},
- BlurMat = Material("blur3.png", "smooth noclamp"),
- MovingMat = Material("blurbackground.png", "smooth noclamp"),
- NoteMat = Material("musicnote.png", "smooth noclamp"),
- Intensity = 50,
- }
- local function DrawCircle( x, y, radius, seg )
- local cir = {}
- table.insert( cir, { x = x, y = y, u = 0.5, v = 0.5 } )
- for i = 0, seg do
- local a = math.rad( ( i / seg ) * -360 )
- table.insert( cir, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius, u = math.sin( a ) / 2 + 0.5, v = math.cos( a ) / 2 + 0.5 } )
- end
- local a = math.rad( 0 ) -- This is needed for non absolute segment counts
- table.insert( cir, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius, u = math.sin( a ) / 2 + 0.5, v = math.cos( a ) / 2 + 0.5 } )
- surface.DrawPoly( cir )
- end
- local i = 1
- function DrawBackgroundD(mat, clr, x, y, w, h, limitW, limitH)
- render.ClearStencil();
- render.SetStencilEnable( true );
- render.SetStencilCompareFunction( STENCIL_ALWAYS );
- render.SetStencilPassOperation( STENCIL_REPLACE );
- render.SetStencilFailOperation( STENCIL_KEEP );
- render.SetStencilZFailOperation( STENCIL_KEEP );
- render.SetStencilWriteMask( 255 );
- render.SetStencilTestMask( 255 );
- render.SetStencilReferenceValue( 1 );
- surface.SetDrawColor( clr )
- surface.DrawRect( x, y, limitW, limitH )
- render.SetStencilCompareFunction( STENCIL_EQUAL );
- -- clear the inside of our mask so we have a nice clean slate to draw in.
- render.ClearBuffersObeyStencil( 0, 0, 0, 0, true );
- surface.SetDrawColor( clr )
- surface.SetMaterial( Visualizer.BlurMat )
- local texW = 3840
- local texH = 2400
- local limitW2, limitH2 = limitW, limitH
- surface.DrawTexturedRect( x, y, w, h )
- surface.SetMaterial( Visualizer.MovingMat )
- surface.DrawTexturedRect( x - Visualizer.Intensity or 50/2, y - Visualizer.Intensity/2 or 50/2, w, h )
- render.SetStencilEnable( false );
- end
- function Visualizer.PlayURL(url, flags, callback)
- sound.PlayURL(url, flags, function(channel, err, errtxt)
- if IsValid(channel) then
- for i = 1, 1024 do
- Visualizer.SmoothData[i] = 0
- end
- callback(channel, err, errtxt)
- Visualizer.AudioChannel = channel
- else
- return
- end
- end)
- end
- function Visualizer.PlayFile(path, flags, callback)
- sound.PlayFile(path, flags, function(channel, err, errtxt)
- if IsValid(channel) then
- callback(channel, err, errtxt)
- Visualizer.AudioChannel = channel
- else
- return
- end
- end)
- end
- local blur = Material("pp/blurscreen")
- local function DrawCircleBlur(x, y, radius, seg, amount)
- surface.SetDrawColor(20, 20, 20, 200)
- draw.NoTexture()
- DrawCircle(x, y, radius, seg)
- end
- hook.Add( "PostDrawOpaqueRenderables", "example", function()
- local pos = Vector(-11100, -1550, -8050)
- local angle = Angle(0, 90, 90)
- cam.Start3D2D( pos, angle, 1 )
- DrawBackgroundD( Visualizer.BlurMat, Color(255, 255, 255, 255), 0, 0, 1280/6 + Visualizer.Intensity, 720/6 + Visualizer.Intensity, 1280/6, 720/6)
- if IsValid(Visualizer.AudioChannel) and Visualizer.AudioChannel:GetState() == 1 then
- Visualizer.Data = { }
- Visualizer.AudioChannel:FFT(Visualizer.Data, FFT_2048)
- for i = 1, 1024 do
- Visualizer.SmoothData[i] = Lerp(5 * FrameTime(), Visualizer.SmoothData[i], Visualizer.Data[i])
- end
- Visualizer.Intensity = Visualizer.SmoothData[5] * 1000
- surface.SetDrawColor( 0, 0, 0, 200 )
- DrawCircleBlur(1280/6/2, 720/6/2, math.Clamp(Visualizer.Intensity or 50, 50, 100), 30 )
- surface.SetDrawColor( 255, 255, 255, 255 )
- surface.SetMaterial(Visualizer.NoteMat)
- DrawCircle(1280/6/2, 720/6/2, math.Clamp(Visualizer.Intensity - 15 or 35, 35, 85) , 30)
- end
- cam.End3D2D()
- end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement