home *** CD-ROM | disk | FTP | other *** search
- { This procedure will draw dashed or dotted (or alternating dot-dash) lines
- in Turbo Pascal. The first five parameters are the same as for the TP
- built-in DRAW procedure. The last parameter (Pattern) determines a 16-bit
- sequence of pixels illuminated or bypassed. Some examples:
-
- $8888 will light every 4th dot along the line (so will $4444, $2222, $1111)
- $F0F0 will light 4 dots, skip 4, etc.
- $FF00 will light 8 dots, skip 8, etc.
- $8421 will light every 5th dot, but when the sequence repeats you'll get
- two dots togther turned on.
- $FFFF will give you a solid line, like DRAW, but about 15% slower
-
- This procedure is a modification of a printer graphics procedure shown in
- the Nov. 1985 issue of BYTE magazine. }
-
- Procedure Linepat(x1,y1,x2,y2,PixColor,Pattern:INTEGER);
- Var
- x,y,z,a,b :INTEGER;
- p :INTEGER;
- deltap,deltaq :INTEGER;
- d,dx,dy :INTEGER;
- Begin
- dx:=abs(x2 - x1);
- dy:=abs(y2 - y1);
- if dy <= dx then
- begin {slope <= 1}
- x:= x1; y:= y1;
- z:= x2;
- if x1 <= x2 then a:= 1
- else a:= -1;
- if y1 <= y2 then b:= 1
- else b:= -1;
- deltap:= dy + dy;
- d := deltap - dx;
- deltaq := d - dx;
- PLOT(x,y,PixColor);
- while x <> z do
- begin
- x:= x + a;
- if d < 0 then
- d:= d + deltap
- else
- begin
- y:= y + b;
- d:= d + deltaq;
- end;
- p:= 1 and pattern;
- pattern:= pattern shr 1;
- if p = 1 then
- begin
- pattern := pattern or $8000;
- PLOT(x,y,PixColor);
- end;
- end;
- end
- else
- begin
- y:= y1; x:= x1;
- z:= y2;
- if y1 <= y2 then a:= 1
- else a:= -1;
- if x1 <= x2 then b:= 1
- else b:= -1;
- deltap:= dx + dx;
- d:= deltap - dy;
- deltaq:= d - dy;
- PLOT(x,y,PixColor);
- while y <> z do
- begin
- y:= y + a;
- if d < 0 then
- d:= d + deltap
- else
- begin
- x:= x + b;
- d:= d + deltaq;
- end;
- p:= 1 and pattern;
- pattern:= pattern shr 1;
- if p = 1 then
- begin
- pattern := pattern or $8000;
- PLOT(x,y,PixColor);
- end;
- end;
- end;
- end;
-