-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathcolor.js
More file actions
256 lines (213 loc) · 5.56 KB
/
color.js
File metadata and controls
256 lines (213 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/**
* @fileoverview A wrapper for colors.
* @suppress {useOfGoogProvide}
*/
goog.provide('ee.Color');
goog.require('ee.ApiFunction');
goog.require('ee.ComputedObject');
/**
* An object to represent colors.
*
* @param {string|!Array<number>|!ee.ComputedObject} color
* 1) A W3C compatible color string.
* 2) A list of RGBA values in the range of [0:1].
* 3) A ComputedObject returning a color.
* @constructor
* @extends {ee.ComputedObject}
* @export
*/
ee.Color = function(color) {
if (!(this instanceof ee.Color)) {
return new ee.Color(color);
}
ee.Color.initialize();
if (color instanceof ee.ComputedObject) {
ee.Color.base(this, 'constructor', color.func, color.args, color.varName);
} else {
ee.Color.base(
this, 'constructor', new ee.ApiFunction('Color'), {'input': color});
}
};
goog.inherits(ee.Color, ee.ComputedObject);
/**
* Whether the class has been initialized.
* @type {boolean}
* @private
*/
ee.Color.initialized_ = false;
/**
* Imports API functions to this class.
*/
ee.Color.initialize = function() {
if (!ee.Color.initialized_) {
ee.ApiFunction.importApi(ee.Color, 'Color', 'Color');
ee.Color.initialized_ = true;
}
};
/**
* Removes imported API functions from this class.
*/
ee.Color.reset = function() {
ee.ApiFunction.clearApi(ee.Color);
ee.Color.initialized_ = false;
};
/**
* @override
* @return {string}
*/
ee.Color.prototype.name = function() {
return 'Color';
};
/**
* Creates a Color given a list of HSV values.
*
* @param {!Array<number>|!ee.ComputedObject} hsv A list of HSV (hue,
* saturation, value) values in the range [0:1].
* @return {!ee.Color}
* @export
*/
ee.Color.fromHsv = function(hsv) {
return /** @type {!ee.Color} */ (ee.ApiFunction._call('Color.fromHsv', hsv));
};
/**
* Creates a Color given a list of HSL values.
*
* @param {!Array<number>|!ee.ComputedObject} hsl A list of HSL (hue,
* saturation, luminosity) values in the range [0:1].
* @return {!ee.Color}
* @export
*/
ee.Color.fromHsl = function(hsl) {
return /** @type {!ee.Color} */ (ee.ApiFunction._call('Color.fromHsl', hsl));
};
/**
* Creates a Color given a list of CIE-LAB values.
*
* @param {!Array<number>|!ee.ComputedObject} lab A list of CIE-LAB values.
* @return {!ee.Color}
* @export
*/
ee.Color.fromLab = function(lab) {
return /** @type {!ee.Color} */ (ee.ApiFunction._call('Color.fromLab', lab));
};
/**
* Creates a Color given a list of CIE-LCH values.
*
* @param {!Array<number>|!ee.ComputedObject} lch A list of CIE-LCH (lightness,
* chroma, hue) values.
* @return {!ee.Color}
* @export
*/
ee.Color.fromLch = function(lch) {
return /** @type {!ee.Color} */ (ee.ApiFunction._call('Color.fromLch', lch));
};
/**
* Creates a gray color.
*
* @param {number|!ee.ComputedObject} value The gray value in the range [0:1].
* @param {number|!ee.ComputedObject=} opt_alpha The alpha value in the range
* [0:1].
* @return {!ee.Color}
* @export
*/
ee.Color.gray = function(value, opt_alpha) {
return /** @type {!ee.Color} */ (
ee.ApiFunction._call('Color.gray', value, opt_alpha));
};
/**
* Mixes two colors.
*
* @param {!ee.Color} start The starting color.
* @param {!ee.Color} end The ending color.
* @param {number|!ee.ComputedObject=} opt_ratio The mix ratio.
* @param {string|!ee.ComputedObject=} opt_colorspace The colorspace to mix
* in.
* @return {!ee.Color}
* @export
*/
ee.Color.mix = function(start, end, opt_ratio, opt_colorspace) {
return /** @type {!ee.Color} */ (
ee.ApiFunction._call('Color.mix', start, end, opt_ratio, opt_colorspace));
};
/**
* Scale each of the RGB channels to produce a brighter color.
*
* @param {number|!ee.ComputedObject=} opt_scale The scale factor.
* @return {!ee.Color}
* @export
*/
ee.Color.prototype.brighter = function(opt_scale) {
return /** @type {!ee.Color} */ (
ee.ApiFunction._call('Color.brighter', this, opt_scale));
};
/**
* Scale each of the RGB channels to produce a darker color.
*
* @param {number|!ee.ComputedObject=} opt_scale The scale factor.
* @return {!ee.Color}
* @export
*/
ee.Color.prototype.darker = function(opt_scale) {
return /** @type {!ee.Color} */ (
ee.ApiFunction._call('Color.darker', this, opt_scale));
};
/**
* Convert a color to HSL.
*
* @return {!ee.ComputedObject}
* @export
*/
ee.Color.prototype.toHsl = function() {
return /** @type {!ee.ComputedObject} */ (
ee.ApiFunction._call('Color.toHsl', this));
};
/**
* Convert a color to HSV.
*
* @return {!ee.ComputedObject}
* @export
*/
ee.Color.prototype.toHsv = function() {
return /** @type {!ee.ComputedObject} */ (
ee.ApiFunction._call('Color.toHsv', this));
};
/**
* Convert a color to CIE-Lab.
*
* @return {!ee.ComputedObject}
* @export
*/
ee.Color.prototype.toLab = function() {
return /** @type {!ee.ComputedObject} */ (
ee.ApiFunction._call('Color.toLab', this));
};
/**
* Convert a color to CIE-LCH.
*
* @return {!ee.ComputedObject}
* @export
*/
ee.Color.prototype.toLch = function() {
return /** @type {!ee.ComputedObject} */ (
ee.ApiFunction._call('Color.toLch', this));
};
/**
* Convert a color to RGB.
*
* @return {!ee.ComputedObject}
* @export
*/
ee.Color.prototype.toRgb = function() {
return /** @type {!ee.ComputedObject} */ (
ee.ApiFunction._call('Color.toRGB', this));
};
/**
* Returns value of a color as an RGBA hex string.
*
* @return {!ee.ComputedObject}
* @export
*/
ee.Color.prototype.toHexString = function() {
return /** @type {!ee.ComputedObject} */ (
ee.ApiFunction._call('Color.toHexString', this));
};