Skip to main content

sm.color

Associated object type: Color

A color is represented using a red, green, blue and alpha component.
Colors are prominently used for blocks and parts that are colored by the Paint Tool.

To create one, use sm.color.new. It is possible to use hex 0xRRGGBBAA, RGBA 0.5, 0.5, 0.5, 1.0 or strings "RRGGBBAA".

Functions

new

local color = sm.color.new(r_hex_string, g, b, a)

Creates a new color object.

Parameters:

  • r_hex_string (number/hexInt/string): The red value if using RGBA or a hex integer/color string if not.
  • g (number): The green value, if using RGBA.
  • b (number): The blue value if using RGBA.
  • a (number, optional): The alpha (transparency) value if using RGBA.

Returns:

  • color (Color): The created color object.

getR

local r = sm.color.getR(color)

Returns the red component of the given color object.
This does the same as accessing Color.r, but can have better performance in certain cases.

Parameters:

  • color (Color): The color.

Returns:

  • r (number): The red component value.

getG

local g = sm.color.getG(color)

Returns the green component of the given color object.
This does the same as accessing Color.g, but can have better performance in certain cases.

Parameters:

  • color (Color): The color.

Returns:

  • g (number): The green component value.

getB

local b = sm.color.getB(color)

Returns the blue component of the given color object.
This does the same as accessing Color.b, but can have better performance in certain cases.

Parameters:

  • color (Color): The color.

Returns:

  • b (number): The blue component value.

getA

local a = sm.color.getA(color)

Returns the alpha/transparency component of the given color object.
This does the same as accessing Color.a, but can have better performance in certain cases.

Parameters:

  • color (Color): The color.

Returns:

  • a (number): The alpha component value.

setR

sm.color.setR(color, r)

Sets the red component of the given color object.
This does the same as setting Color.r, but can have better performance in certain cases.

Parameters:

  • color (Color): The color.
  • r (number): The red component value.

setG

sm.color.setG(color, g)

Sets the green component of the given color object.
This does the same as setting Color.g, but can have better performance in certain cases.

Parameters:

  • color (Color): The color.
  • g (number): The green component value.

setB

sm.color.setB(color, b)

Sets the blue component of the given color object.
This does the same as setting Color.b, but can have better performance in certain cases.

Parameters:

  • color (Color): The color.
  • b (number): The blue component value.

setA

sm.color.setA(color, a)

Sets the alpha/transparency component of the given color object.
This does the same as setting Color.a, but can have better performance in certain cases.

Parameters:

  • color (Color): The color.
  • a (number): The alpha component value.