PINE LIBRARY
Updated

UtilityLibrary

Library "UtilityLibrary"
A collection of custom utility functions used in my scripts.

milliseconds_per_bar()
  Gets the number of milliseconds per bar.
  Returns: (int) The number of milliseconds per bar.

realtime()
  Checks if the current bar is the actual realtime bar.
  Returns: (bool) `true` when the current bar is the actual realtime bar, `false` otherwise.

replay()
  Checks if the current bar is the last replay bar.
  Returns: (bool) `true` when the current bar is the last replay bar, `false` otherwise.

bar_elapsed()
  Checks how much of the current bar has elapsed.
  Returns: (float) Between 0 and 1.

even(number)
  Checks if a number is even.
  Parameters:
    number (float): (float) The number to evaluate.
  Returns: (bool) `true` when the number is even, `false` when the number is odd.

sign(number)
  Gets the sign of a float.
  Parameters:
    number (float): (float) The number to evaluate.
  Returns: (int) 1 or -1, unlike math.sign() which returns 0 if the number is 0.

atan2(y, x)
  Derives an angle in radians from the XY coordinate.
  Parameters:
    y (float): (float) Y coordinate.
    x (float): (float) X coordinate.
  Returns: (float) Between -π and π.

clamp(number, min, max)
  Ensures a value is between the `min` and `max` thresholds.
  Parameters:
    number (float): (float) The number to clamp.
    min (float): (float) The minimum threshold (0 by default).
    max (float): (float) The maximum threshold (1 by default).
  Returns: (float) Between `min` and `max`.

remove_gamma(value)
  Removes gamma from normalized sRGB channel values.
  Parameters:
    value (float): (float) The normalized channel value [0, 1].
  Returns: (float) Channel value with gamma removed.

add_gama(value)
  Adds gamma into normalized linear RGB channel values.
  Parameters:
    value (float): (float) The normalized channel value [0, 1].
  Returns: (float) Channel value with gamma added.

rgb_to_xyz(Color)
  Extracts XYZ-D65 channels from sRGB colors.
  Parameters:
    Color (color): (color) The sRGB color to process.
  Returns: (float tuple) [x, y, z]

xyz_to_rgb(x, y, z)
  Converts XYZ-D65 channels to sRGB channels.
  Parameters:
    x (float): (float) The X channel value.
    y (float): (float) The Y channel value.
    z (float): (float) The Z channel value.
  Returns: (int tuple) [r, g, b]

rgb_to_oklab(Color)
  Extracts OKLAB-D65 channels from sRGB colors.
  Parameters:
    Color (color): (color) The sRGB color to process.
  Returns: (float tuple) [l, a, b]

oklab_to_rgb(l, a, b)
  Converts OKLAB-D65 channels to sRGB channels.
  Parameters:
    l (float): (float) The L channel value.
    a (float): (float) The A channel value.
    b (float): (float) The B channel value.
  Returns: (int tuple) [r, g, b]

rgb_to_oklch(Color)
  Extracts OKLCH channels from sRGB colors.
  Parameters:
    Color (color): (color) The sRGB color to process.
  Returns: (float tuple) [l, c, h]

oklch_to_rgb(l, c, h)
  Converts OKLCH channels to sRGB channels.
  Parameters:
    l (float): (float) The L channel value.
    c (float): (float) The C channel value.
    h (float): (float) The H channel value.
  Returns: (float tuple) [r, g, b]

hues(l1, h1, l2, h2, dist)
  Ensures the hue angles are set correctly for linearly interpolating OKLCH.
  Parameters:
    l1 (float): (float) The first L channel value.
    h1 (float): (float) The first H channel value.
    l2 (float): (float) The second L channel value.
    h2 (float): (float) The second H channel value.
    dist (string): (string) The preferred angular distance to use. Options: `min` or `max` (`min` by default).
  Returns: (float tuple) [h1, h2]

lerp(a, b, t)
  Linearly interpolates between two values.
  Parameters:
    a (float): (float) The starting point (first value).
    b (float): (float) The ending point (second value).
    t (float): (float) The interpolation factor [0, 1].
  Returns: (float) Between `a` and `b`.

smoothstep(t, precise)
  A non-linear (smooth) interpolation between 0 and 1.
  Parameters:
    t (float): (float) The interpolation factor [0, 1].
    precise (bool): (bool) Sets if the calc should be precise or efficient (`true` by default).
  Returns: (float) Between 0 and 1.

ease(t, n, v, x1, y1, x2, y2)
  A customizable non-linear interpolation between 0 and 1.
  Parameters:
    t (float): (float) The interpolation factor [0, 1].
    n (float): (float) The degree of ease [0≤] (1 by default).
    v (string): (string) The easing variant type: `in-out`, `in`, or `out` (`in-out` by default).
    x1 (float): (float) Optional X coordinate of starting point [0, 1] (0 by default).
    y1 (float): (float) Optional Y coordinate of starting point [0, 1] (0 by default).
    x2 (float): (float) Optional X coordinate of ending point [0, 1] (1 by default).
    y2 (float): (float) Optional Y coordinate of ending point [0, 1] (1 by default).
  Returns: (float) Between 0 and 1.

mix(color1, color2, blend, space, dist)
  Linearly interpolates between two colors.
  Parameters:
    color1 (color): (color) The first color.
    color2 (color): (color) The second color.
    blend (float): (float) The interpolation factor [0, 1].
    space (string): (string) The color space to use for interpolating. Options: `rgb`, `oklab`, and `oklch` (`rgb` by default).
    dist (string): (string) The anglular distance to use for the hue change when the color space is set to `oklch`. Options: `min` and `max` (`min` by default).
  Returns: (color) Blend of `color1` and `color2`.
Release Notes
v2

Added:
fade(Color, Alpha)
  Linearly interpolates a colors transparency.
  Parameters:
    Color (color): (color) The color to process.
    Alpha (float): (float) The interpolation factor [0, 1], where `0` is fully transparent and `1` is the original transparency value (0.5 by default).
  Returns: (color) The same RGB color with an interpolated A channel.

Disclaimer