MCPcopy Create free account
hub / github.com/microsoft/SandDance / rectangularSpiral

Function rectangularSpiral

docs/app/js/sanddance-app.js:140978–141001  ·  view source on GitHub ↗
(size)

Source from the content-addressed store, hash-verified

140976 };
140977}
140978function rectangularSpiral(size) {
140979 var dy = 4, dx = dy * size[0] / size[1], x = 0, y = 0;
140980 return function(t) {
140981 var sign = t < 0 ? -1 : 1; // See triangular numbers: T_n = n * (n + 1) / 2.
140982 switch(Math.sqrt(1 + 4 * sign * t) - sign & 3){
140983 case 0:
140984 x += dx;
140985 break;
140986 case 1:
140987 y += dy;
140988 break;
140989 case 2:
140990 x -= dx;
140991 break;
140992 default:
140993 y -= dy;
140994 break;
140995 }
140996 return [
140997 x,
140998 y
140999 ];
141000 };
141001} // TODO reuse arrays?
141002function zeroArray(n) {
141003 var a = [], i = -1;
141004 while(++i < n)a[i] = 0;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected