Libraries.Robots.Spike.ColorMatrix Documentation

The color matrix is an external device that is connected to the hub through a port. The color matrix is a 3x3 matrix of lights where the color and brightness of each pixel can be changed to display things.

Example Code


use Libraries.Robots.Spike.ColorMatrix
use Libraries.Robots.Spike.Color
use Libraries.Robots.Spike.Port
ColorMatrix cm
Color color
Port port
cm:SetPort(port:A)
cm:SetPixelColor(0, 0, color:RED, 100)

Inherits from: Libraries.Language.Object

Actions Documentation

Clear()

Clears all pixels on the color matrix

Example

use Libraries.Robots.Spike.ColorMatrix
use Libraries.Robots.Spike.Port
ColorMatrix cm
Port port
cm:SetPort(port:A)
cm:Clear()

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

GetPixelColor(integer x, integer y)

Returns the current color and intensity of the pixel at the provided x and y location

Parameters

  • integer x: The x location of the pixel, 0 to 2
  • integer y: The y location of the pixel, 0 to 2

Return

Libraries.Containers.Array: An array of size 2 with the color and intensity of the pixel

Example

use Libraries.Robots.Spike.ColorMatrix
use Libraries.Robots.Spike.Port
use Libraries.Containers.Array
ColorMatrix cm
Port port
cm:SetPort(port:A)
Array<integer> colorIntensity = cm:GetPixelColor(0, 0)

GetPort()

Returns the currently assigned port for this color matrix

Return

integer: The current port number

Example

use Libraries.Robots.Spike.ColorMatrix
ColorMatrix cm
integer port = cm:GetPort()

SetPixelColor(integer x, integer y, integer color, integer intensity)

Sets the color and intensity of the pixel at the provided x and y location

Parameters

  • integer x: The x location of the pixel, 0 to 2
  • integer y: The y location of the pixel, 0 to 2
  • integer color: The color constant to set the pixel to (see Color)
  • integer intensity: The intensity (brightness) to set the pixel to

Example

use Libraries.Robots.Spike.ColorMatrix
use Libraries.Robots.Spike.Color
use Libraries.Robots.Spike.Port
ColorMatrix cm
Color color
Port port
cm:SetPort(port:A)
cm:SetPixelColor(0, 0, color:RED, 100)

SetPort(integer port)

Sets the port for this color matrix

Parameters

  • integer port: The port to assign

Example

use Libraries.Robots.Spike.ColorMatrix
use Libraries.Robots.Spike.Port
ColorMatrix cm
Port port
cm:SetPort(port:A)

ShowColors(Libraries.Containers.Array<integer> colorValues, Libraries.Containers.Array<integer> intensityValues)

Changes the color and intensity (brightness) of all pixels from the provided color and intensity arrays

Parameters

Example

use Libraries.Robots.Spike.ColorMatrix
use Libraries.Robots.Spike.Color
use Libraries.Robots.Spike.Port
use Libraries.Containers.Array
ColorMatrix cm
Color color
Port port
Array<integer> colors
Array<integer> intensities
repeat 9 times
    colors:Add(color:RED)
    intensities:Add(100)
end
cm:SetPort(port:A)
cm:ShowColors(colors, intensities)