September 2008 Archives

Map function in JavaScript

| | Comments (0) | TrackBacks (0)

While building out my new lifestream, I ran into a wall, and needed a function to map a variable from one coordinate space (specifically arrays). I remembered that Proce55ing had just such a function. OpenSource Software FTW!

function map(value, istart, istop, ostart, ostop) {
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));

}