*process source xref or(!); brbn:Proc Options(main); /********************************************************************* * 21.05.2014 Walter Pachl * Implementing the pseudo code of * http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm * under 'Simplification' (see also REXX version 2) *********************************************************************/ grid.= dcl image(-2:7,-4:11) char(1); image='.'; image(*,0)='-'; image(0,*)='|'; image(0,0)='+'; call draw_line(-1,-3,6,10); Dcl (i,j) Bin Fixed(31); Do j=11 To -4 By -1; Put Edit(j,' ')(Skip,f(2),a); Do i=-2 To 7; Put Edit(image(i,j))(a); End; End; Put Edit(' 2101234567')(Skip,a); draw_line: procedure (x0,y0,x1,y1); dcl (x0,y0,x1,y1) fixed binary(31); dcl (dx,dy,sx,sy,err,e2) fixed binary(31); dx = abs(x1-x0); dy = abs(y1-y0); if x0 < x1 then sx = 1; else sx = -1; if y0 < y1 then sy = 1; else sy = -1; err = dx-dy; Do Until(x0=x1&y0=y1); image(x0,y0)='X'; e2=err*2; if e2>-dy then do; err=err-dy; x0=x0+sx; End; if e2