Last active
December 15, 2015 14:49
-
-
Save jonathanmarvens/5276974 to your computer and use it in GitHub Desktop.
Revisions
-
jonathanmarvens revised this gist
Mar 30, 2013 . 4 changed files with 19 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,14 +23,22 @@ function colorShader( color_hex, amount ) { 'b': ( ( ( color_number >> 8 ) & 0xFF ) + amount ) }; if ( color_rgb.r > 0xFF ) { color_rgb.r = 0xFF; } else if ( color_rgb.r < 0x00 ) { color_rgb.r = 0x00; } if ( color_rgb.g > 0xFF ) { color_rgb.g = 0xFF; } else if ( color_rgb.g < 0x00 ) { color_rgb.g = 0x00; } if ( color_rgb.b > 0xFF ) { color_rgb.b = 0xFF; } else if ( color_rgb.b < 0x00 ) { color_rgb.b = 0x00; } var color_new = ( This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ function colorShader(a,b){"use strict";if(!isHexColorString(a))return null;var c=parseInt(a,16),d={r:(c>>16)+b,g:(255&c)+b,b:(255&c>>8)+b};d.r>255?d.r=255:0>d.r&&(d.r=0),d.g>255?d.g=255:0>d.g&&(d.g=0),d.b>255?d.b=255:0>d.b&&(d.b=0);var e=(d.r<<16|d.g|d.b<<8).toString(16);return 6===e.length?e:Array(6-e.length+1).join("0")+e} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,9 +11,8 @@ function isHexColorString( hex_string ) { } hex_string = hex_string.trim(); if ( ! ( /^[0-9a-f]{6}$/i ).test( hex_string ) ) { return false; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ function isHexColorString(a){"use strict";return"[object String]"!=={}.toString.call(a)?!1:(a=a.trim(),/^[0-9a-f]{6}$/i.test(a)?!0:!1)} -
jonathanmarvens revised this gist
Mar 30, 2013 . 2 changed files with 9 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,22 +23,14 @@ function colorShader( color_hex, amount ) { 'b': ( ( ( color_number >> 8 ) & 0xFF ) + amount ) }; for ( var key in color_rgb ) { if ( {}.hasOwnProperty.call( color_rgb, key ) ) { if ( color_rgb[ key ] > 0xFF ) { color_rgb[ key ] = 0xFF; } else if ( color_rgb[ key ] < 0x00 ) { color_rgb[ key ] = 0x00; } } } var color_new = ( This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ function colorShader(a,b){"use strict";if(!isHexColorString(a))return null;var c=parseInt(a,16),d={r:(c>>16)+b,g:(255&c)+b,b:(255&c>>8)+b};for(var e in d)({}).hasOwnProperty.call(d,e)&&(d[e]>255?d[e]=255:0>d[e]&&(d[e]=0));var f=(d.r<<16|d.g|d.b<<8).toString(16);return 6===f.length?f:Array(6-f.length+1).join("0")+f} -
jonathanmarvens created this gist
Mar 30, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ /** * @author Jonathan Barronville * @example * var color_001 = colorShader( '000000', 255 ); * // color_001 === 'ffffff'; * var color_002 = colorShader( 'ffffff', -255 ); * // color_002 === '000000'; * @param {String} color_hex * @param {Number} amount * @return {String} */ function colorShader( color_hex, amount ) { 'use strict'; if ( ! isHexColorString( color_hex ) ) { return null; } var color_number = parseInt( color_hex, 16 ); var color_rgb = { 'r': ( ( color_number >> 16 ) + amount ), 'g': ( ( color_number & 0xFF ) + amount ), 'b': ( ( ( color_number >> 8 ) & 0xFF ) + amount ) }; if ( color_rgb.r > 0xFF ) { color_rgb.r = 0xFF; } else if ( color_rgb.r < 0x00 ) { color_rgb.r = 0x00; } if ( color_rgb.g > 0xFF ) { color_rgb.g = 0xFF; } else if ( color_rgb.g < 0x00 ) { color_rgb.g = 0x00; } if ( color_rgb.b > 0xFF ) { color_rgb.b = 0xFF; } else if ( color_rgb.b < 0x00 ) { color_rgb.b = 0x00; } var color_new = ( ( color_rgb.r << 16 ) | color_rgb.g | ( color_rgb.b << 8 ) ).toString( 16 ); if ( color_new.length === 6 ) { return color_new; } else { return ( ( new Array( ( 6 - color_new.length ) + 1 ) ).join( '0' ) + color_new ); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ function colorShader(a,b){"use strict";if(!isHexColorString(a))return null;var c=parseInt(a,16),d={r:(c>>16)+b,g:(255&c)+b,b:(255&c>>8)+b};d.r>255?d.r=255:0>d.r&&(d.r=0),d.g>255?d.g=255:0>d.g&&(d.g=0),d.b>255?d.b=255:0>d.b&&(d.b=0);var e=(d.r<<16|d.g|d.b<<8).toString(16);return 6===e.length?e:Array(6-e.length+1).join("0")+e} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ /** * @author Jonathan Barronville * @param {String} hex_string * @return {Boolean} */ function isHexColorString( hex_string ) { 'use strict'; if ( {}.toString.call( hex_string ) !== '[object String]' ) { return false; } hex_string = hex_string.trim(); hex_string = hex_string.toLowerCase(); if ( ! /^[0-9a-f]{6}$/.test( hex_string ) ) { return false; } return true; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ function isHexColorString(a){"use strict";return"[object String]"!=={}.toString.call(a)?!1:(a=a.trim(),a=a.toLowerCase(),/^[0-9a-f]{6}$/.test(a)?!0:!1)}