Math.range = function(min, max) {
return min + Math.random() * (max - min);
Math.chance = function(probability) {
return Math.random() < probability;
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
this.isActive = (Math.chance(0.5));
Particle.COLORS = ['#ff0000', '#daede6', '#a3d9cc', '#738076', '#734357', '#f5496b', '#e3b1be'];
Particle.prototype.init = function() {
this.color = toRGB(Particle.COLORS[Math.round(Math.random() * (Particle.COLORS.length - 1))]);
this.fade = Math.range(0.005, 0.25);
this.grow = (this.fade > 0.01) ? Math.range(0.25, 0.5) : Math.range(0.05, 0.4);
this.x += Math.range(-10, 10);
this.y += Math.range(-10, 10);