Reference | Utility

These utility functions are provided for the convenience of Perlenspiel programmers.

PS.MakeRGB ( r, g, b )

Takes three values representing red, green and blue color components, and returns a multiplexed value suitable for use with commands requiring an RGB color parameter.

Parameters:

  1. r : integer
  2. g : integer
  3. b : integer

Returns: integer

Each parameter value must be in the range of 0-255 inclusive. Values outside this range are clamped.

If a parameter error occurs, the value PS.ERROR is returned.

PS.UnmakeRGB ( rgb )

Takes a multiplexed rgb value and returns a table with separate red, green and blue component values.

Parameters:

  1. rgb : integer

Returns: table

The rgb parameter must be a multiplexed RGB color value in the range 0x000000 to 0xFFFFFF. An error occurs (and the value PS.ERROR is returned) if the rgb parameter is invalid.

The returned table contains three elements (named r, g and b), each containing a value between 0 and 255 inclusive.

PS.Random ( val )

Returns a random integer between 1 and the supplied value.

Parameters:

  1. val : integer

Returns: integer

The val parameter should be an integer greater than 1. Any value less than 2 will return the value 1. An error occurs (and the value PS.ERROR is returned) if the val parameter is invalid.

Example:

PS.Click = function ( x, y, data, options )
{
    "use strict";
    var r;

    // set bead to a random shade of red

    r = PS.Random (255);
    PS.BeadColor( x, y, PS.MakeRGB(r, 0, 0) );
};