getColor function

int getColor(
  1. int r,
  2. int g,
  3. int b, [
  4. int a = 255,
])

Get the color with the given r, g, b, and a components.

The channel order of a uint32 encoded color is RGBA.

Implementation

int getColor(int r, int g, int b, [int a = 255]) =>
    // what we're doing here, is creating a 32 bit
    // integer by collecting the rgba in one integer.
    // we know for certain and we're also assuring that
    // all our variables' values are 255 at maximum,
    // which means that they can never be bigger than
    // 8 bits  so we can safely slide each one by 8 bits
    // for adding the other.
    (clamp255(a) << 24) |
    (clamp255(b) << 16) |
    (clamp255(g) << 8) |
    (clamp255(r));