Results 1 to 4 of 4

Thread: drawing lines

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Glasgow,Scotland
    Posts
    281

    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.

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    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!

  3. #3
    Addicted Member
    Join Date
    Nov 2001
    Location
    San Diego, CA
    Posts
    159
    Assuming your example would give you a 45 degree angled line, it should be fairly easy to create something like...
    VB Code:
    1. dim n, x1, x2, y1, y2 as integer
    2.    x1= 1
    3.    x2=1
    4.    y1=2
    5.    y2=2
    6.  
    7.    for n = 1 to 100   'or any number to outerspace
    8.       me.line (x1, y1) - (x2, y2)
    9.       x1=x2     'sets starting point to original ending point
    10.       y1=y2
    11.       x2=x2+n  'sets new ending point
    12.       y2=y2+n
    13.    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.
    ttfn
    Kicker

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    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:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     ExtendLine 1476, 1253, 3269, 2387
    5. End Sub
    6.  
    7. Private Sub Form_Load()
    8.     Me.AutoRedraw = True
    9.     Me.Line (1476, 1253)-(3269, 2387)
    10. End Sub
    11.  
    12. Private Sub ExtendLine(ByVal x1 As Integer, _
    13.         ByVal Y1 As Integer, ByVal X2 As Integer, _
    14.         ByVal Y2 As Integer)
    15. Dim x As Integer
    16. Dim y As Integer
    17.  
    18.     x = Abs(x1 - X2)
    19.     y = Abs(Y1 - Y2)
    20.    
    21.     Do
    22.         Me.Cls
    23.         x1 = x1 - x
    24.         Y1 = Y1 - y
    25.         Me.Line (x1, Y1)-(X2, Y2)
    26.     Loop While x1 > 0 And Y1 > 0
    27.    
    28.     Do
    29.         Me.Cls
    30.         X2 = X2 + x
    31.         Y2 = Y2 + y
    32.         Me.Line (x1, Y1)-(X2, Y2)
    33.     Loop While X2 < Me.Width And Y2 < Me.Height
    34.  
    35. 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
  •  



Click Here to Expand Forum to Full Width