Created
March 29, 2012 11:56
-
-
Save antimatter15/2236530 to your computer and use it in GitHub Desktop.
Smoothing any amount of input arbitrarily
This file contains 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
function Interpolator(degree){ | |
var inter = []; | |
function interpolate(a,b) { | |
return a + (b-a) * 0.04; | |
} | |
var fn = { | |
set: function(n){ | |
inter[0] = n; | |
}, | |
diff: function(){ | |
return Math.abs(inter[0] - inter[degree]) | |
}, | |
inter: function(){ | |
return inter | |
}, | |
reset: function(){ | |
for(var i = 0; i < degree + 1; i++){ | |
inter[i] = 0; | |
} | |
}, | |
get: function(){ | |
for(var i = 0; i < degree; i++){ | |
inter[i+1] = interpolate(inter[i+1], inter[i]) | |
} | |
return inter[degree] | |
} | |
}; | |
fn.reset(); | |
return fn; | |
} | |
var polar_p1 = new Interpolator(2); | |
var polar_p2 = new Interpolator(2) | |
function updatePolar(p1, p2){ | |
if(polar_p1.diff() < 1e-5 && polar_p2.diff() < 1e-5){ | |
requestAnimFrame(renderPolar); | |
} | |
polar_p1.set(p1); | |
polar_p2.set(p2); | |
} | |
function renderPolar(){ | |
var p1 = polar_p1.get(); | |
var p2 = polar_p2.get(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment