Libraries.Game.Graphics.Color Documentation

The Color class stores information about a color used by the game engine. Colors are stored as a combination of red, green, blue, and alpha (or opacity). All four values may be set from 0 to 1, where 0 represents the total lack of a color or full transparency, and 1 represents full presence of that color or total opacity.

Example Code

use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable rectangle1
    Drawable rectangle2
    Drawable rectangle3

    Color blue
    Color yellow
    Color glassy

    action Main
        StartGame()
    end

    action CreateGame
        blue:SetColor(0, 0, 1, 1)
        rectangle1:LoadFilledRectangle(100, 50, blue)

        yellow:SetColor(1, 1, 0, 1)
        rectangle2:LoadFilledRectangle(100, 50, yellow)

        glassy:SetColor(1, 1, 1, 0.25)
        rectangle3:LoadFilledRectangle(100, 50, glassy)

        rectangle1:SetPosition(50, 50)
        rectangle2:SetPosition(200, 50)
        rectangle3:SetPosition(125, 65)
       
        Add(rectangle1)
        Add(rectangle2)
        Add(rectangle3)
    end
end

Inherits from: Libraries.Game.Graphics.ColorGroup, Libraries.Language.Object

Actions Documentation

Black()

This action returns a new Color object that is black.

Return

Libraries.Game.Graphics.Color:

Example

use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable rectangle

    Color color

    action Main
        StartGame()
    end

    action CreateGame
        color = color:Black()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

Blue()

This action returns a new Color object that is blue.

Return

Libraries.Game.Graphics.Color:

Example

use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable rectangle

    Color color

    action Main
        StartGame()
    end

    action CreateGame
        color = color:Blue()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

CalculateContrast(Libraries.Game.Graphics.Color one, Libraries.Game.Graphics.Color two)

This action calculates the W3C color contrast between two colors passed as parameters. Contrast values range between 1 (minimum contrast) and 21 (maximum contrast).

Parameters

Return

number: the contrast, between 1 and 21

Example

use Libraries.Game.Graphics.Color
Color color
Color pinkish = color:CustomColor(236.0/255.0,85.0/255.0,93.0/255.0,1)
contrast = color:CalculateContrast(pinkish, color:White())
output contrast

CalculateContrast(Libraries.Game.Graphics.Color two)

This action calculates the W3C color contrast between the current color and the color passed. Contrast values range between 1 (minimum contrast) and 21 (maximum contrast).

Parameters

Return

number: the contrast, between 1 and 21

Example

use Libraries.Game.Graphics.Color
Color color
Color pinkish = color:CustomColor(236.0/255.0,85.0/255.0,93.0/255.0,1)
contrast = pinkish:CalculateContrast(color:White())
output contrast

CalculateLuminance()

This action calculates the W3C luminance of the current color. Luminance ranges from 0 (black) to 1 (white). The potential values include the endpoints of 0 and 1.

Return

number: the luminance, between 0 and 1 (inclusive)

Example

use Libraries.Game.Graphics.Color
Color color //black by default
contrast = color:CalculateLuminance()
output contrast

CalculateLuminance(Libraries.Game.Graphics.Color color)

This action calculates the W3C luminance of the passed color. Luminance ranges from 0 (black) to 1 (white). The potential values include the endpoints of 0 and 1.

Parameters

Return

number: the luminance, between 0 and 1 (inclusive)

Example

use Libraries.Game.Graphics.Color
Color color
contrast = color:CalculateLuminance(color:White())
output contrast

Clamp()

This action sets all color component values to be between 0 and 1.

Return

Libraries.Game.Graphics.Color:

Example

use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable rectangle

    Color color

    action Main
        StartGame()
    end

    action CreateGame
        color:SetRed(50)
        color:SetBlue(-10)
        color:SetGreen(0.5)
        color:SetAlpha(1)
        color:Clamp()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

Clear()

This action returns a new Color object that is clear.

Return

Libraries.Game.Graphics.Color:

Example

use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable rectangle

    Color color

    action Main
        StartGame()
    end

    action CreateGame
        color = color:Clear()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

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)

Copy()

This action returns a new color that is a copy of this color.

Return

Libraries.Game.Graphics.Color:

Example

use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Game

class Main is Game
    
    Color original
    Color copy

    action Main is Game
        StartGame()
    end

    action CreateGame
        original = original:Navy()
        copy = original:Copy()
    end
end

CopyColor(Libraries.Game.Graphics.Color copyColor)

This action sets this color to be identical to the given color parameter.

Parameters

Example

use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Game

class Main is Game
    
    Color original
    Color copy

    action Main is Game
        StartGame()
    end

    action CreateGame
        original = original:Navy()
        copy:CopyColor(original)
    end
end

CustomColor(number red, number green, number blue, number alpha)

This action returns a new color with the given red, green, blue, and alpha values, where 0 represents a total absence of that component and 1 represents a full presence of it. Alpha is the opacity of a color, where 0 represents total transparency and 1 represents total opacity.

Parameters

  • number red
  • number green
  • number blue
  • number alpha

Return

Libraries.Game.Graphics.Color:

Example

use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable rectangle

    Color color

    action Main
        StartGame()
    end

    action CreateGame
        rectangle:LoadFilledRectangle(100, 50, color:CustomColor(1, 0.7, 0, 1))
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

Cyan()

This action returns a new Color object that is cyan.

Return

Libraries.Game.Graphics.Color:

Example

use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable rectangle

    Color color

    action Main
        StartGame()
    end

    action CreateGame
        color = color:Cyan()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

DarkGray()

This action returns a new Color object that is dark gray.

Return

Libraries.Game.Graphics.Color:

Example

use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable rectangle

    Color color

    action Main
        StartGame()
    end

    action CreateGame
        color = color:DarkGray()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

EncodeColorAsNumber()

This action encodes this color as a number. This is used primarily for internal use, and most users will never need to use this action directly.

Return

number:

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)

GetAlpha()

This action returns the alpha component of this color.

Return

number:

Example

use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable rectangle

    Color color

    action Main
        StartGame()
    end

    action CreateGame
        color:SetColor(0.5, 0.7, 0.9, 1)
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
        output "The alpha value is " + color:GetAlpha()
    end
end

GetBlue()

This action returns the blue component of this color.

Return

number:

Example

use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable rectangle

    Color color

    action Main
        StartGame()
    end

    action CreateGame
        color:SetColor(0.5, 0.7, 0.9, 1)
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
        output "The blue value is " + color:GetBlue()
    end
end

GetBottomLeft()

This action returns what color is applied to the bottom left corner of an object which is using this Color. Note that for a Color object, the returned value is the same Color object from which the action was called, and all four corner actions (GetTopLeft(), GetTopRight(), GetBottomLeft(), and GetBottomRight()) return the same value.

Return

Libraries.Game.Graphics.Color: The Color object that the action was called from.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Gradient

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        color = color:Orange()
        
        Color corner = gradient:GetBottomLeft()
        output "The color's values are: " + corner:GetRed() + ", " + corner:GetBlue() + ", " + corner:GetGreen() + ", " + corner:GetAlpha()
    end

end

GetBottomRight()

This action returns what color is applied to the bottom right corner of an object which is using this Color. Note that for a Color object, the returned value is the same Color object from which the action was called, and all four corner actions (GetTopLeft(), GetTopRight(), GetBottomLeft(), and GetBottomRight()) return the same value.

Return

Libraries.Game.Graphics.Color: The Color object that the action was called from.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Gradient

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        color = color:Orange()
        
        Color corner = gradient:GetTopLeft()
        output "The color's values are: " + corner:GetRed() + ", " + corner:GetBlue() + ", " + corner:GetGreen() + ", " + corner:GetAlpha()
    end

end

GetColorCode()

This action will return the color as an integer in the RGBA8888 format, or in other words, in the 32 bit integer, the highest 8 bits represent the red, the next 8 represent the green, the next 8 represent the blue, and the final 8 represent the alpha (which is usually transparency). This is used primarily for internal use, and most users will never need to use this action directly.

Return

integer:

GetGreen()

This action returns the green component of this color.

Return

number:

Example

use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable rectangle

    Color color

    action Main
        StartGame()
    end

    action CreateGame
        color:SetColor(0.5, 0.7, 0.9, 1)
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
        output "The green value is " + color:GetGreen()
    end
end

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()

GetHexColorWithAlpha()

This action returns a 8-character hexadecimal string representing this color. The color is made of red, green, blue, and alpha components, each of which is represented by two hex characters (in that order). Some formats do not uniformly support alpha values for hex color codes, such as SVGs. If you need a hex string that does not include alpha information, use "GetHexColorWithoutAlpha()" instead.

Return

text: A 8-character hex string representing the RGBA components of this color.

Example

use Libraries.Game.Graphics.Color

Color color
color:SetColor(0.0, 1.0, 1.0, 0.70)

// This will output "00FFFFB2", representing no red, full green and blue, and 70% opacity
output color:GetHexColorWithAlpha()

GetHexColorWithoutAlpha()

This action returns a 6-character hexadecimal string representing this color. The color is made of red, green, and blue components, each of which is represented by two hex characters (in that order). This does not include any information on the alpha component. This is useful for formats that do not uniformly support alpha values for hex color codes, such as SVGs. If you need a hex string that does include alpha information, use "GetHexColorWithAlpha()" instead.

Return

text: A 6-character hex string representing the RGB components of this color.

Example

use Libraries.Game.Graphics.Color

Color color
Color red = color:Red()

// This will output "FF0000", representing full red and no green or blue
output red:GetHexColorWithoutAlpha()

GetRed()

This action returns the red component of this color.

Return

number:

Example

use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable rectangle

    Color color

    action Main
        StartGame()
    end

    action CreateGame
        color:SetColor(0.5, 0.7, 0.9, 1)
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
        output "The red value is " + color:GetRed()
    end
end

GetTopLeft()

This action returns what color is applied to the top left corner of an object which is using this Color. Note that for a Color object, the returned value is the same Color object from which the action was called, and all four corner actions (GetTopLeft(), GetTopRight(), GetBottomLeft(), and GetBottomRight()) return the same value.

Return

Libraries.Game.Graphics.Color: The Color object that the action was called from.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Gradient

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        color = color:Orange()
        
        Color corner = gradient:GetTopLeft()
        output "The color's values are: " + corner:GetRed() + ", " + corner:GetBlue() + ", " + corner:GetGreen() + ", " + corner:GetAlpha()
    end

end

GetTopRight()

This action returns what color is applied to the top right corner of an object which is using this Color. Note that for a Color object, the returned value is the same Color object from which the action was called, and all four corner actions (GetTopLeft(), GetTopRight(), GetBottomLeft(), and GetBottomRight()) return the same value.

Return

Libraries.Game.Graphics.Color: The Color object that the action was called from.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Gradient

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        color = color:Orange()
        
        Color corner = gradient:GetTopRight()
        output "The color's values are: " + corner:GetRed() + ", " + corner:GetBlue() + ", " + corner:GetGreen() + ", " + corner:GetAlpha()
    end

end

Gray()

This action returns a new Color object that is gray.

Return

Libraries.Game.Graphics.Color:

Example

use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable rectangle

    Color color

    action Main
        StartGame()
    end

    action CreateGame
        color = color:Gray()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

Green()

This action returns a new Color object that is green.

Return

Libraries.Game.Graphics.Color:

Example

use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable rectangle

    Color color

    action Main
        StartGame()
    end

    action CreateGame
        color = color:Green()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

LightGray()

This action returns a new Color object that is light gray.

Return

Libraries.Game.Graphics.Color:

Example

use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable rectangle

    Color color

    action Main
        StartGame()
    end

    action CreateGame
        color = color:LightGray()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

LinearInterpolation(Libraries.Game.Graphics.Color targetColor, number coefficient)

This action will perform linear interpolation between this Color and the provided target Color using the given interpolation coefficient, which can be between 0 and 1 (inclusive). The Color that called this action will be changed to reflect the results of the linear interpolation.

Parameters

Example

use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable rectangle

    Color color
    Color targetColor

    action Main
        StartGame()
    end

    action CreateGame
        rectangle:LoadFilledRectangle(100, 50, color:White())
        rectangle:SetPosition(50, 50)
        Add(rectangle)

        color:SetColor(1, 1, 1, 1)
        targetColor:SetColor(1, 0, 0, 1)
    end

    action Update(number seconds)
        color:LinearInterpolation(targetColor, 0.5 * seconds)
        rectangle:SetColor(color)
    end
end