alvaro-prieto
5/25/2018 - 9:19 AM

interpolar colores lerp color interpolacion intermedio transicion JS

function lerpColor(a, b, cantidad) { 
  var ah = parseInt(a.replace(/#/g, ''), 16),
  ar = ah >> 16, ag = ah >> 8 & 0xff, ab = ah & 0xff,
  bh = parseInt(b.replace(/#/g, ''), 16),
  br = bh >> 16, bg = bh >> 8 & 0xff, bb = bh & 0xff,
  rr = ar + cantidad * (br - ar),
  rg = ag + cantidad * (bg - ag),
  rb = ab + cantidad * (bb - ab);

  return '#' + ((1 << 24) + (rr << 16) + (rg << 8) + rb | 0).toString(16).slice(1);
}