turtle.txt


\ turtle 97.8.15 8:26 pm NAB

include trig
include graphics
variable x  variable y  variable angle
variable ink
: black   1 ink ! ;   : white   0 ink ! ;
: goto ( y x )  80 + x !  80 + y ! ;
: drawto ( toY toX --)
   ink @ if  2dup  y @ x @ line  then
   x !  y ! ;
: turtle  page  0 angle !  0 dup goto
   black ;
: sindist ( angle distance -- yOffset)
   swap  sin 10000 */ ;
: cosdist ( angle distance -- xOffset)
   swap  cos 10000 */ ;
: turn ( angle --)  angle +! ;
: fwd ( distance  --)
   angle @  swap 2dup
   cosdist x @ +  >r
   sindist negate  y @ +
   r>   drawto ;



  HTMLized by Forth2HTML