Libraries.Game.Graphics.ColorNamer Documentation

The ColorNamer class takes in a red, green, blue (RGB) value and converts it to the name of a given color. Because colors can an incredibly diverse set of names, we selected colors from standard web consortium names, which can be found at the following address: https://www.w3.org/wiki/CSS/Properties/color/keywords When a color is requested that does not have an exact match in this list, the least Euclidian distance is used to calculate the color that is closest. This provides a mechanism to use relatively standard naming conventions without necessitating a very large set of what are likely esoteric names. Note that we did not try to optimize this algorithm, making it O(n) per call, where n is the number of colors in the possible set.

Example Code

use Libraries.Game.Graphics.ColorNamer

ColorNamer namer
output namer:GetName(117,243,56) //outputs "YellowGreen"

Inherits from: Libraries.Language.Object

Actions Documentation

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetName(number red, number green, number blue)

From a red, green, blue value, outputs the closest name in the set of common w3C colors. In this case, the colors go from 0 to 255.

Parameters

  • number red
  • number green
  • number blue

Return

text:

Example

use Libraries.Game.Graphics.ColorNamer
    
ColorNamer namer
output namer:GetName(117,243,56) //outputs "YellowGreen"

GetNameAsPercentage(number red, number green, number blue)

From a red, green, blue value, outputs the closest name in the set of common w3C colors. In this case, the colors go from 0 to 1. The system automatically multiplies this percentage by 255 for the calculation.

Parameters

  • number red
  • number green
  • number blue

Return

text:

Example

use Libraries.Game.Graphics.ColorNamer
    
ColorNamer namer
output namer:GetName(117,243,56) //outputs "YellowGreen"