home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / alt / sys / amiga / demos / 1144 < prev    next >
Encoding:
Internet Message Format  |  1992-09-14  |  1.6 KB

  1. Path: sparky!uunet!mcsun!corton!loria!loria.crin.fr!eker
  2. From: eker@loria.crin.fr (Steven Eker)
  3. Newsgroups: alt.sys.amiga.demos
  4. Subject: Re: Drawing lines
  5. Message-ID: <475@muller.loria.fr>
  6. Date: 14 Sep 92 08:37:01 GMT
  7. References: <umage.715709408@mcl>
  8. Sender: mirtain@news.loria.fr
  9. Organization: CRIN (CNRS) Nancy - INRIA Lorraine
  10. Lines: 27
  11.  
  12. In article <umage.715709408@mcl>, umage@mcl.ucsb.edu (androgyny) writes:
  13. |> Yea me, the novitiate programmer again.
  14. |> OK, i know the blitter will draw lines, but i wanted to try my hand at
  15. |> writing a straight lin edrawer myself.  And now i want to compare with
  16. |> folks here.  Keep in mind i've never had any teaching or theory in this,
  17. |> and i've got a routine which requires 2 divides at the beginning of each
  18. |> line, and from then on is simple adds and checks. (about 2 to 5 per pixel,
  19. |> excluding actually drawing the pixel in ram)  How does this measure up?
  20.  
  21. Very badly... The algorithm you want is called "Bresenham's Algorithm"
  22. which requires 2 adds & 1 subtract at the beginning of each line
  23. and two adds & a test per pixel. You can actually unwind BA into spagetti
  24. code to avoid the loop (with its test) bringing the cost down to just
  25. 3 68k instructions (16cy) /pixel (not including screen accesses).
  26.  
  27. This might still be to slow for some purposes in which case you want a
  28. more complicated beast called "Bresenham's scanline algorithm" which
  29. lets you draw whole runs of pixels with the same y coordinate in a single
  30. instruction.
  31.  
  32. Both these algorithms generate the "optimal" line - no cumulative rounding errors.
  33.  
  34. |> Should i think some more ? ( Of course i should! )
  35.  
  36. Definitely.
  37.  
  38. Steven
  39.