Qbasicnews.com

Full Version: LINE
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
does any one know how to draw a line into an array?

Instead of drawing it onto the screen i.e. LINE (0, 0) - (5, 5), 4

I want to define a line in an array.
I assume it's some kind of algorithm.
if anyone can help, I'd appreciate it

Jony_Basic
I don't think that's possible. The easiest way to store a line into an array would probably be to store the x,y coordinates and the color in an array and call it from there, but I'm not sure.

Just trying to help with ideas.
im sure searching this forum will turn up a few line algorithms, the only one i can remember is bresenham/bresnham

i posted it here
http://forum.qbasicnews.com/viewtopic.ph...t=bresnham
If you're in a hurry, you could just use LINE itself. As of FB .15, there is an extra parameter before line, like so:

Code:
LINE buffer, (...)-(...)

Not sure if it was in any other releases, but that's what the manual has to say on the subject.
Here is one way, if I understood you correctly:

Code:
'Store lines of type LINE(x1,y1)-(x2,y2),color  in the array L:

'for storing up to 5 ines
n=5
DIM) L(n, n, n, n, n)

'for two lines:

'line 1:
L(1, 0, 0, 0, 0) = 0 'x11
L(0, 1, 0, 0, 0) = 0 'y11
L(0, 0, 1, 0, 0) = 8 'x21
L(0, 0, 0, 1, 0) = 8 'y21
L(0, 0, 0, 0, 1) = 7 'color1

'line 2:
L(2, 0, 0, 0, 0) = 8 'x12
L(0, 2, 0, 0, 0) = 0 'y12
L(0, 0, 2, 0, 0) = 0 'x22
L(0, 0, 0, 2, 0) = 8 'y22
L(0, 0, 0, 0, 2) = 7 'color2

'draw the first two lines stored in the array L:
SCREEN 13
FOR I = 1 TO 2
  LINE(L(I,  0, 0, 0, 0),L(0,  I, 0, 0, 0))-(L(0,  0, I, 0, 0), _
  L(0, 0, 0, I, 0)), L(0,  0, 0, 0, I)
NEXT I

'done!
the bresenham line algorithm works well enough, except the line is some what broken, what I am doing is getting the mouse coordinates and then drawing a line between
oldMousex, oldMousey and mousex, mousey
the line comes out all broken looking, is there a way to remedy this?
never mind :oops:
I found the bug
it was a mouse handling problem, thanks for your help Smile