Skip to content

Instantly share code, notes, and snippets.

@reportbase
Created October 17, 2018 05:20
Show Gist options
  • Save reportbase/6f9d60b8f6d022d3106826a11ec453e5 to your computer and use it in GitHub Desktop.
Save reportbase/6f9d60b8f6d022d3106826a11ec453e5 to your computer and use it in GitHub Desktop.
normalscale scale interpolate
Math.normalscale = function(minv, maxv, lst)
{
for (var n = 0; n < lst.length; ++n)
{
var k = (Math.abs(maxv - minv) > 0.001) ? ((lst[n] - minv) / (maxv - minv)) : 0;
lst[n] = 1-k;
}
};
Math.scale = function(width, height, maxdim)
{
var scale = Math.min(maxdim / width, maxdim / height);
return [scale * width, scale * height];
};
//alpha == 255, then all weight is val1, if alpha is 0, then all weight is val2
Math.interpolate = function(alpha, val1, val2)
{
return ((val1 + 1) * alpha >> 8) - ((val2 + 1) * alpha >> 8) + val2;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment