Hi,

Is there a good standard implementation of Bresenham's linedraw? My silly
attempt, which is basically just a translation of a Processing program, is
below. I know it can be done better than this, I'm just not sure how - and
this program fails to compile with a rather bizarre error related to the
first unless statement which apparently takes something like 5 inputs!?

Mark


! Create a new 10x10 grid
: newgrid ( n n -- byte-array ) * <byte-array> ;

! Get address of cell x,y
: celladdress ( n n -- n ) 10 * + ;

! Get value of cell at x,y
: cellat ( byte-array n n -- n ) celladdress swap nth ;

! Do operation on cell at x,y
:: docell ( array x y op -- ) x y celladdress array op change-nth ;

! Set value of cell at x,y
:: setcell ( array x y val -- )  array x y [ drop val ] docell ;

:: los ( map ax ay bx by -- bool )
     bx ax - abs :> dx!
     by ay - abs :> dy!
     dx! dy! - :> err!
     t :> continue!
     t :> result!
     ax ay
     [ continue! ] [
        2dup cellat 0 = [ f :> continue! f :> result! ] unless
        2dup by = swap bx = and [ f :> continue! t :> result! ] when
        err 2 *
        dup 0 dy! - > [ err! dy! - :> err! roll dx! sgn + -roll ] when
        dx! < [ err! dx! + :> err! dy! sgn + ] when
     ] while
     result! ;
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to