home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!uwm.edu!linac!uchinews!machine!ddsw1!infopls!rhps!warlok
- From: warlok@rhps.chi.il.us (Jon L Fincher)
- Newsgroups: comp.os.msdos.programmer
- Subject: Re: Line drawing algorithm wanted
- Message-ID: <gmycuB8w165w@rhps.chi.il.us>
- Date: Mon, 16 Nov 92 18:45:27 CST
- References: <17514@mindlink.bc.ca>
- Organization: CrissySoft Incorporated
- Lines: 44
-
- Damon_Harper@mindlink.bc.ca (Damon Harper) writes:
-
- > A request:
- > d
- > Could someone please post or send me a simple line-drawing algorithm, in C or
- > non-language-specific, it doesn't matter, the method is all I want. Thanks.
- >
- > --- ---
- > damon harper Damon_Harper@mindlink.bc.ca
- > --- ---
-
- The following routine is in Pascal (pseudo-code) and follows Bresenham's
- algorithm from the book "Computer Graphics" by Donald Hearn and M. Pauline
- Baker:
-
- procedure bres_line(x1,y1,x2,y2:integer);
- var
- dx,dy,x,y,x_end,p,const1,const2:integer;
- begin
- dx := abs (x1-x2); dy:=abs(y1-y2);
- p := 2*dy-dx;
- const1 := 2* dy; const2 := 2* (dy-dx);
-
- if x1>x2 then begin
- x := x2; y:=y2; x_end:=x1;
- end
- else begin
- x:=x1; y:=y1; x_end:=x2;
- end
- set_pixel(x,y); (* you supply this one, just set a pixel *)
- while x<x_end do begin
- x:=x+1;
- if p<0 then p:=p+const1;
- else begin
- y:=y+1;
- p:=p+const2;
- end;
- set_pixel(x,y);
- end
- end;
-
- Hope it helps. Sorry if some C syntax creeped in...
-
- J.L.Fincher, Warlok
-