Drawing using Catmull and Rom cubic spline

This came up on other forum. I was just dorking around [url=http://www.mvps.org/directx/articles/catmull/]this article.

var px = [], py = [];
function spline (t, p) {
 // this maps t = 0..1 to P1..P2
 var P0 = p[p.length -4], P1 = p[p.length -3], P2 = p[p.length -2], P3 = p[p.length -1];
 return 0.5 * ((2 * P1) + (-P0 + P2) * t + (2*P0 - 5*P1 + 4*P2 - P3) * t * t + (-P0 + 3*P1 - 3*P2 + P3) * t * t * t);
}
function onMouseUp () {
 do { px.push (_xmouse); py.push (_ymouse); } while (px.length < 4);
 var x0 = px[px.length -2], y0 = py[py.length -2], x1 = px[px.length -1], y1 = py[py.length -1];
 // polyline
 _root.lineStyle(1, 0xFF0000, 100); _root.moveTo(x0, y0); _root.lineTo(x1, y1);
 // employ spline
 x0 = px[px.length -3]; y0 = py[py.length -3]; x1 = spline (1, px); y1 = spline (1, py);
 var n = Math.round(2 + Math.sqrt((x0 - x1)*(x0 - x1) + (y0 - y1)*(y0 - y1)) / 5);
 _root.lineStyle(1, 0x0000FF, 100); _root.moveTo(x0, y0);
 for (var i=1; i<=n; i++) {
  x1 = spline (i/n, px); y1 = spline (i/n, py); _root.lineTo(x1, y1);
 }
}

:block: