Results 1 to 13 of 13

Thread: lines

  1. #1

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197

    Red face

    How would you draw a line and bend it like in paint?
    Or draw a straight line?
    I am thinking of something to do with the X and Y variables in an event.
    *************
    Also, tell me everything you know about .Move
    How would I use this in a timer to make a label or something move at the user-selected speed from its origin at runtime to a user-selected place without it apearing jagged and jerky?
    I know this is a lot of questions at one but they dont seem too hard.
    retired member. Thanks for everything

  2. #2
    Guest
    To move an object (ie a PictureBox) use the following code (demonstrates usage of Move method and a Timer control.
    Code:
    Private Sub Form_Load()
        Timer1.Interval = 1
    End Sub
    
    Private Sub Timer1_Timer()
        Picture1.Move Picture1.Left + 20, Picture1.Top
    End Sub

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Here's how you draw those curves, btw they're called bezier curves. You need to select four points for each curve so this will let you select each point by clicking on the form.
    Code:
    Private Type POINTAPI
            X As Long
            Y As Long
    End Type
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Cls
        Static Count&, points(3) As POINTAPI, temp As POINTAPI, z As Single
            Count = (Count + 1) Mod 4
            points(Count).X = X: points(Count).Y = Y
            temp = Bezier(0, points(0), points(1), points(2), points(3))
            CurrentX = temp.X: CurrentY = temp.Y
        For z = 0 To 1 Step 0.05
            temp = Bezier(z, points(0), points(1), points(2), points(3))
            Line -(temp.X, temp.Y)
        Next z
    End Sub
    
    Private Function Bezier(t!, p0 As POINTAPI, p1 As POINTAPI, p2 As POINTAPI, p3 As POINTAPI) As POINTAPI
        cX = 3 * (p1.X - p0.X)
        bX = 3 * (p2.X - p1.X) - cX
        aX = p3.X - p0.X - cX - bX
        cy = 3 * (p1.Y - p0.Y)
        By = 3 * (p2.Y - p1.Y) - cy
        ay = p3.Y - p0.Y - cy - By
        Bezier.X = aX * t ^ 3 + bX * t ^ 2 + cX * t + p0.X
        Bezier.Y = ay * t ^ 3 + By * t ^ 2 + cy * t + p0.Y
    End Function
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197

    Thank you!

    thankyouthankyouthankyou.
    But now,
    how can I make a straight line as in paint (click while holding, drag, then drop to create line) the bend it as in paint (click again)?
    Then.....
    How can I make an object follow the path of the line using the move statement?









































    Any idea?
    retired member. Thanks for everything

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    fairly more easier to draw a simple line.
    Code:
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Static Count&
            
            Count = (Count + 1) Mod 2
        If Count Then
            CurrentX = X
            CurrentY = Y
        Else
            Line -(X, Y)
        End If
    End Sub
    to move the object use move statement as in megantrons sample and use a counter to count its position, like count does above.
    To calculate the position you do:
    y=(y1-y2)/(x1-x2)*counter where counter acts as as x.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197

    Question

    So how would you make an object follow the path of a line?
    could you give it to me inside of one of
    Code:
    'these
    Thanks
    retired member. Thanks for everything

  7. #7

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197
    Im not sure if you people look in past messages, so i added a reply so this message would go to the front page. Please answer the above ?.
    (ill be blunt if i may)
    retired member. Thanks for everything

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Oh, sorry i didn't know you had replied here, well i think i can help but first i need to know, what you are trying to do, if there's any use storing the lines drawed and how you want to move the object
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197
    Im doing this for something similar to Flash. I have a simple ocx (basiclly a shape) that I need to move along a path that the user can draw and alter (as in Paint). The user should be able to edit the speed as well. The belzier curves you stated above would be good if they were a little more user-friendly (like in Paint). If possible, the lines that the user can draw will connect on their endpoints if they are drawn close enough together.
    Thanks for replying again!
    retired member. Thanks for everything

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Well theres a lot of stuff you need then, at the moment i can tell you you could have a good use of class modules and class collections, it would be good for you to know how they work. The bezier curve drawing can get more userfriendly than that, but you decide how. And to connect the endpoints is just simple collision detection. Also do you want to have handles to the lines so you can be able to move them after been drawn? The movement of the shape goes on one line only?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  11. #11

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197
    exactly. But what would I do for the user-friendly curves?
    retired member. Thanks for everything

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    If you want to have it like in paint, You have to store the points private in declarations section, and same goes for count variable. you change the count in mouseup event and redraw the curve in mousemove event instead.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  13. #13

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197

    good news

    I have found a sample at planet-source-code.com in the hall of fame section. Search for pencil or something like that. It has straight lines and curvy ones just like in paint.
    Now the bad news:
    It is extremely complex and blew my socks off.
    so... I was wondering if you could pick out the parts that just have to do with lines (straight and curvy).
    That may be a lot to ask but I wont put another reply on this forum again!!!
    retired member. Thanks for everything

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