- 
      
 - 
        
Save p01/1005192 to your computer and use it in GitHub Desktop.  
    Make RGB Colors Lighter / Darker
  
        
  
    
      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 characters
    
  
  
    
  | /* | |
| * Make RGB-Colors lighter / darker | |
| */ | |
| var color = function(c,n,i,d){for(i=3;i--;c[i]=d<0?0:d>255?255:d|0)d=c[i]+n;return c} | |
| /** | |
| * @param array RGB Colors | |
| * @param number Amount | |
| */ | |
| color( [225, 100, 10 ], -90 ); // returns [135,10,0] | |
| color( [225, 100, 10 ], 70 ); // returns [255,170,80] | 
  
    
      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 characters
    
  
  
    
  | function(c,n,i,d){for(i=3;i--;c[i]=d<0?0:d>255?255:d|0)d=c[i]+n;return c} | 
  
    
      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 characters
    
  
  
    
  | { | |
| "name": "darker color", | |
| "keywords": [ "color", "darker", "lighter" ] | |
| } | 
Wolf140b? You sir have no idea what you just unleashed.
Save 1 byte? I'm not sure if this works in all web browsers but I think so.
function(c,n,i,d){for(i in c)d=c[i]+n,c[i]=d<0?0:d>255?255:d|0;return c}ES5 version, saves 1 byte:
function(c,n){return c.map(function(d){return(d+=n)<0?0:d>255?255:d|0})}ES6 version, saves 32 byte:
(c,n)=>c.map(d=>(d+=n)<0?0:d>255?255:d|0)
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Nice one! We're all still waiting for a wolf140b...