local function DrawRainbowText( frequency, str, font, x, y )
surface.SetFont( font )
surface.SetTextPos( x, y )
for i = 1, #str do
local col = HSVToColor( i * frequency % 360, 1, 1 ) -- Providing 3 numbers to surface.SetTextColor rather
surface.SetTextColor( col.r, col.g, col.b ) -- than a single color is faster
surface.DrawText( string.sub( str, i, i ) )
end
end
-- Solid color rainbow, faster than example above
local function DrawSimpleRainbowText( speed, str, font, x, y )
surface.SetFont( font )
surface.SetTextColor( HSVToColor( ( CurTime() * speed ) % 360, 1, 1 ) )
surface.SetTextPos( x, y )
surface.DrawText( str )
end
hook.Add( "HUDPaint", "RainbowPuke", function()
DrawRainbowText( 10, "Hello world! This is rainbow text.", "CloseCaption_Bold", 5, 5 )
DrawSimpleRainbowText( 100, "Hello world! This is rainbow text.", "CloseCaption_Bold", 5, 55 )
end )