|
-
Apr 28th, 2003, 07:07 AM
#1
Thread Starter
Hyperactive Member
drawing lines
Hi,
Say if I have a line with coordinates:
(x1,y1)-(x2,y2)
This will have a beginning and an end point.
How can I have it so the line will continue on through these, points, forever, without stopping on the points? Just need it for a project I'm working on.
Thanks.
-
Apr 28th, 2003, 07:14 AM
#2
I would calculate the coordinates at the margin of the visible field (window/form) that are "on that line". Using those draw the line from one edge of the field to the other.
Of course, you have to redo that each time you change the visible field.
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Apr 28th, 2003, 10:44 AM
#3
Addicted Member
Assuming your example would give you a 45 degree angled line, it should be fairly easy to create something like...
VB Code:
dim n, x1, x2, y1, y2 as integer
x1= 1
x2=1
y1=2
y2=2
for n = 1 to 100 'or any number to outerspace
me.line (x1, y1) - (x2, y2)
x1=x2 'sets starting point to original ending point
y1=y2
x2=x2+n 'sets new ending point
y2=y2+n
next n
For anything other than a 45 degree angle, you would have to have a calculation of the original x y changes and put that into your formula.
-
Apr 28th, 2003, 11:14 AM
#4
Doing the math would be a much better way of getting there but since mine sucks, this is how I would do it.
VB Code:
Option Explicit
Private Sub Command1_Click()
ExtendLine 1476, 1253, 3269, 2387
End Sub
Private Sub Form_Load()
Me.AutoRedraw = True
Me.Line (1476, 1253)-(3269, 2387)
End Sub
Private Sub ExtendLine(ByVal x1 As Integer, _
ByVal Y1 As Integer, ByVal X2 As Integer, _
ByVal Y2 As Integer)
Dim x As Integer
Dim y As Integer
x = Abs(x1 - X2)
y = Abs(Y1 - Y2)
Do
Me.Cls
x1 = x1 - x
Y1 = Y1 - y
Me.Line (x1, Y1)-(X2, Y2)
Loop While x1 > 0 And Y1 > 0
Do
Me.Cls
X2 = X2 + x
Y2 = Y2 + y
Me.Line (x1, Y1)-(X2, Y2)
Loop While X2 < Me.Width And Y2 < Me.Height
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|