Function toHex

Returns a colour in hex format #000000.

canvas.fillStyle = Colour.toHex(`blue`);
canvas.fillStyle = Colour.toHex({ h:0.5, s:0.1, l:1 });
canvas.fillStyle = Colour.toHex({ r: 1, g: 0.3, b: 0 });

Input colour can be a human-friendly colour name ("blue"), a HSL colour (eg. "hsl(0, 50%, 50%)")", an object {h,s,l} or {r,g,b}. '#' is included in the return string.

Transparent colour is returned as #00000000

  • Parameters

    Returns string

    Hex format, including #