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

LinearInterpolation(number r, number g, number b, number a, number coefficient)

This action will perform linear interpolation between this Color and the provided red, green, blue, and alpha color values 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

  • number r
  • number g
  • number b
  • number a
  • number coefficient

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:White())
        rectangle:SetPosition(50, 50)
        Add(rectangle)

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

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

Magenta()

This action returns a new Color object that is magenta.

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:Magenta()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

Maroon()

This action returns a new Color object that is maroon.

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:Maroon()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

This action returns a new Color object that is navy.

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:Navy()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

Olive()

This action returns a new Color object that is olive.

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:Olive()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

Orange()

This action returns a new Color object that is orange.

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:Orange()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

Pink()

This action returns a new Color object that is pink.

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:Pink()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

Purple()

This action returns a new Color object that is purple.

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:Purple()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

Red()

This action returns a new Color object that is red.

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:Red()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

SetAlpha(number aVal)

This action sets the alpha component of this color. The value passed should be between 0 and 1, where 0 represents total transparency, and 1 represents total opacity.

Parameters

  • number aVal

Example

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

class Main is Game

    Drawable rectangle

    Color black

    action Main
        StartGame()
    end

    action CreateGame
        black:SetAlpha(1)
        rectangle:LoadFilledRectangle(100, 50, black)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

SetBlue(number bVal)

This action sets the blue component of this color. The value passed should be between 0 and 1, where 0 represents a total lack of blue, and 1 represents a full presence of blue.

Parameters

  • number bVal

Example

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

class Main is Game

    Drawable rectangle

    Color blue

    action Main
        StartGame()
    end

    action CreateGame
        blue:SetBlue(1)
        blue:SetAlpha(1)
        rectangle:LoadFilledRectangle(100, 50, blue)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

SetColor(number redValue, number greenValue, number blueValue, number alphaValue)

This action sets a color by setting its 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 redValue
  • number greenValue
  • number blueValue
  • number alphaValue

Example

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

class Main is Game

    Drawable rectangle

    Color orange

    action Main
        StartGame()
    end

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

SetColorFromCode(integer code)

This action is used internally by the game engine to set a color using an integer value representing a color. Most users will never need to use this action directly.

Parameters

  • integer code

SetGreen(number gVal)

This action sets the green component of this color. The value passed should be between 0 and 1, where 0 represents a total lack of green, and 1 represents a full presence of green.

Parameters

  • number gVal

Example

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

class Main is Game

    Drawable rectangle

    Color green

    action Main
        StartGame()
    end

    action CreateGame
        green:SetGreen(1)
        green:SetAlpha(1)
        rectangle:LoadFilledRectangle(100, 50, green)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

SetHexColor(text hexValue)

This action sets the color using a hexadecimal string. The hexadecimal string must be 6 or 8 hex characters long, and can optionally be preceded by a pound symbol ("#"). From left to right, the color will use each set of 2 hex characters to set the red, green, blue, and alpha components, in that order. If there are only 6 characters, the alpha will be set to 1.0 (fully opaque).

Parameters

  • text hexValue: 6 or 8 hexadecimal characters, which can optionally have a "#" at the front

Example


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

class Main is Game

    action CreateGame
        // This hex value represents full red, no green, and full blue.
        text hexValue1 = "FF00FF"

        // This hex value represents no red, full green, and some blue. The alpha value is set to roughly half-transparency.
        // Note that the text isn't case sensitive, so lowercase "f" and uppercase "F" are the same thing.
        text hexValue2 = "#00ff4588"

        // Loading our hex values into a pair of colors.
        Color color1
        color1:SetHexColor(hexValue1)
        Color color2
        color2:SetHexColor(hexValue2)

        // Loading drawables using our new colors, as an example of what the loaded colors look like.
        Drawable box1
        box1:LoadFilledRectangle(100, 100, color1)
        Add(box1)
    
        Drawable box2
        box2:LoadFilledRectangle(100, 100, color2)
        box2:SetPosition(50, 50)
        Add(box2)
    end

    action Main
        StartGame()
    end

end

SetRed(number rVal)

This action sets the red component of this color. The value passed should be between 0 and 1, where 0 represents a total lack of red, and 1 represents a full presence of red.

Parameters

  • number rVal

Example

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

class Main is Game

    Drawable rectangle

    Color red

    action Main
        StartGame()
    end

    action CreateGame
        red:SetRed(1)
        red:SetAlpha(1)
        rectangle:LoadFilledRectangle(100, 50, red)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

Teal()

This action returns a new Color object that is teal.

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:Teal()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

White()

This action returns a new Color object that is white.

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:White()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

Yellow()

This action returns a new Color object that is yellow.

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:Yellow()
        rectangle:LoadFilledRectangle(100, 50, color)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end