diff --git a/README.md b/README.md index ac0448b..0652b6c 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,25 @@ How close two dots need to be, in pixels, before they join. 5 -The lower the number, the more extreme the parallax effect wil be. +The lower the number, the more extreme the parallax effect will be. + +### randomStrokeColor + + false + +Overwrites `strokeColor` - Randomises the stroke colours of the particles, picking a random greyscale color between `strokeColorMin` and `strokeColorMax`, where `0 = #000` and `15 = #FFF`. + +## strokeColorMin + + 0 + +Defines the minimum color selectable by the random color picker. Range 0-15. + +## strokeColorMax + + 15 + +Defines the maximum color selectable by the random color picker. Range 0-15. ### onInit diff --git a/jquery.particleground.js b/jquery.particleground.js index 3146625..dee2884 100644 --- a/jquery.particleground.js +++ b/jquery.particleground.js @@ -95,6 +95,15 @@ hook('onInit'); } + /** + Get a random color from #000 - #FFF (0-15) + **/ + function getRandColor(min,max) { + var t = ['#000','#111','#222','#333','#444','#555','#666','#777','#888','#999','#AAA','#BBB','#CCC','#DDD','#EEE','#FFF']; + var c = Math.floor((Math.random() * max) + min); + return t[c]; + } + /** * Style the canvas */ @@ -186,6 +195,11 @@ * Particle */ function Particle() { + if (options.randomStrokeColor) { + this.strokeColor = getRandColor(options.strokeColorMin,options.strokeColorMax); + } else { + this.strokeColor = options.strokeColor; + } this.stackPos; this.active = true; this.layer = Math.ceil(Math.random() * 3); @@ -255,6 +269,7 @@ } } } + ctx.strokeStyle = this.strokeColor; ctx.stroke(); ctx.closePath(); } @@ -388,6 +403,9 @@ proximity: 100, // How close two dots need to be before they join parallax: true, parallaxMultiplier: 5, // The lower the number, the more extreme the parallax effect + randomStrokeColor: false, // True to enable random greyscale colors for strokes + strokeColorMin: 0, + strokeColorMax: 15, onInit: function() {}, onDestroy: function() {} }; diff --git a/jquery.particleground.min.js b/jquery.particleground.min.js index dca1f0b..cd7d8b2 100644 --- a/jquery.particleground.min.js +++ b/jquery.particleground.min.js @@ -13,4 +13,4 @@ * @see: http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating * @license: MIT license */ -function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;c