* Gets the color as a string * @param {boolean} alpha Whether to include alpha
(alpha)
| 34 | * @param {boolean} alpha Whether to include alpha |
| 35 | */ |
| 36 | toString(alpha) { |
| 37 | let r = this.r.toString(16); |
| 38 | let g = this.g.toString(16); |
| 39 | let b = this.b.toString(16); |
| 40 | let a = this.a.toString(16); |
| 41 | |
| 42 | if (r.length === 1) r = `0${r}`; |
| 43 | if (g.length === 1) g = `0${g}`; |
| 44 | if (b.length === 1) b = `0${b}`; |
| 45 | if (a.length === 1) a = `0${a}`; |
| 46 | |
| 47 | const hex = () => `#${r}${g}${b}`.toUpperCase(); |
| 48 | const hexA = () => `#${r}${g}${b}${a}`.toUpperCase(); |
| 49 | |
| 50 | if (alpha === undefined) { |
| 51 | return this.a === 255 ? hex() : hexA(); |
| 52 | } |
| 53 | |
| 54 | return alpha ? hexA() : hex(); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Gets the color as an RGB object |