Skip to content

Commit

Permalink
Added ability to set a hex string as a base color
Browse files Browse the repository at this point in the history
  • Loading branch information
Fooidge committed Sep 16, 2014
1 parent f86f673 commit fd00a18
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pleasejs",
"version": "0.2.6",
"version": "0.3.0",
"homepage": "https://github.com/Fooidge/PleaseJS",
"authors": [
"Fooidge"
Expand Down
4 changes: 2 additions & 2 deletions dist/Please.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pleasejs",
"version": "0.2.6",
"version": "0.3.0",
"description": "JS library to generate random pleasing colors/color schemes",
"main": "Please.js",
"scripts": {
Expand Down
12 changes: 9 additions & 3 deletions src/Please.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!Please JS v0.2.6, Jordan Checkman 2014, Checkman.io, MIT License, Have fun.*/
/*!Please JS v0.3.0, Jordan Checkman 2014, Checkman.io, MIT License, Have fun.*/
(function( globalName, root, factory ) {
if ( typeof define === 'function' && define.amd ) {
define( [], factory );
Expand Down Expand Up @@ -273,7 +273,7 @@
//accepts hex string, produces RGB object
Please.HEX_to_RGB = function( hex ){
var regex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace( regex, function( r, g, b ) {
hex = hex.replace( regex, function( m, r, g, b ) {
return r + r + g + g + b + b;
});
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec( hex );
Expand Down Expand Up @@ -521,7 +521,13 @@
}
//first, check for a base color
if ( color_options.base_color.length > 0 ) {
base_color = Please.NAME_to_HSV( color_options.base_color );
//then determine if its a hex string or a named color
if( color_options.base_color.match( /^#?([0-9a-f]{3})([0-9a-f]{3})?$/i ) ){
base_color = Please.HEX_to_HSV( color_options.base_color );
}
else{
base_color = Please.NAME_to_HSV( color_options.base_color );
}
}
for ( var i = 0; i < color_options.colors_returned; i++ ) {
var random_hue = random_int( 0, 360 );
Expand Down

0 comments on commit fd00a18

Please sign in to comment.