amos-tool
Version:
amos ui tool
27 lines (26 loc) • 863 B
JavaScript
;
module.exports = {
randomHexColor: function() {
return (~~(Math.random() * (1 << 24))).toString(16);
},
randomRgbColor: function() {
return "rgb(" + this._random(255) + "," + this._random(255) + "," + this._random(255) + ")";
},
randomRgbaColor: function(r) {
var o = r || this._randomAlpha();
return "rgba(" + this._random(255) + "," + this._random(255) + "," + this._random(255) + "," + o + ")";
},
_randomAlpha: function() {
return parseFloat(Math.random().toFixed(2));
},
_random: function(r) {
return Math.floor(Math.random() * r + 1);
},
randomHexColorStr: function() {
return "#" + Math.random().toString(16).substring(2).substr(0, 6);
},
randomHexAlphaColorStr: function() {
var r = Math.round(255 * this._randomAlpha()).toString(16);
return this.randomHexColorStr() + r;
}
};