This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
1.0.0 1.0.1

ColorRecord

This module exposes the ColorRecord type. Color records can be manipulated mathemaitcall, e.g., if x and y are color records, then so is mix x y -- it is a kind of average of x and y .

The function rgba x y converts a color record to a string compatible with SVG.

API

type alias ColorRecord = { r : Int, g : Int, b : Int, a : Float }

A record which represents a color.

rgba : ColorRecord -> String

Convert a ColorRecord into a string compatible with SVG

mix : ColorRecord -> ColorRecord -> ColorRecord

Take the average of two ColorRecords

module ColorRecord exposing (ColorRecord, rgba, mix)

{-| This module exposes the ColorRecord type. Color records
can be manipulated mathemaitcall, e.g., if x and y are
color records, then so is mix x y -- it is a kind of average
of x and y .

The function rgba x y converts a color record to a string compatible
with SVG.


# API

@docs ColorRecord, rgba, mix

-}


{-| A record which represents a color.
-}
type alias ColorRecord =
    { r : Int, g : Int, b : Int, a : Float }


{-| Take the average of two ColorRecords
-}
mix : ColorRecord -> ColorRecord -> ColorRecord
mix a b =
    let
        rr =
            intAverage a.r b.r

        gg =
            intAverage a.g b.g

        bb =
            intAverage a.b b.b

        aa =
            (a.a + b.a) / 2.0
    in
        ColorRecord rr gg bb aa


intAverage i j =
    let
        sum =
            toFloat <| i + j

        average =
            sum / 2.0
    in
        round average


{-| Convert a ColorRecord into a string compatible with SVG
-}
rgba : ColorRecord -> String
rgba color =
    "rgba(" ++ toString color.r ++ "," ++ toString color.g ++ "," ++ toString color.b ++ "," ++ toString color.a ++ ")"