~/bend-docscommunity

lib.bend checks

raw source on the hub · import 0xc6ecb72f45a1b2f83318765698582f7f/lib.bend as Lib

Color — Layer 1: Rgb/Hsl types, conversion, and string show for Bend 2.0.2.

Channel conventions (documented, not enforced by the constructors): - Rgb.r/g/b: U32 octets in 0..=255 (values outside are clamped by convert helpers that go through channel_u8 / channel_to_u8). - Rgb.a / Hsl.a: F32 alpha, conventionally 0.0..=1.0. - Hsl.h: F32 hue in degrees, conventionally 0.0..=360.0. - Hsl.s / Hsl.l: F32 saturation and lightness in the unit interval 0.0..=1.0.

Conversion uses Base F32 arithmetic. Results are approximate: F32 ops are opaque to definitional equality, and channel_to_u8 rounds with F32.round then clamps. Primary colors and many modest RGB triples round-trip at runtime; that is not a definitional claim.

Layer 1 only: no random_*, no sampling. ColorRange validates min/max without RNG. Base only; no termination escapes.

1 import
import Base

Types

type Rgb source · line 19 · raw

Data

type Hsl source · line 22 · raw

Data

type ColorRange source · line 27 · raw

Data

Inclusive RGB axis-aligned box for later sampling layers. Alpha is part of each endpoint; validate checks every channel with the natural order.

Definitions

def Color.rgb source · line 33 · raw

@r:U32 -> @g:U32 -> @b:U32 -> @a:F32 -> Rgb

def Color.hsl source · line 36 · raw

@h:F32 -> @s:F32 -> @l:F32 -> @a:F32 -> Hsl

def Color.range source · line 39 · raw

@min:Rgb -> @max:Rgb -> ColorRange

def Color.clamp_u8 source · line 45 · raw

@x:U32 -> U32

def Color.clamp_unit source · line 48 · raw

@+x:F32 -> F32

def Color.clamp_hue source · line 51 · raw

@+h:F32 -> F32

def Color.clamp_rgb source · line 54 · raw

@c:Rgb -> Rgb

def Color.clamp_hsl source · line 63 · raw

@c:Hsl -> Hsl

def Color.rgb_r source · line 75 · raw

@c:Rgb -> U32

def Color.rgb_g source · line 80 · raw

@c:Rgb -> U32

def Color.rgb_b source · line 85 · raw

@c:Rgb -> U32

def Color.rgb_a source · line 90 · raw

@c:Rgb -> F32

def Color.hsl_h source · line 95 · raw

@c:Hsl -> F32

def Color.hsl_s source · line 100 · raw

@c:Hsl -> F32

def Color.hsl_l source · line 105 · raw

@c:Hsl -> F32

def Color.hsl_a source · line 110 · raw

@c:Hsl -> F32

def Color.channel_u8 source · line 118 · raw

@+x:U32 -> F32

def Color.channel_to_u8 source · line 121 · raw

@+x:F32 -> U32

def Color.rgb_to_hsl.hue_from_r source · line 128 · raw

@+r:F32 -> @+g:F32 -> @+b:F32 -> @+d:F32 -> F32

def Color.rgb_to_hsl.hue source · line 132 · raw

@+r:F32 -> @+g:F32 -> @+b:F32 -> @+mx:F32 -> @+d:F32 -> F32

def Color.rgb_to_hsl.sat source · line 139 · raw

@+mx:F32 -> @+mn:F32 -> @+l:F32 -> @+d:F32 -> F32

def Color.rgb_to_hsl.chromatic source · line 144 · raw

@+r:F32 -> @+g:F32 -> @+b:F32 -> @+mx:F32 -> @+mn:F32 -> @+l:F32 -> @+a:F32 -> Hsl

def Color.rgb_to_hsl source · line 153 · raw

@c:Rgb -> Hsl

def Color.hue2rgb.go2 source · line 169 · raw

@+p:F32 -> @+q:F32 -> @+t:F32 -> @c2:Bool -> F32

def Color.hue2rgb.go source · line 178 · raw

@+p:F32 -> @+q:F32 -> @+t:F32 -> @c1:Bool -> F32

def Color.hue2rgb.wrap source · line 183 · raw

@+t:F32 -> F32

def Color.hue2rgb source · line 187 · raw

@+p:F32 -> @+q:F32 -> @+t0:F32 -> F32

def Color.hsl_to_rgb.chromatic source · line 191 · raw

@+h:F32 -> @+s:F32 -> @+l:F32 -> @+a:F32 -> Rgb

def Color.hsl_to_rgb source · line 206 · raw

@c:Hsl -> Rgb

def Color.to_rgba_string source · line 219 · raw

@c:Rgb -> String

def Color.to_hsla_string source · line 228 · raw

@c:Hsl -> String

def Color.range_rgb_le source · line 240 · raw

@a:Rgb -> @b:Rgb -> Bool

def Color.range_valid source · line 247 · raw

@r:ColorRange -> Bool