Skip to content

Commit

Permalink
create toHex(), and bug fix to patch in zeros, phetsims/fourier-makin…
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Nov 13, 2020
1 parent 7b7a2ed commit e3d4658
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion js/util/Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -573,7 +586,7 @@ class Color {
g: this.g,
b: this.b,
a: this.a,
hex: '#' + this.toNumber().toString( 16 )
hex: this.toHex()
};
}

Expand Down

0 comments on commit e3d4658

Please sign in to comment.