home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / LINEPAT.ZIP / LINEPAT.INC
Encoding:
Text File  |  1986-01-11  |  2.5 KB  |  88 lines

  1. { This procedure will draw dashed or dotted (or alternating dot-dash) lines
  2. in Turbo Pascal.  The first five parameters are the same as for the TP
  3. built-in DRAW procedure.  The last parameter (Pattern) determines a 16-bit
  4. sequence of pixels illuminated or bypassed.  Some examples:
  5.  
  6.    $8888 will light every 4th dot along the line (so will $4444, $2222, $1111)
  7.    $F0F0 will light 4 dots, skip 4, etc.
  8.    $FF00 will light 8 dots, skip 8, etc.
  9.    $8421 will light every 5th dot, but when the sequence repeats you'll get
  10.          two dots togther turned on.
  11.    $FFFF will give you a solid line, like DRAW, but about 15% slower
  12.  
  13. This procedure is a modification of a printer graphics procedure shown in
  14. the Nov. 1985 issue of BYTE magazine.  }
  15.  
  16. Procedure Linepat(x1,y1,x2,y2,PixColor,Pattern:INTEGER);
  17. Var
  18.    x,y,z,a,b            :INTEGER;
  19.    p                    :INTEGER;
  20.    deltap,deltaq        :INTEGER;
  21.    d,dx,dy              :INTEGER;
  22. Begin
  23.    dx:=abs(x2 - x1);
  24.    dy:=abs(y2 - y1);
  25.    if dy <= dx then
  26.    begin               {slope <= 1}
  27.       x:= x1; y:= y1;
  28.       z:= x2;
  29.       if x1 <= x2 then a:= 1
  30.                   else a:= -1;
  31.       if y1 <= y2 then b:= 1
  32.                   else b:= -1;
  33.       deltap:= dy + dy;
  34.       d := deltap - dx;
  35.       deltaq := d - dx;
  36.       PLOT(x,y,PixColor);
  37.       while x <> z do
  38.       begin
  39.          x:= x + a;
  40.          if d < 0 then
  41.             d:= d + deltap
  42.          else
  43.          begin
  44.             y:= y + b;
  45.             d:= d + deltaq;
  46.          end;
  47.          p:= 1 and pattern;
  48.          pattern:= pattern shr 1;
  49.          if p = 1 then
  50.          begin
  51.             pattern := pattern or $8000;
  52.             PLOT(x,y,PixColor);
  53.          end;
  54.       end;
  55.    end
  56.    else
  57.    begin
  58.       y:= y1; x:= x1;
  59.       z:= y2;
  60.       if y1 <= y2 then a:= 1
  61.                   else a:= -1;
  62.       if x1 <= x2 then b:= 1
  63.                   else b:= -1;
  64.       deltap:= dx + dx;
  65.       d:= deltap - dy;
  66.       deltaq:= d - dy;
  67.       PLOT(x,y,PixColor);
  68.       while y <> z do
  69.       begin
  70.          y:= y + a;
  71.          if d < 0 then
  72.             d:= d + deltap
  73.          else
  74.          begin
  75.             x:= x + b;
  76.             d:= d + deltaq;
  77.          end;
  78.          p:= 1 and pattern;
  79.          pattern:= pattern shr 1;
  80.          if p = 1 then
  81.          begin
  82.             pattern := pattern or $8000;
  83.             PLOT(x,y,PixColor);
  84.          end;
  85.       end;
  86.    end;
  87. end;
  88.