Posts: 3,368
Threads: 195
Joined: Jan 2003
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.
Posts: 9
Threads: 2
Joined: Mar 2003
Posts: 729
Threads: 105
Joined: Feb 2003
: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]
Posts: 6,419
Threads: 74
Joined: Mar 2002
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.
Posts: 3,288
Threads: 167
Joined: Nov 2001
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.
Posts: 9
Threads: 2
Joined: Mar 2003
Well then by all means tell me the faster way to do it!
Posts: 3,368
Threads: 195
Joined: Jan 2003
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.
Posts: 3,288
Threads: 167
Joined: Nov 2001
Here:
http://relsoft.wrq.cjb.net/files/relgfx.zip
Rel.Line
Just change the PutPixel to Psets...