ehime

Untitled

Oct 31st, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /** hex parsers */
  3. (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);
  4.  
  5. var baseColor = $('#chart').attr('data-base-color');
  6. var sigmas    = parseInt($('#chart').attr('data-base-sigmas'), 10);
  7.  
  8. var max = 0;
  9. var min = 255;
  10. for(var i in rgb)
  11. {
  12.     if(rgb[i] >= max)
  13.     {
  14.         max = rgb[i];
  15.     }
  16.  
  17.     if(rgb[i] <= min)
  18.     {
  19.         min = rgb[i];
  20.     }
  21. }
  22.  
  23. var ratio = [
  24.     rgb[0]/max,
  25.     rgb[1]/max,
  26.     rgb[2]/max,
  27. ];
  28.  
  29. var maxColor = [
  30.     Math.floor(255*ratio[0]),
  31.     Math.floor(255*ratio[1]),
  32.     Math.floor(255*ratio[2])
  33. ];
  34.  
  35. var minColor = [
  36.     Math.floor((255-min)*ratio[0]),
  37.     Math.floor((255-min)*ratio[1]),
  38.     Math.floor((255-min)*ratio[2])
  39. ];
  40.  
  41. var minColor = [0,0,0];
  42.  
  43. var maxIncrements = [
  44.     (maxColor[0]-minColor[0])/(sigmas),
  45.     (maxColor[1]-minColor[1])/(sigmas),
  46.     (maxColor[2]-minColor[2])/(sigmas)
  47. ]
  48.  
  49. var minIncrements = [
  50.     (255-maxColor[0])/(sigmas),
  51.     (255-maxColor[1])/(sigmas),
  52.     (255-maxColor[2])/(sigmas)
  53. ]
  54.  
  55. for(var i = 0; i < sigmas; i++)
  56. {
  57.     var newColor = [
  58.         Math.floor(minColor[0]+maxIncrements[0]*i),
  59.         Math.floor(minColor[1]+maxIncrements[1]*i),
  60.         Math.floor(minColor[2]+maxIncrements[2]*i)
  61.     ];
  62.  
  63.     var hex = this.toHex(newColor[0], newColor[1], newColor[2]);
  64.  
  65.     $('#chart .value').each(function (index, value)
  66.     {
  67.         ($.browser.webkit)
  68.             ? $(this).css('background', '-webkit-gradient(linear, left top, left bottom, from('+hex+'), to(#000));').css('border:', '1px solid #ccc')
  69.             : $(this).css('background', '-moz-linear-gradient(top, '+hex+',  #000);').css('border:', '1px solid #ccc');
  70.     });
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment