Module colorizer.color

Provides color conversion and utility functions for RGB and HSL values.

Functions

hsl_to_rgb (h, s, l) Converts an HSL color value to RGB.
hue_to_rgb (p, q, t) Converts an HSL component to RGB, used within `hsl_to_rgb`.
is_bright (r, g, b) Determines whether a color is bright, helping decide text color.


Functions

hsl_to_rgb (h, s, l)
Converts an HSL color value to RGB. Accepts hue, saturation, and lightness values, each within the range [0, 1], and converts them to an RGB color representation with values scaled to [0, 255].

Parameters:

  • h number: Hue, in the range [0, 1].
  • s number: Saturation, in the range [0, 1].
  • l number: Lightness, in the range [0, 1].

Returns:

  1. number|nil,number|nil,number|nil: Returns red, green, and blue values scaled to [0, 255], or nil if any input value is out of range.
  2. number|nil,number|nil,number|nil
hue_to_rgb (p, q, t)
Converts an HSL component to RGB, used within `hsl_to_rgb`. Source: https://gist.github.com/mjackson/5311256 This function computes one component of the RGB value by adjusting the color based on intermediate values `p`, `q`, and `t`.

Parameters:

  • p number: A helper variable representing part of the lightness scale.
  • q number: Another helper variable based on saturation and lightness.
  • t number: Adjusted hue component to be converted to RGB.

Returns:

    number: The RGB component value, in the range [0, 1].
is_bright (r, g, b)
Determines whether a color is bright, helping decide text color. ref: https://stackoverflow.com/a/1855903/837964 https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color Calculates the perceived luminance of the RGB color. Returns `true` if the color is bright enough to warrant black text and `false` otherwise. Formula based on the human eye’s sensitivity to different colors.

Parameters:

  • r number: Red component, in the range [0, 255].
  • g number: Green component, in the range [0, 255].
  • b number: Blue component, in the range [0, 255].

Returns:

    boolean: `true` if the color is bright, `false` if it's dark.
generated by LDoc 1.5.0 Last updated - December