Created
October 17, 2018 05:20
-
-
Save reportbase/6f9d60b8f6d022d3106826a11ec453e5 to your computer and use it in GitHub Desktop.
normalscale scale interpolate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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