Blendend.Style.Color (blendend v0.2.0)
View SourceColor helpers for the blendend drawing API.
This module works with color resources representing RGBA colors and provides convenience constructors in RGB, HSL, and HSV. You can also read back the RGBA components.
Summary
Functions
Returns the RGBA components of a color as integers 0..255.
Same as components/1, but raises on failure.
Convenience helper that accepts either {h, s, v} or positional h, s, v (with optional alpha).
Creates a color from HSL (hue–saturation–lightness) plus alpha.
Creates a color from HSV (hue–saturation–value) plus alpha.
Creates a color in RGBA space.
Same as rgb/4, but returns the color directly and raises on failure.
Types
Functions
Returns the RGBA components of a color as integers 0..255.
On success, returns {:ok, {r, g, b, a}}.
On failure, returns {:error, reason}.
@spec components!(t()) :: {0..255, 0..255, 0..255, 0..255}
Same as components/1, but raises on failure.
@spec from_hsv({number(), number(), number()}, nil | number(), nil | number(), 0..255) :: t()
@spec from_hsv(number(), number(), number(), 0..255) :: t()
Convenience helper that accepts either {h, s, v} or positional h, s, v (with optional alpha).
Creates a color from HSL (hue–saturation–lightness) plus alpha.
h_deg– hue in degrees (0–360)s– saturation 0.0–1.0l– lightness 0.0–1.0a– alpha 0–255 (default 255)
Returns an RGBA color resource. Values outside the typical ranges are not clamped; pass normalized inputs.
Creates a color from HSV (hue–saturation–value) plus alpha.
h_deg– hue in degrees (0–360)s– saturation 0.0–1.0v– value (brightness) 0.0–1.0a– alpha 0–255 (default 255)
Returns an RGBA color resource. Inputs are expected to be normalized.
@spec random() :: Color.t()
Creates a random t/0.
Creates a color in RGBA space.
All channels are integers in the range 0..255. The alpha channel
defaults to 255 (fully opaque).
On success, returns {:ok, color}.
On failure, returns {:error, reason} from the NIF.
@spec rgb!(0..255, 0..255, 0..255, 0..255) :: t()
Same as rgb/4, but returns the color directly and raises on failure.
On success, returns the color resource.
On failure, raises Blendend.Error.