ckrbd.js
//The returned line begins with a and ends with b.
The returned line begins with a and ends with b.
The returned line begins with a and ends with b .
function stLine(a, b){
    function dither(p,index) { return Math.floor((index+1)*p) == Math.floor(index*p)?0:1; }
    var di = a.i < b.i? 1:-1;
    var dj = a.j < b.j? 1:-1;
    var p = (a.j == b.j)?1:Math.abs(a.i - b.i)/(Math.abs(a.i - b.i) + Math.abs(a.j - b.j));
    var index = 0;
    var i=a.i, j=a.j;
    var r = [];
    for (let index=0;index<10000;index++) { 
        r.push({i:i, j:j}); 
        if (i==b.i && j==b.j) break; 
        if (dither(p,index)) i+=di; else j+=dj;
    }
    return r;
}
function stLine ( a , b ) { function dither ( p , index ) { return Math . floor ( ( index + 1 ) * p ) == Math . floor ( index * p ) ? 0 : 1 ; } var di = a . i < b . i ? 1 : - 1 ; var dj = a . j < b . j ? 1 : - 1 ; var p = ( a . j == b . j ) ? 1 : Math . abs ( a . i - b . i ) / ( Math . abs ( a . i - b . i ) + Math . abs ( a . j - b . j ) ) ; var index = 0 ; var i = a . i , j = a . j ; var r = [ ] ; for ( let index = 0 ; index < 10000 ; index ++ ) { r . push ( { i : i , j : j } ) ; if ( i == b . i && j == b . j ) break ; if ( dither ( p , index ) ) i += di ; else j += dj ; } return r ; }
The returned line begins with a and ends with b.
The returned line begins with a and ends with b .
//for (var index=0; true; index++) print( dither(p,index) ); //produces a sequence of 0's and 1's, where the probability of 1's is p, and the 1's are  //uniformly dithered, that is, they are spread out as uniformly as possible. //limit prevents inf loop if I've miscalculated //first time pushes a. //last time pushed b