Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Line Drawing... Bresenham?
#11
Quote:DX=x2-x1
dy=y2-y1

L!=sqr(DX*dx+dy*dy)

NX!=DX/L!
NY!=dy/L!


For I=0 to L!

X1=x1+NX!
Y1=Y1+NY!
Pset(x1!,Y1!),15
Next I
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#12
Thanks Agamemnus
Reply
#13
:o that's it? It's that simple? you do realize, of course, that I once spent days trying to figure that out, and ended up with a hunk of code, 30 lines.... life before i used the forums...
size=9]"To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public." -- Theodore Roosevelt[/size]
Reply
#14
That is the slow, floating point algorithm. The bresenham approach only uses interger math and several optimizations, thus it is more complicated, but heaps faster.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#15
Yeah, its what you call a vector line. I used that for some of my games.

YOu could also try to use DDA. The one with error Code.
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#16
Well then by all means tell me the faster way to do it!
Reply
#17
Code:
DIM SHARED x2b(8) AS INTEGER, y2b(8) AS INTEGER
x2b(1) = 0: y2b(1) = 1
x2b(2) = 0: y2b(2) = -1
x2b(3) = 1: y2b(3) = 0
x2b(4) = -1: y2b(4) = 0
x2b(5) = -1: y2b(5) = 1
x2b(6) = 1: y2b(6) = 1
x2b(7) = 1: y2b(7) = -1
x2b(8) = -1: y2b(8) = -1

FUNCTION try.straight% (x0 AS INTEGER, y0 AS INTEGER, x1 AS INTEGER, y1 AS INTEGER)
DIM diff AS INTEGER, cost.min AS INTEGER, x0b AS INTEGER, y0b AS INTEGER
DO
cost.min = 32767
FOR i = 1 TO 8
diff = (x1 - x0 - x2b(i)) ^ 2 + (y1 - y0 - y2b(i)) ^ 2
IF diff < cost.min THEN cost.min = diff: x0b = x0 + x2b(i): y0b = y0 + y2b(i)
NEXT i
x0 = x0b: y0 = y0b
IF x0 = x1 THEN IF y0 = y1 THEN try.straight% = 1: EXIT DO
LOOP
END FUNCTION
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#18
Here:

http://relsoft.wrq.cjb.net/files/relgfx.zip

Rel.Line

Just change the PutPixel to Psets...
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)