on eb2a032 help sign in
elk/libraries/Color.elm
100 lines 3.2 kB history raw
2module Color where
4import Native.Color
5import Basics ((-))
7data Color = Color Int Int Int Float
9-- Create RGB colors with an alpha component for transparency.
10-- The alpha component is specified with numbers between 0 and 1.
11rgba : Int -> Int -> Int -> Float -> Color
12rgba = Color
14-- Create RGB colors from numbers between 0 and 255 inclusive.
15rgb : Int -> Int -> Int -> Color
16rgb r g b = Color r g b 1
18lightYellow = Color 255 233 79 1
19yellow = Color 237 212 0 1
20darkYellow = Color 196 160 0 1
22lightOrange = Color 252 175 62 1
23orange = Color 245 121 0 1
24darkOrange = Color 206 92 0 1
26lightBrown = Color 233 185 110 1
27brown = Color 193 125 17 1
28darkBrown = Color 143 89 2 1
30lightGreen = Color 138 226 52 1
31green = Color 115 210 22 1
32darkGreen = Color 78 154 6 1
34lightBlue = Color 114 159 207 1
35blue = Color 52 101 164 1
36darkBlue = Color 32 74 135 1
38lightPurple = Color 173 127 168 1
39purple = Color 117 80 123 1
40darkPurple = Color 92 53 102 1
42lightRed = Color 239 41 41 1
43red = Color 204 0 0 1
44darkRed = Color 164 0 0 1
46black = Color 0 0 0 1
47white = Color 255 255 255 1
49lightGrey = Color 238 238 236 1
50grey = Color 211 215 207 1
51darkGrey = Color 186 189 182 1
53lightGray = Color 238 238 236 1
54gray = Color 211 215 207 1
55darkGray = Color 186 189 182 1
57lightCharcoal = Color 136 138 133 1
58charcoal = Color 85 87 83 1
59darkCharcoal = Color 46 52 54 1
61grayscale : Float -> Color
62grayscale p = hsv 0 0 (1-p)
63greyscale p = hsv 0 0 (1-p)
65-- Produce a “complementary color”.
66-- The two colors will accent each other.
67complement : Color -> Color
68complement = Native.Color.complement
70-- Create [HSV colors](http://en.wikipedia.org/wiki/HSL_and_HSV)
71-- with an alpha component for transparency.
72hsva : Float -> Float -> Float -> Float -> Color
73hsva = Native.Color.hsva
75-- Create [HSV colors](http://en.wikipedia.org/wiki/HSL_and_HSV).
76-- This is very convenient for creating colors that cycle and shift.
77-- Hue is an angle and should be given in standard Elm angles (radians).
78--
79-- hsv (degrees 240) 1 1 == blue
80hsv : Float -> Float -> Float -> Color
81hsv = Native.Color.hsv
83data Gradient
84 = Linear (Float,Float) (Float,Float) [(Float,Color)]
85 | Radial (Float,Float) Float (Float,Float) Float [(Float,Color)]
87-- Create a linear gradient. Takes a start and end point and then a series
88-- of “color stops” that indicate how to interpolate between
89-- the start and end points. See [this example](/edit/examples/Elements/LinearGradient.elm) for
90-- a more visual explanation.
91linear : (number, number) -> (number, number) -> [(Float,Color)] -> Gradient
92linear = Linear
94-- Create a radial gradient. First takes a start point and inner radius.
95-- Then takes an end point and outer radius. It then takes a series
96-- of “color stops” that indicate how to interpolate between
97-- the inner and outer circles. See [this example](/edit/examples/Elements/RadialGradient.elm) for
98-- a more visual explanation.
99radial : (number,number) -> number -> (number,number) -> number -> [(Float,Color)] -> Gradient
100radial = Radial