Color

There are two ways to generate colors using the tools library. One, using string method with constant color names. Two, using a gradient object method to get color based on number value.

Constants

Using the _color() method with constant color names. These constants follow a naming convention of color name followed by a type of shade: <color>_bright, <color>_light, <color>_medium, and <color>_dark. For example, "aqua_bright"._color() returns the color #00FFFF.

colorsconstantshex values
aqua_bright#00FFFF
aqua_light#00C8FF
aqua_medium#0096FF
aqua_dark#0078FF
black_bright#191919
black_light#0A0A0A
black_medium#050505
black_dark#000000
blue_bright#0000FF
blue_light#0000C8
blue_medium#000096
blue_dark#000078
gray_bright#3C4650
gray_light#2D3741
gray_medium#1E2832
gray_dark#0F1923
green_bright#00FF00
green_light#00C800
green_medium#009600
green_dark#007800
orange_bright#FF6400
orange_light#F55A00
orange_medium#EB5000
orange_dark#E14600
pink_bright#FF96FF
pink_light#FF64FF
pink_medium#FF32FF
pink_dark#FF00FF
purple_bright#9696FF
purple_light#9664FF
purple_medium#9632FF
purple_dark#9600FF
red_bright#FF0000
red_light#C80000
red_medium#960000
red_dark#780000
white_bright#FFFFFF
white_light#EBEBEB
white_medium#D7D7D7
white_dark#C8C8C8
yellow_bright#FFFF00
yellow_light#E6E600
yellow_medium#D2D200
yellow_dark#AFAF00

Usage examples:

// All available preset colors.

"aqua_bright"._color()   // returns the color #00FFFF.
"aqua_light"._color()    // returns the color #00C8FF.
"aqua_medium"._color()   // returns the color #0096FF.
"aqua_dark"._color()     // returns the color #0078FF.
"black_bright"._color()  // returns the color #191919.
"black_light"._color()   // returns the color #0A0A0A.
"black_medium"._color()  // returns the color #050505.
"black_dark"._color()    // returns the color #000000.
"blue_bright"._color()   // returns the color #0000FF.
"blue_light"._color()    // returns the color #0000C8.
"blue_medium"._color()   // returns the color #000096.
"blue_dark"._color()     // returns the color #000078.
"gray_bright"._color()   // returns the color #3C4650.
"gray_light"._color()    // returns the color #2D3741.
"gray_medium"._color()   // returns the color #1E2832.
"gray_dark"._color()     // returns the color #0F1923.
"green_bright"._color()  // returns the color #00FF00.
"green_light"._color()   // returns the color #00C800.
"green_medium"._color()  // returns the color #009600.
"green_dark"._color()    // returns the color #007800.
"orange_bright"._color() // returns the color #FF6400.
"orange_light"._color()  // returns the color #F55A00.
"orange_medium"._color() // returns the color #EB5000.
"orange_dark"._color()   // returns the color #E14600.
"pink_bright"._color()   // returns the color #FF96FF.
"pink_light"._color()    // returns the color #FF64FF.
"pink_medium"._color()   // returns the color #FF32FF.
"pink_dark"._color()     // returns the color #FF00FF.
"purple_bright"._color() // returns the color #9696FF.
"purple_light"._color()  // returns the color #9664FF.
"purple_medium"._color() // returns the color #9632FF.
"purple_dark"._color()   // returns the color #9600FF.
"red_bright"._color()    // returns the color #FF0000.
"red_light"._color()     // returns the color #C80000.
"red_medium"._color()    // returns the color #960000.
"red_dark"._color()      // returns the color #780000.
"white_bright"._color()  // returns the color #FFFFFF.
"white_light"._color()   // returns the color #EBEBEB.
"white_medium"._color()  // returns the color #D7D7D7.
"white_dark"._color()    // returns the color #C8C8C8.
"yellow_bright"._color() // returns the color #FFFF00.
"yellow_light"._color()  // returns the color #E6E600.
"yellow_medium"._color() // returns the color #D2D200.
"yellow_dark"._color()   // returns the color #AFAF00.

// The color method also accepts a parameter for passing transparency value. 
// By default, its always 0 (full transparency).

"aqua_bright"._color(transp=50)   // returns the color #00FFFF7F.

Gradient

The second use of the _color() method is with the _gradient object. It accepts a parameter for passing transparency value. By default, it's always 0 (full transparency). For example, "aqua_bright"._color(transp=50) returns the color #00FFFF7F. Let's look at some examples below.

Usage examples:

// Create a new _gradient object.
var gradient = tools._gradient.new(
                 max=100, 
                 min=-100, 
                 mid=0, 
                 up=color.lime, 
                 neutral=color.white, 
                 down=color.red)

// Examples of getting gradient colors.
gradient._color(num=25.08)   // returns color #BFF8DC.
gradient._color(num=-25.90)  // returns color #FFD2D2.
gradient._color(num=0)       // returns color #FFFFFF.
gradient._color(num=100)     // returns color #00E676.
gradient._color(num=-100)    // returns color #FF5252.
gradient._color(num=62.35)   // returns color #60EFA9.