Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add random greyscale color feature #26

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions jquery.particleground.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -255,6 +269,7 @@
}
}
}
ctx.strokeStyle = this.strokeColor;
ctx.stroke();
ctx.closePath();
}
Expand Down Expand Up @@ -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() {}
};
Expand Down
2 changes: 1 addition & 1 deletion jquery.particleground.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.