@@ -27,7 +27,25 @@ import Internal.Truth
27
27
import qualified "base" Prelude as P
28
28
import "base" Prelude ((.) )
29
29
30
+ -- | A color.
31
+ --
32
+ -- Colors can be described in several ways:
33
+ --
34
+ -- 1. Using common color names: 'red', 'blue', 'yellow', 'green',
35
+ -- 'orange', 'purple', 'pink', 'black', 'white', 'brown', and
36
+ -- 'gray'.
37
+ -- 2. Transforming other colors with functions such as 'light',
38
+ -- 'dark', 'bright', 'dull', 'translucent', and 'mixed'.
39
+ -- 3. Constructing colors from coordinates in a color space, such
40
+ -- as 'RGB', 'RGBA', or 'HSL'.
41
+ --
42
+ -- Note that transparency is included in a color. Common color
43
+ -- names and the 'RGB' and 'HSL' constructors only produce opaque
44
+ -- colors, but 'RGBA' and the 'translucent' function work with
45
+ -- transparency.
30
46
newtype Color = Color { toCWColor :: CW. Color } deriving (P.Eq )
47
+
48
+ -- | A synonym for 'Color', using the non-US spelling.
31
49
type Colour = Color
32
50
33
51
{-# RULES
@@ -72,36 +90,95 @@ fromHSL :: (Number, Number, Number) -> Color
72
90
fromHSL (h, s, l) =
73
91
Color (CW. HSL (toDouble (pi * h / 180 )) (toDouble s) (toDouble l))
74
92
93
+ -- | Produces a color by mixing other colors in equal proportion.
94
+ --
95
+ -- The order of colors is unimportant. Colors may be mixed in uneven
96
+ -- proportions by listing a color more than once, such as
97
+ -- @mixed([red, red, orange])@.
75
98
mixed :: [Color ] -> Color
76
99
mixed = Color . CW. mixed . P. map toCWColor
77
100
101
+ -- | Increases the luminosity of a color by the given amount.
102
+ --
103
+ -- The amount should be between -1 and 1, where:
104
+ --
105
+ -- * @lighter(c, 1)@ is always white, regardless of @c@.
106
+ -- * @lighter(c, 0)@ is the same as @c@.
107
+ -- * @lighter(c, -1)@ is always black, regardless of @c@.
78
108
lighter :: (Color , Number ) -> Color
79
109
lighter (c, d) = Color (CW. lighter (toDouble d) (toCWColor c))
80
110
111
+ -- | Produces a lighter shade of the given color.
112
+ --
113
+ -- This function may be nested more than once to produce an even
114
+ -- lighter shade, as in @light(light(blue))@.
81
115
light :: Color -> Color
82
116
light = Color . CW. light . toCWColor
83
117
118
+ -- | Decreases the luminosity of a color by the given amount.
119
+ --
120
+ -- The amount should be between -1 and 1, where:
121
+ --
122
+ -- * @darker(c, 1)@ is always black, regardless of @c@.
123
+ -- * @darker(c, 0)@ is the same as @c@.
124
+ -- * @darker(c, -1)@ is always white, regardless of @c@.
84
125
darker :: (Color , Number ) -> Color
85
126
darker (c, d) = Color (CW. darker (toDouble d) (toCWColor c))
86
127
128
+ -- | Produces a darker shade of the given color.
129
+ --
130
+ -- This function may be nested more than once to produce an even
131
+ -- darker shade, as in @dark(dark(green))@.
87
132
dark :: Color -> Color
88
133
dark = Color . CW. dark . toCWColor
89
134
135
+ -- | Increases the saturation of a color by the given amount.
136
+ --
137
+ -- The amount should be between -1 and 1, where:
138
+ --
139
+ -- * @brighter(c, 1)@ is a fully saturated version of @c@.
140
+ -- * @brighter(c, 0)@ is the same as @c@.
141
+ -- * @brighter(c, -1)@ is just a shade of gray with no color.
90
142
brighter :: (Color , Number ) -> Color
91
143
brighter (c, d) = Color (CW. brighter (toDouble d) (toCWColor c))
92
144
145
+ -- | Produces a brighter shade of the given color; that is, less
146
+ -- gray and more colorful.
147
+ --
148
+ -- This function may be nested more than once to produce an even
149
+ -- brighter shade, as in @bright(bright(yellow))@.
93
150
bright :: Color -> Color
94
151
bright = Color . CW. bright . toCWColor
95
152
153
+ -- | Decreases the saturation of a color by the given amount.
154
+ --
155
+ -- The amount should be between -1 and 1, where:
156
+ --
157
+ -- * @duller(c, 1)@ is just a shade of gray with no color.
158
+ -- * @duller(c, 0)@ is the same as @c@.
159
+ -- * @duller(c, -1)@ is a fully saturated version of @c@.
96
160
duller :: (Color , Number ) -> Color
97
161
duller (c, d) = Color (CW. duller (toDouble d) (toCWColor c))
98
162
163
+ -- | Produces a duller shade of the given color; that is, more
164
+ -- gray and less colorful.
165
+ --
166
+ -- This function may be nested more than once to produce an even
167
+ -- duller shade, as in @dull(dull(purple))@.
99
168
dull :: Color -> Color
100
169
dull = Color . CW. dull . toCWColor
101
170
171
+ -- | Produces a partially transparent color.
172
+ --
173
+ -- This function may be nested more than once to produce an even
174
+ -- more transparent color, as in @translucent(translucent(brown))@.
102
175
translucent :: Color -> Color
103
176
translucent = Color . CW. translucent . toCWColor
104
177
178
+ -- | An infinite list of various colors.
179
+ --
180
+ -- The list is chosen to contain a variety of different hues as
181
+ -- spread out as possible to create colorful effects.
105
182
assortedColors :: [Color ]
106
183
assortedColors = P. map Color CW. assortedColors
107
184
@@ -116,32 +193,65 @@ alpha = fromDouble . CW.alpha . toCWColor
116
193
117
194
-- New style colors
118
195
119
- -- Old style colors
120
-
121
- white , black , red , green , blue , cyan , magenta , yellow :: Color
122
- orange , rose , chartreuse , aquamarine , violet , azure :: Color
123
- gray , grey :: Color
124
-
196
+ -- | The color white
197
+ white :: Color
125
198
white = Color CW. white
199
+
200
+ -- | The color black
201
+ black :: Color
126
202
black = Color CW. black
203
+
204
+ -- | The color gray
205
+ gray :: Color
127
206
gray = Color CW. gray
207
+
208
+ -- | The color grey
209
+ --
210
+ -- This is the same color as 'gray', but with a non-US
211
+ -- spelling.
212
+ grey :: Color
128
213
grey = Color CW. grey
214
+
215
+ -- | The color red
216
+ red :: Color
129
217
red = Color CW. red
218
+
219
+ -- | The color orange
220
+ orange :: Color
130
221
orange = Color CW. orange
222
+
223
+ -- | The color yellow
224
+ yellow :: Color
131
225
yellow = Color CW. yellow
226
+
227
+ -- | The color green
228
+ green :: Color
132
229
green = Color CW. green
230
+
231
+ -- | The color blue
232
+ blue :: Color
133
233
blue = Color CW. blue
234
+
235
+ -- | The color purple
236
+ purple :: Color
134
237
purple = Color CW. purple
238
+
239
+ -- | The color pink
240
+ pink :: Color
135
241
pink = Color CW. pink
242
+
243
+ -- | The color brown
244
+ brown :: Color
136
245
brown = Color CW. brown
137
246
247
+ cyan , magenta , rose , chartreuse , aquamarine , violet , azure :: Color
138
248
cyan = Color CW. cyan
139
249
magenta = Color CW. magenta
250
+ rose = Color CW. rose
140
251
chartreuse = Color CW. chartreuse
141
252
aquamarine = Color CW. aquamarine
142
- azure = Color CW. azure
143
253
violet = Color CW. violet
144
- rose = Color CW. rose
254
+ azure = Color CW. azure
145
255
146
256
{-# WARNING magenta [ "Please use HSL(300, 0.75, 0.5) instead of magenta."
147
257
, "The variable magenta may be removed July 2020." ] #-}
@@ -157,3 +267,11 @@ rose = Color CW.rose
157
267
, "The variable rose may be removed July 2020." ] #-}
158
268
{-# WARNING violet [ "Please use purple instead of violet."
159
269
, "The variable violet may be removed July 2020." ] #-}
270
+ {-# WARNING hue [ "Please match HSL(...) instead of using hue(...)."
271
+ , "The hue function may be removed July 2020." ] #-}
272
+ {-# WARNING saturation [ "Please match HSL(...) instead of using saturation(...)."
273
+ , "The saturation function may be removed July 2020." ] #-}
274
+ {-# WARNING luminosity [ "Please match HSL(...) instead of using luminosity(...)."
275
+ , "The luminosity function may be removed July 2020." ] #-}
276
+ {-# WARNING alpha [ "Please match RGBA(...) instead of using alpha(...)."
277
+ , "The alpha function may be removed July 2020." ] #-}
0 commit comments