javascriptcolorshex

Average 2 hex colors together in javascript


Alright thought I would throw this one out there for the crowd to think over.

Given a function (written in javascript) that expects two strings formated like a hex color (ex #FF0000)

return a hex color that is the average of both of the colors passed.

function averageColors(firstColor,secondColor)
{
  ...
  return avgColor;
}

--edit--

average would be defined as enter image description here

if the color passed was yellow and the second was light purple the returned color would be a medium orange


Solution

  • I hate sounding like the oh-so-broken jQuery record, but there is a jQuery plugin for this already.

    $.xcolor.average(color, color)