Global/HSVToColor

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (It was mixed up)
Line 1: Line 1:
 
{{Func
 
{{Func
|Description=Converts a color from HSV color space into RGB color space and returns a {{Struct|Color}}.
+
|Description=Converts a color from [https://en.wikipedia.org/wiki/HSL_and_HSV HSV color space] into RGB color space and returns a {{Struct|Color}}.
  
 
{{Bug|Issue=2407|The returned color will not have the color metatable.}}
 
{{Bug|Issue=2407|The returned color will not have the color metatable.}}
Line 9: Line 9:
 
|type=number
 
|type=number
 
|name=hue
 
|name=hue
|desc=Hue in degrees.
+
|desc=Hue in degrees. (0 to 360)
 
}}
 
}}
 
{{Arg
 
{{Arg
 
|type=number
 
|type=number
|name=saturation black
+
|name=saturation
|desc=Saturation Black from 0 - 1.
+
|desc=The saturation, from 0 to 1.
 
}}
 
}}
 
{{Arg
 
{{Arg
 
|type=number
 
|type=number
|name=saturation white
+
|name=value
|desc=Saturation White from 0 - 1.
+
|desc=The "Value", from 0 to 1.
 
}}
 
}}
 
{{Ret
 
{{Ret

Revision as of 19:18, 30 September 2019

 HSVToColor( )

Contents

Description

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

BUG

The returned color will not have the color metatable.

Issue Tracker: #2407

Arguments

number hue

Hue in degrees. (0 to 360)

Arguments

number saturation

The saturation, from 0 to 1.

Arguments

number value

The "Value", from 0 to 1.

Returns

table

The Color structure created from the HSV color space.

Examples

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:

DrawRainbowText.png

Examples

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:

ChatPrintRainbow.png

Examples

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:

ConsolePrintRainbow.png
Personal tools
Navigation