Conversions

All the functions used for conversions in the library are listed here.

Angle Conversions

Degree to Radian

The function degToRad(deg) converts the given angle in degrees to radians.
You might use it a lot because, all the angle inputs in the library are in radians.

                
    degToRad(angleInDegrees);

    degToRad(90);         // returns 1.5707963267948966
            

Radian to Degree

The function radToDeg(rad) converts the given angle in radians to degrees.

                
    radToDeg(angleInRadians);

    radToDeg(PI);          // returns 180
            

Color Conversions

RGB to Hex

The function RGBtoHex(r,g,b) converts the given RGB color to Hex color form.
It returns a string with the Hex color value.

                
    RGBtoHex(r,g,b);

    RGBtoHex(255,0,0);     // returns "#ff0000"
            

Parameters

r Number [0-255] : Red value of the color
g Number [0-255] : Green value of the color
b Number [0-255] : Blue value of the color

RGB( , , )

Hex to RGB

The function HexToRGB(hex) converts the given Hex color to RGB color form.
It returns an object with the properties r, g, b.

                
    HexToRGB(hex);

    HexToRGB("#ff0000");   // returns {r: 255, g: 0, b: 0}
            

Parameters

hex String : Hex color value


RGB to HSL

The function RGBtoHSL(r,g,b) converts the given RGB color to HSL color form.
It returns an object with the properties h, s, l.

                
    RGBtoHSL(r,g,b);

    RGBtoHSL(255,0,0);     // returns {h: 0, s: 100%, l: 50%}
            

Parameters

r Number [0-255] : Red value of the color
g Number [0-255] : Green value of the color
b Number [0-255] : Blue value of the color

RGB( , , )

HSL to RGB

The function HSLtoRGB(h,s,l) converts the given HSL color to RGB color form.
It returns an object with the properties r, g, b.

                
    HSLtoRGB(h,s,l);

    HSLtoRGB(0,100%,50%);   // returns {r: 255, g: 0, b: 0}
            

Parameters

h Number [0-360] : Hue value of the color
s Number [0-100] : Saturation value of the color
Enter only the number, and not the percentage sign.
l Number [0-100] : Lightness value of the color
Enter only the number, and not the percentage sign.

HSL( , %, % )

HSL to Hex

The function HSLtoHex( h, s, l ) converts the given HSL color to Hex color form.
It returns a string with the Hex color value.

                
    HSLtoHex(h,s,l);

    HSLtoHex(188,100,60);      // returns '#33e3ff'
    

Parameters

h Number [0-360] : Hue value of the color
s Number [0-100] : Saturation value of the color
Enter only the number, and not the percentage sign.
l Number [0-100] : Lightness value of the color
Enter only the number, and not the percentage sign.

HSL( , %, % )

Hex to HSL

The function HexToHSL(hex) converts the given Hex color to HSL color form.
It returns an object with the properties h, s, l.

                
    HexToHSL(hex);

    HexToHSL('#33e3ff');      // returns {h: 188, s: 100, l: 60}
            

Parameters

hex String : Hex color value