FANDOM


Snippets for working with colors

A simple RGB object

function RGB(r,g,b){
  this.r = r;
  this.g = g;
  this.b = b;
  this.ease = function(newRGB,pct){
    var newR = this.r + Math.round((newRGB.r - this.r)*pct);
    var newG = this.g + Math.round((newRGB.g - this.g)*pct);
    var newB = this.b + Math.round((newRGB.b - this.b)*pct);
    return new RGB(newR,newG,newB);
  }
  this.hex = function(){
    var rhex, ghex, bhex;
    
    if ((rhex=this.r.toString(16)).length < 2) {rhex = "0"+rhex;}
    if ((ghex=this.g.toString(16)).length < 2) {ghex = "0"+ghex;}
    if ((bhex=this.b.toString(16)).length < 2) {bhex = "0"+bhex;}
    
    return "#"+rhex+ghex+bhex;
  }
}

Example

  var pct = i / (rowsInList - 1);
  var fin = new RGB(128,128,128);
  var ini = new RGB(221,221,221);
  list[i].bgColor = ini.ease(fin,pct).hex();

See Also: http://www2.konfabulator.com/forums/index.php?showtopic=11014

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.