code exch ( >a >b --- ) sp )+ a0 long move sp )+ a1 long move a0 ) d0 long move a1 ) d1 long move d0 a1 ) long move d1 a0 ) long move c; variable color variable dx variable dy variable incr1 variable incr2 variable d variable x variable y variable xend variable flag variable x0 variable y0 variable x1 variable y1 variable x2 variable y2 : sline ( x1 y1 x2 y2 --- ) y2 ! x2 ! y1 ! x1 ! flag off x2 @ x1 @ - \ x2-x1 dup x0 ! dup 0<= if negate then dup x2 ! dup dx ! \ dx y2 @ y1 @ - \ dx y2-y1 dup y0 ! dup 0<= if negate then dup y2 ! dup dy ! \ dx dy < if \ x2 y2 exch dx dy exch x1 y1 exch x0 y0 exch flag on then dy @ 2* \ dy<<1 dup dx @ - d ! incr1 ! \ dy @ dx @ - 2* incr2 ! x1 @ y1 @ flag @ if swap then color @ plot x off y off begin x @ x2 @ < while 1 x +! d @ 0< if incr1 else 1 y +! incr2 then @ d +! x1 @ x @ x0 @ 0< if negate then + dx ! y1 @ y @ y0 @ 0< if negate then + dy ! dx @ dy @ flag @ if swap then color @ plot repeat ; code dxdyplot ( --- ) dx l#) d0 long move dy l#) d1 long move flag l#) long tst 0<> if d0 d1 long exg then color l#) d2 long move >fb l#) a1 long move a1 a0 long move gr_x_select gr_update + l# a0 long adda d0 a0 long adda d1 a1 long adda d2 a1 ) byte move \ select y d2 a0 ) byte move \ update x next code inc-dx x1 l#) d0 long move x l#) d1 long move x0 l#) d2 long move 1 d2 long subq 0< if d1 d0 long sub else d1 d0 long add then d0 dx l#) long move c; code inc-dy y1 l#) d0 long move y l#) d1 long move y0 l#) d2 long move 1 d2 long subq 0< if d1 d0 long sub else d1 d0 long add then d0 dy l#) long move c; code inc-d 1 x l#) long addq d l#) long tst 0< if incr1 l#) d0 long move else incr2 l#) d0 long move 1 y l#) long addq then d0 d l#) long add c; create (line-body assembler \ 1 x +! \ d @ 0< if \ incr1 \ else \ 1 y +! \ incr2 \ then \ @ d +! 1 x l#) long addq d l#) long tst 0< if incr1 l#) d0 long move else incr2 l#) d0 long move 1 y l#) long addq then d0 d l#) long add \ x @ \ x0 @ 0<= if negate then \ x1 @ + dx ! x1 l#) d0 long move x l#) d1 long move x0 l#) d2 long move 1 d2 long subq 0< if d1 d0 long sub else d1 d0 long add then d0 dx l#) long move \ y @ \ y0 @ 0<= if negate then \ y1 @ + dy ! y1 l#) d0 long move y l#) d1 long move y0 l#) d2 long move 1 d2 long subq 0< if d1 d0 long sub else d1 d0 long add then d0 dy l#) long move \ dx @ dy @ \ flag @ if swap then \ color @ plot dx l#) d0 long move dy l#) d1 long move flag l#) long tst 0<> if d0 d1 long exg then color l#) d2 long move >fb l#) a1 long move a1 a0 long move gr_x_select gr_update + l# a0 long adda d0 a0 long adda d1 a1 long adda d2 a1 ) byte move \ select y d2 a0 ) byte move \ update x rts forth code cline ( x1 y1 x2 y2 --- ) \ y2 ! x2 ! y1 ! x1 ! sp )+ y2 l#) long move sp )+ x2 l#) long move sp )+ y1 l#) long move sp )+ x1 l#) long move \ flag off flag l#) long clr \ x2 @ x1 @ - \ x2-x1 x2 l#) d0 long move x1 l#) d0 long sub \ dup x0 ! d0 x0 l#) long move \ dup 0< if negate then 0< if d0 long neg then \ dup x2 ! d0 x2 l#) long move \ dup dx ! \ dx d0 dx l#) long move \ y2 @ y1 @ - \ dx y2-y1 y2 l#) d1 long move y1 l#) d1 long sub \ dup y0 ! d1 y0 l#) long move \ dup 0< if negate then 0< if d1 long neg then \ dup y2 ! d1 y2 l#) long move \ dup dy ! \ dx dy d1 dy l#) long move d1 d0 long cmp < if \ dx dy exch d0 dy l#) long move d1 dx l#) long move \ x2 y2 exch x2 l#) d0 long move y2 l#) d1 long move d1 x2 l#) long move d0 y2 l#) long move \ x1 y1 exch x1 l#) d0 long move y1 l#) d1 long move d1 x1 l#) long move d0 y1 l#) long move \ x0 y0 exch x0 l#) d0 long move y0 l#) d1 long move d1 x0 l#) long move d0 y0 l#) long move \ flag on -1 l# flag l#) long move then \ dy @ 2* \ dy<<1 dy l#) d0 long move 1 # d0 long asl \ dup dx @ - d ! \ incr1 ! \ d0 incr1 l#) long move dx l#) d0 long sub d0 d l#) long move \ dy @ dx @ - 2* incr2 ! dy l#) d0 long move dx l#) d0 long sub 1 # d0 long asl d0 incr2 l#) long move \ x1 @ y1 @ \ flag @ if swap then \ color @ plot x1 l#) d0 long move y1 l#) d1 long move flag l#) long tst 0<> if d0 d1 long exg then color l#) d2 long move >fb l#) a1 long move a1 a0 long move gr_x_select gr_update + l# a0 long adda d0 a0 long adda d1 a1 long adda d2 a1 ) byte move \ select y d2 a0 ) byte move \ update x \ x off y off x l#) long clr y l#) long clr begin \ x @ x2 @ < while x l#) d0 long move x2 l#) d0 long cmp < while (line-body bsr repeat c; : fline ( x1 y1 x2 y2 --- ) y2 ! x2 ! y1 ! x1 ! flag off x2 @ x1 @ - \ x2-x1 dup x0 ! dup 0<= if negate then dup x2 ! dup dx ! \ dx y2 @ y1 @ - \ dx y2-y1 dup y0 ! dup 0<= if negate then dup y2 ! dup dy ! \ dx dy < if \ x2 y2 exch dx dy exch x1 y1 exch x0 y0 exch flag on then dy @ 2* \ dy<<1 dup dx @ - d ! incr1 ! \ dy @ dx @ - 2* incr2 ! x1 @ y1 @ flag @ if swap then color @ plot x off y off begin x @ x2 @ < while inc-d \ 1 x +! \ d @ 0< if \ incr1 \ else \ 1 y +! \ incr2 \ then \ @ d +! inc-dx \ x @ \ x0 @ 0<= if negate then \ x1 @ + dx ! inc-dy \ y @ \ y0 @ 0<= if negate then \ y1 @ + dy ! dxdyplot \ dx @ dy @ \ flag @ if swap then \ color @ plot repeat ; \ get_fb .( Done.) cr defer line ' fline is line : foo [ hex ] 100 rnd 100 rnd 100 rnd 100 rnd 100 rnd color ! line ; : bar 0 do foo loop ;