Task

Using the data storage type defined on the Bitmap page for raster graphics images,

draw a line given two points with Bresenham's line algorithm.




 
PROGRAM BRESENHAM
 
!$INCLUDE="PC.LIB"
 
PROCEDURE BRESENHAM
! === Draw a line using graphic coordinates
! Inputs are X1, Y1, X2, Y2: Destroys value of X1, Y1
dx=ABS(x2-x1) sx=-1
IF x1<x2 THEN sx=1
dy=ABS(y2-y1) sy=-1
IF y1<y2 THEN sy=1
er=-dy
IF dx>dy THEN er=dx
er=INT(er/2)
LOOP
   PSET(x1,y1,1)
   EXIT IF x1=x2 AND y1=y2
   e2=er
   IF e2>-dx THEN er=er-dy x1=x1+sx
   IF e2<dy THEN er=er+dx y1=y1+sy
END LOOP
END PROCEDURE
 
BEGIN
  SCREEN(2)
  INPUT(x1,y1,x2,y2)
  BRESENHAM
  GET(A$)
  SCREEN(0)
END PROGRAM
 