\ Line drawing \ \ \ Exported words: \ \ move-to ( x y -- ) \ line-to ( x y -- ) \ \ \ Exported values: \ \ bold: true, if the line should be drawn bold \ x0, y0: current position \ \ \ Imported word: \ \ plot ( x y -- ): plot a point at the specified position \ bold flag for line-to 0 value bold \ current coordinates for move-to and line-to 0 value x0 0 value y0 0 value x1 0 value y1 \ locals for line word 0 value delta-x 0 value delta-y 0 value y-step 0 value line-error 0 value steep \ draws a line from x0/y0 to x1/y1 : line ( -- ) y1 y0 - abs x1 x0 - abs > dup to steep if x0 y0 to x0 to y0 x1 y1 to x1 to y1 then x0 x1 > if x1 x0 to x1 to x0 y1 y0 to y1 to y0 then x1 x0 - to delta-x y1 y0 - abs to delta-y y0 y1 < if 1 else -1 then to y-step delta-x 2/ to line-error x1 1+ x0 do i y0 steep if swap then bold if 2dup plot 2dup 1+ plot 2dup swap 1+ swap plot 1+ swap 1+ swap plot else plot then line-error delta-y + dup to line-error delta-x < invert if y0 y-step + to y0 line-error delta-x - to line-error then loop ; \ move current position to the specified position : move-to ( x y -- ) to y0 to x0 ; \ draw a line from the current position to the specified position \ and set the current position to the end point : line-to ( x y -- ) 2dup to y1 to x1 line to y0 to x0 ;