-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcolor.js
More file actions
78 lines (72 loc) · 1.64 KB
/
color.js
File metadata and controls
78 lines (72 loc) · 1.64 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
import { setAlpha } from "./utils.js";
/**
* @typedef {number[]} color An array of 3 (RGB) or 4 (A) values.
*
* All components in the range 0 <= x <= 1
*/
/**
* Creates a new color from linear values.
* @alias module:pex-color.create
* @param {number} [r=0]
* @param {number} [g=0]
* @param {number} [b=0]
* @param {number} [a]
* @returns {color}
*/
export function create(r = 0, g = 0, b = 0, a = 1) {
return [r, g, b, a];
}
/**
* Returns a copy of a color.
* @alias module:pex-color.copy
* @param {color} color
* @returns {color}
*/
export function copy(color) {
return color.slice();
}
/**
* Sets a color to another color.
* @alias module:pex-color.set
* @param {color} color
* @param {color} color2
* @returns {color}
*/
export function set(color, color2) {
color[0] = color2[0];
color[1] = color2[1];
color[2] = color2[2];
return setAlpha(color, color2[3]);
}
/**
* Updates a color based on r, g, b, [a] values.
* @alias module:pex-color.fromValues
* @param {import("./color.js").color} color
* @param {number} r
* @param {number} g
* @param {number} b
* @param {number} [a]
* @returns {import("./color.js").color}
*/
export function fromValues(color, r, g, b, a) {
color[0] = r;
color[1] = g;
color[2] = b;
return setAlpha(color, a);
}
/**
* @deprecated Use "fromValues()".
* @ignore
*/
export function fromRGB(color, r, g, b, a) {
console.error(`"fromRGB()" deprecated. Use "fromValues()".`);
return fromValues(color, r, g, b, a);
}
/**
* @deprecated Use "set()".
* @ignore
*/
export function toRGB(color, out = []) {
console.error(`"toRGB()" deprecated. Use "set()".`);
return set(out, color);
}