The Color Type
To represent colors the botfather script engine provides a
Color type. Some botfather APIs take instances of
Color as parameters. Feel free to use and extend the
Color type yourself in your bot scripts.
Table of contents
- Table of contents
- RGB color instanciation
- HSV Color instanciation
- Instanciate colors by their name
- Color methods
RGB color instanciation
The most common way to represent colors is by using their RGB (red, gree, blue) values. Each RGB value ranges from 0 to 255. Red for example can be represented like this:
var red = new Color(255, 0, 0);
Programs like GIMP or Paint.net can help you choose the
Color you want to represent and it’s RGB values.
There are also tons of online tools available, just search for rgb color picker using your favourite search engine.
Some RGB examples
var gold = new Color(255,215,0);
var crimson = new Color(220,20,60);
var purple = new Color(128,0,128);
HSV Color instanciation
When working with color ranges you might want to use the HSV color space instead of RGB. HSV stands for Hue, Saturation and Value. A HSV
Color object can be instanciated like this:
var hsv_blue = new Color(240, 255, 127, 'hsv');
The hue must be in range of 0-359. Both the saturation and value must be in range of 0-255.
Instanciate colors by their name
Simple colors can be instantiated using their name. To create a variable representing green you could write:
var green = new Color('green');
The following inbuild color names can be used to instanciate
Color variables in botfather scripts.
If you want to define a more complex color like crimson or teal, use the RGB or HSV based instanciation discussed earlier.
Inbuild color names:
You can also create an initially invalid
Color object bei neither providing a color name or RGB/HSV values:
var invalid_color = new Color();
Returns true if the color is valid; otherwise returns false.
Returns a number between 0 and 255 representing the colors RGB red value.
red_value: The colors new RGB red value (number between 0 and 255).
Alters the colors RGB red value.
Returns a number between 0 and 255 representing the colors RGB green value.
green_value: The colors new RGB green value (number between 0 and 255).
Alters the colors RGB green value.
Returns a number between 0 and 255 representing the colors RGB blue value.
blue_value: The colors new RGB blue value (number between 0 and 255).
Alters the colors RGB blue value.
Color.setHsv(hue, saturation, value);
Sets the colors hue, saturation and value HSV color space components.
Returns the hue color HSV color space component of this color.
Returns the saturation color component of this color.
Returns the value color component of this color.