Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alternate way to draw a line (PSET line)
#4
Well I used the Bresenham Algorythm and modified it to this:

Code:
SUB BLine (x%, y%, x2%, y2%, c%)
   i% = 0: steep% = 0: e% = 0
   IF (x2% - x%) > 0 THEN sx% = 1:  ELSE sx% = -1
   dx% = ABS(x2% - x%)
   IF (y2% - y%) > 0 THEN sy% = 1:  ELSE sy% = -1
   dy% = ABS(y2% - y%)
   IF (dy% > dx%) THEN
      steep% = 1
      SWAP x%, y%
      SWAP dx%, dy%
      SWAP sx%, sy%
   END IF
   e% = 2 * dy% - dx%
   FOR i% = 0 TO dx% - 1
      IF steep% = 1 THEN PSET (y%+39, x%+1), c%:  ELSE PSET (x%+39, y%+1), c%
      
      IF steep% = 1 THEN PSET (y%*2, x%*2), c%:  ELSE PSET (x%*2, y%*2), c%
      IF steep% = 1 THEN PSET (y%*2+1, x%*2), c%:  ELSE PSET (x%*2+1, y%*2), c%
      IF steep% = 1 THEN PSET (y%*2, x%*2+1), c%:  ELSE PSET (x%*2, y%*2+1), c%
      IF steep% = 1 THEN PSET (y%*2+1, x%*2+1), c%:  ELSE PSET (x%*2+1, y%*2+1), c%
      WHILE e% >= 0
         y% = y% + sy%: e% = e% - 2 * dx%
      WEND
      x% = x% + sx%: e% = e% + 2 * dy%
   NEXT
   PSET (x2%+39, y2%+1), c%
  
   PSET (x2%*2, y2%*2), c%
   PSET (x2%*2+1, y2%*2), c%
   PSET (x2%*2, y2%*2+1), c%
   PSET (x2%*2+1, y2%*2+1), c%
END SUB

Now it works perfectly and I am glad to say that, my program is pretty much completed and maybe now I'll just add a few more commands like drawing a box filled or unfilled.
Reply


Messages In This Thread
Alternate way to draw a line (PSET line) - by KiZ - 12-19-2005, 07:06 AM
Alternate way to draw a line (PSET line) - by axipher - 12-19-2005, 07:26 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)