2012-10-05 02:01:20 +00:00
|
|
|
|
2013-04-28 12:21:46 +00:00
|
|
|
module Color where
|
2013-02-10 11:58:40 +00:00
|
|
|
|
2013-07-29 21:23:04 +00:00
|
|
|
import Native.Color
|
2013-07-25 22:19:21 +00:00
|
|
|
|
2012-10-05 02:01:20 +00:00
|
|
|
data Color = Color Int Int Int Float
|
|
|
|
|
2013-04-10 05:15:06 +00:00
|
|
|
-- Create RGB colors with an alpha component for transparency.
|
|
|
|
-- The alpha component is specified with numbers between 0 and 1.
|
2013-04-08 08:49:44 +00:00
|
|
|
rgba : Int -> Int -> Int -> Float -> Color
|
2012-10-05 02:01:20 +00:00
|
|
|
rgba = Color
|
2013-03-24 12:45:56 +00:00
|
|
|
|
|
|
|
-- Create RGB colors from numbers between 0 and 255 inclusive.
|
2013-04-08 08:49:44 +00:00
|
|
|
rgb : Int -> Int -> Int -> Color
|
2012-10-05 02:01:20 +00:00
|
|
|
rgb r g b = Color r g b 1
|
|
|
|
|
2013-04-08 08:49:44 +00:00
|
|
|
red : Color
|
|
|
|
red = Color 255 0 0 1
|
|
|
|
lime : Color
|
|
|
|
lime = Color 0 255 0 1
|
|
|
|
blue : Color
|
|
|
|
blue = Color 0 0 255 1
|
2013-02-10 11:58:40 +00:00
|
|
|
|
2013-04-08 08:49:44 +00:00
|
|
|
yellow : Color
|
2012-10-05 02:01:20 +00:00
|
|
|
yellow = Color 255 255 0 1
|
2013-04-08 08:49:44 +00:00
|
|
|
cyan : Color
|
2012-10-05 02:01:20 +00:00
|
|
|
cyan = Color 0 255 255 1
|
2013-04-08 08:49:44 +00:00
|
|
|
magenta : Color
|
2012-10-05 02:01:20 +00:00
|
|
|
magenta = Color 255 0 255 1
|
2013-02-10 11:58:40 +00:00
|
|
|
|
2013-04-08 08:49:44 +00:00
|
|
|
black : Color
|
|
|
|
black = Color 0 0 0 1
|
|
|
|
white : Color
|
|
|
|
white = Color 255 255 255 1
|
|
|
|
|
|
|
|
gray : Color
|
|
|
|
gray = Color 128 128 128 1
|
|
|
|
grey : Color
|
|
|
|
grey = Color 128 128 128 1
|
|
|
|
|
|
|
|
maroon : Color
|
|
|
|
maroon = Color 128 0 0 1
|
|
|
|
navy : Color
|
|
|
|
navy = Color 0 0 128 1
|
|
|
|
green : Color
|
|
|
|
green = Color 0 128 0 1
|
|
|
|
|
|
|
|
teal : Color
|
|
|
|
teal = Color 0 128 128 1
|
|
|
|
purple : Color
|
|
|
|
purple = Color 128 0 128 1
|
|
|
|
|
|
|
|
violet : Color
|
2013-02-10 11:58:40 +00:00
|
|
|
violet = Color 238 130 238 1
|
2013-04-08 08:49:44 +00:00
|
|
|
forestGreen : Color
|
|
|
|
forestGreen = Color 34 139 34 1
|
2013-02-10 11:58:40 +00:00
|
|
|
|
2013-04-08 08:49:44 +00:00
|
|
|
-- Produce a “complementary color”.
|
|
|
|
-- The two colors will accent each other.
|
2013-03-10 09:40:31 +00:00
|
|
|
complement : Color -> Color
|
2013-07-29 21:23:04 +00:00
|
|
|
complement = Native.Color.complement
|
2013-03-24 12:45:56 +00:00
|
|
|
|
2013-05-17 20:46:08 +00:00
|
|
|
-- Create [HSV colors](http://en.wikipedia.org/wiki/HSL_and_HSV)
|
|
|
|
-- with an alpha component for transparency.
|
|
|
|
hsva : Float -> Float -> Float -> Float -> Color
|
2013-07-29 21:23:04 +00:00
|
|
|
hsva = Native.Color.hsva
|
2013-03-24 12:45:56 +00:00
|
|
|
|
2013-05-17 20:46:08 +00:00
|
|
|
-- Create [HSV colors](http://en.wikipedia.org/wiki/HSL_and_HSV).
|
|
|
|
-- This is very convenient for creating colors that cycle and shift.
|
2013-08-11 03:07:57 +00:00
|
|
|
-- Hue is an angle and should be given in standard Elm angles (radians).
|
2013-03-24 12:45:56 +00:00
|
|
|
--
|
2013-05-17 20:46:08 +00:00
|
|
|
-- hsv (degrees 240) 1 1 == blue
|
|
|
|
hsv : Float -> Float -> Float -> Color
|
2013-07-29 21:23:04 +00:00
|
|
|
hsv = Native.Color.hsv
|
2013-03-06 03:46:35 +00:00
|
|
|
|
|
|
|
data Gradient
|
2013-04-08 08:49:44 +00:00
|
|
|
= Linear (Float,Float) (Float,Float) [(Float,Color)]
|
|
|
|
| Radial (Float,Float) Float (Float,Float) Float [(Float,Color)]
|
2013-03-06 03:46:35 +00:00
|
|
|
|
2013-05-16 20:10:50 +00:00
|
|
|
-- Create a linear gradient. Takes a start and end point and then a series
|
|
|
|
-- of “color stops” that indicate how to interpolate between
|
|
|
|
-- the start and end points. See [this example](/edit/examples/Elements/LinearGradient.elm) for
|
|
|
|
-- a more visual explanation.
|
2013-07-25 14:40:56 +00:00
|
|
|
linear : (number, number) -> (number, number) -> [(Float,Color)] -> Gradient
|
2013-03-10 09:40:31 +00:00
|
|
|
linear = Linear
|
2013-05-16 20:10:50 +00:00
|
|
|
|
|
|
|
-- Create a radial gradient. First takes a start point and inner radius.
|
|
|
|
-- Then takes an end point and outer radius. It then takes a series
|
|
|
|
-- of “color stops” that indicate how to interpolate between
|
|
|
|
-- the inner and outer circles. See [this example](/edit/examples/Elements/RadialGradient.elm) for
|
|
|
|
-- a more visual explanation.
|
2013-07-25 14:40:56 +00:00
|
|
|
radial : (number,number) -> number -> (number,number) -> number -> [(Float,Color)] -> Gradient
|
2013-03-14 08:04:51 +00:00
|
|
|
radial = Radial
|