diff --git a/js/util/Color.js b/js/util/Color.js index ecdf53002..5f4b942b0 100644 --- a/js/util/Color.js +++ b/js/util/Color.js @@ -562,6 +562,19 @@ class Color { return this.constructor.name + '[r:' + this.r + ' g:' + this.g + ' b:' + this.b + ' a:' + this.a + ']'; } + /** + * Convert to a hex string, that starts with "#". + * @public + * @returns {string} + */ + toHex() { + let hexString = this.toNumber().toString( 16 ); + while ( hexString.length < 6 ) { + hexString = `0${hexString}`; + } + return `#${hexString}`; + } + /** * @public * @@ -573,7 +586,7 @@ class Color { g: this.g, b: this.b, a: this.a, - hex: '#' + this.toNumber().toString( 16 ) + hex: this.toHex() }; }