-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolors.js
49 lines (44 loc) · 1.31 KB
/
colors.js
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
/**
* Função que facilita a criação de instância da classe color @see {@link RGBA}
* @param {number} r Entre 0 e 255 (integer)
* @param {number} g Entre 0 e 255 (integer)
* @param {number} b Entre 0 e 255 (integer)
* @param {number} [a] Entre 0 e 1 (flot)
* @returns {RGBA}
*/
export function rgba(r, g, b, a = 1) {
return new RGBA(r, g, b, a);
}
export class RGBA {
/**
* Contrói uma instância de elemento usada para representar uma cor rgb com
* canal alfa.
* @param {number} r Entre 0 e 255 (integer)
* @param {number} g Entre 0 e 255 (integer)
* @param {number} b Entre 0 e 255 (integer)
* @param {number} [a] Entre 0 e 1 (float)
*/
constructor(r, g, b, a = 1) {
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
/**
*
* @param {number} [value] Valor de escurecimento. Exemplo: 0.1 equivale
* a dizer que a cor terá todos os canais de cor reduzidos em 10% do valor
* atual.
* @returns {RGBA}
*/
darken(value = 0.1) {
return new RGBA(
Math.max(this.r * (1 - value), 0),
Math.max(this.g * (1 - value), 0),
Math.max(this.b * (1 - value), 0),
);
}
toString() {
return `rgba(${this.r}, ${this.g}, ${this.b}, ${this.a})`;
}
}