Drawing a temporary fading red rectangle

I want to draw a red rectangle on the player’s screen that slowly fades away completely after 2 seconds, I’m not sure how to do the fading away stuff, with CurTime()? Timers? plz help =S

I suppose you could do something like this (untested)

[lua]
local time
local alpha

function DoRectangle()

//set time     
time = (CurTime() + 2)     
alpha = 255  

end

function RectanglePaint()

//bailout     
if (alpha == 0) then return end     
if (CurTime() > time) then          
    //reduce alpha         
    alpha = (alpha - 1)     
end      

//draw rect     
surface.SetDrawColor(255, 0, 0, alpha)     
surface.DrawRect(0, 0, ScrW(), ScrH())      

end

hook.Add(“HUDPaint”, “DoRedRectangle”, RectanglePaint)
[/lua]

google is your friend

I googled already…