Garry's Mod Wiki

HSVToColor

table HSVToColor( number hue, number saturation, number value )

Description

Converts a color from HSV color space into RGB color space and returns a Color.

The returned color will not have the color metatable.

Arguments

1 number hue
The hue in degrees from 0-360.
2 number saturation
The saturation from 0-1.
3 number value
The value from 0-1.

Returns

1 table
The Color created from the HSV color space.

Example

A helper function for drawing rainbow text.

local function DrawRainbowText( frequency, str, font, x, y ) surface.SetFont( font ) for i = 1, #str do surface.SetTextColor( HSVToColor( i * frequency % 360, 1, 1 ) ) local w = surface.GetTextSize( string.sub( str, 1, i - 1 ) ) surface.SetTextPos( x + w, y ) surface.DrawText( string.sub( str, i, i ) ) end end
Output:

Example

A helper function for printing rainbow text in the chat.

local function ChatPrintRainbow( frequency, str ) local text = {} for i = 1, #str do table.insert( text, HSVToColor( i * frequency % 360, 1, 1 ) ) table.insert( text, string.sub( str, i, i ) ) end chat.AddText( unpack( text ) ) end
Output:

Example

A helper function for printing rainbow text in the console.

local function ConsolePrintRainbow( frequency, str ) local text = {} for i = 1, #str do table.insert( text, HSVToColor( i * frequency % 360, 1, 1 ) ) table.insert( text, string.sub( str, i, i ) ) end table.insert( text, "\n" ) MsgC( unpack( text ) ) end
Output:

Page Links


Special Pages


Wikis

?

Render Time: 39ms

Session 0
DB GetPage 3
Generate Html 11
SaveChanges 11
Render Body 0
Render Sidebar 11