Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** hex parsers */
- (function(a){a["toRGB"]=function(a){var b=parseInt(a,16);return[b>>16,b>>8&255,b&255]};a["toHex"]=function(a,b,c){return(c|b<<8|a<<16|1<<24).toString(16).slice(1)}})(this);
- var baseColor = $('#chart').attr('data-base-color');
- var sigmas = parseInt($('#chart').attr('data-base-sigmas'), 10);
- var max = 0;
- var min = 255;
- for(var i in rgb)
- {
- if(rgb[i] >= max)
- {
- max = rgb[i];
- }
- if(rgb[i] <= min)
- {
- min = rgb[i];
- }
- }
- var ratio = [
- rgb[0]/max,
- rgb[1]/max,
- rgb[2]/max,
- ];
- var maxColor = [
- Math.floor(255*ratio[0]),
- Math.floor(255*ratio[1]),
- Math.floor(255*ratio[2])
- ];
- var minColor = [
- Math.floor((255-min)*ratio[0]),
- Math.floor((255-min)*ratio[1]),
- Math.floor((255-min)*ratio[2])
- ];
- var minColor = [0,0,0];
- var maxIncrements = [
- (maxColor[0]-minColor[0])/(sigmas),
- (maxColor[1]-minColor[1])/(sigmas),
- (maxColor[2]-minColor[2])/(sigmas)
- ]
- var minIncrements = [
- (255-maxColor[0])/(sigmas),
- (255-maxColor[1])/(sigmas),
- (255-maxColor[2])/(sigmas)
- ]
- for(var i = 0; i < sigmas; i++)
- {
- var newColor = [
- Math.floor(minColor[0]+maxIncrements[0]*i),
- Math.floor(minColor[1]+maxIncrements[1]*i),
- Math.floor(minColor[2]+maxIncrements[2]*i)
- ];
- var hex = this.toHex(newColor[0], newColor[1], newColor[2]);
- $('#chart .value').each(function (index, value)
- {
- ($.browser.webkit)
- ? $(this).css('background', '-webkit-gradient(linear, left top, left bottom, from('+hex+'), to(#000));').css('border:', '1px solid #ccc')
- : $(this).css('background', '-moz-linear-gradient(top, '+hex+', #000);').css('border:', '1px solid #ccc');
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment