Sign in

    color

    rgb2hsl and hsl2rgb convertor

    color
    converter
    hsl
    hsla
    rgb
    rgba
    Download zip
    Version
    0.2.3
    License
    Apache-2.0
    Last updated
    last year
    Downloads
    41

    No dependencies

    #illusory0x0/color

    #Usage

    use hsl_to_rgb and rgb_to_hsl to convert color.

    use Color to store RGBA color (32 bits), It is not recommended use to_hsl to convert RGB to HSL and then use to_color to convert HSL to RGB, it will lose precision due to truncation.

    Color

    type Color
    RGBA color
    impl Compare for Color
    impl Default for Color
    impl Eq for Color
    impl Hash for Color
    impl Show for Color

    Color::alpha

    fn Color::alpha(self : Color) -> Byte

    Color::blue

    fn Color::blue(self : Color) -> Byte

    Color::green

    fn Color::green(self : Color) -> Byte

    Color::hsl

    fn Color::hsl(hue : UInt, saturation : UInt, lightness : UInt) -> Color

    Color::hsla

    fn Color::hsla(hue : UInt, saturation : UInt, lightness : UInt, alpha : UInt) -> Color

    • hue in [0,360)

    • saturation in [0,100]

    • lightness in [0,100]

    • alpha in [0,100]

    Color::new

    fn Color::new(x : UInt) -> Color

    Color::red

    fn Color::red(self : Color) -> Byte

    Color::rgb

    fn Color::rgb(red : Byte, green : Byte, blue : Byte) -> Color

    Color::rgba

    fn Color::rgba(red : Byte, green : Byte, blue : Byte, alpha : Byte) -> Color

    • red in [0,255]

    • green in [0,255]

    • blue in [0,255]

    • alpha in [0,255]

    Color::to_hsl

    fn Color::to_hsl(self : Color) -> HSL

    HSL

    pub struct HSL {
    hue : UInt
    saturation : UInt
    lightness : UInt
    }
    HSL color
    impl Compare for HSL
    impl Default for HSL
    impl Eq for HSL
    impl Hash for HSL
    impl Show for HSL

    HSL::new

    fn HSL::new(hue : UInt, saturation : UInt, lightness : UInt) -> HSL

    HSL::to_color

    fn HSL::to_color(self : HSL) -> Color

    HSL::to_hsla

    fn HSL::to_hsla(self : HSL) -> HSLA

    HSLA

    pub struct HSLA {
    hue : UInt
    saturation : UInt
    lightness : UInt
    alpha : UInt
    }
    HSLA color
    impl Compare for HSLA
    impl Default for HSLA
    impl Eq for HSLA
    impl Hash for HSLA
    impl Show for HSLA

    HSLA::new

    fn HSLA::new(hue : UInt, saturation : UInt, lightness : UInt, alpha : UInt) -> HSLA

    HSLA::to_color

    fn HSLA::to_color(self : HSLA) -> Color

    HSLA::to_hsl

    fn HSLA::to_hsl(self : HSLA) -> HSL

    hsl_to_rgb

    fn hsl_to_rgb(h : Double, s : Double, l : Double) -> (Double, Double, Double)

    h in [0,360)

    s in [0,1]

    l in [0,1]

    rgb_to_hsl

    fn rgb_to_hsl(r : Double, g : Double, b : Double) -> (Double, Double, Double)

    • r in [0,1]

    • g in [0,1]

    • b in [0,1]

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io