Results 1 to 3 of 3

Thread: [RESOLVED] Modify code to make floating Pictue stay within form boundries

  1. #1
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 07
    Posts
    3,000

    Resolved [RESOLVED] Modify code to make floating Pictue stay within form boundries

    How can i modify this code so picture does not disappear off the form

    Sub MovePic()
    Dim x As Single, y As Single, velocity As Single, angle As Single, vangle As Single
    CenterPic

    Me.picJackpot.ZOrder 0
    velocity = 2
    angle = Rnd * 6.283
    x = picJackpot.Left: y = picJackpot.Top

    Do
    If Rnd < 0.1 Then vangle = (Rnd - 0.5) * 0.5 'Change direction velocity randomly 10%chance
    angle = angle + (vangle + 6.283) Mod 6.283 'change direction
    x = x + Cos(angle) * velocity 'move position
    y = y + Sin(angle) * velocity
    picJackpot.Move x, y 'move image
    DoEvents 'threading
    Loop While mStopJackPot = False 'Forms.Count Or yourchoise
    End Sub
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  2. #2
    Frenzied Member
    Join Date
    Aug 11
    Location
    B.C., Canada
    Posts
    1,838

    Re: Modify code to make floating Pictue stay within form boundries

    try this see if it works for you

    Code:
    Sub MovePic()
     Dim x As Single, y As Single, angle As Single, vangle As Single, sCount As Single, Speed As Single
     'CenterPic
     Me.picJackpot.ZOrder 0
     Speed = 0.1 'between 0.1 - 100 ... if you want you can put more but thats insane!
     angle = Rnd * 6.283
     x = picJackpot.Left: y = picJackpot.Top
    
     Do While mStopJackPot = False
     DoEvents
     sCount = sCount + 1
     If sCount > 2500 / Speed Then
     sCount = 0
     If Rnd < 0.1 Then vangle = (Rnd - 0.5) * 0.5 'Change direction velocity randomly 10%chance
     angle = angle + (vangle + 6.283) Mod 6.283 'change direction
     x = x + Cos(angle) * 10 'move position
     y = y + Sin(angle) * 10
     If x <= 0 Then x = 0
     If x >= (Form1.Width - picJackpot.Width - 240) Then x = (Form1.Width - picJackpot.Width - 240)
     If y <= 0 Then y = 0
     If y >= (Form1.Height - picJackpot.Height - 560) Then y = (Form1.Height - picJackpot.Height - 560)
     picJackpot.Move x, y
     End If
     Loop
     End Sub
    or also like this

    Code:
    Sub MovePic(Speed As Single)
     Dim x As Single, y As Single, angle As Single, vangle As Single, sCount As Single
     'CenterPic
     picJackpot.ZOrder 0
     angle = Rnd * 6.283
     x = picJackpot.Left: y = picJackpot.Top
    
     Do While mStopJackPot = False
     DoEvents
     sCount = sCount + 1
     If sCount > 2500 / Speed Then
     sCount = 0
     If Rnd < 0.1 Then vangle = (Rnd - 0.5) * 0.5 'Change direction velocity randomly 10%chance
     angle = angle + (vangle + 6.283) Mod 6.283 'change direction
     x = x + Cos(angle) * 10 'move position
     y = y + Sin(angle) * 10
     If x <= 0 Then x = 0
     If x >= (Form1.Width - picJackpot.Width - 240) Then x = (Form1.Width - picJackpot.Width - 240)
     If y <= 0 Then y = 0
     If y >= (Form1.Height - picJackpot.Height - 560) Then y = (Form1.Height - picJackpot.Height - 560)
     picJackpot.Move x, y
     End If
     Loop
     End Sub
    
    Private Sub Form_Load()
    MovePic 0.1 'Speed 'best between 0.1 - 100 ... if you want you can put more but thats insane!
    End Sub
    
    Private Sub Command1_Click()
    MovePic 0.1
    'Speed 'best between 0.1 - 100 ... if you want you can put more but thats insane!
    End Sub
    Last edited by Max187Boucher; Aug 29th, 2012 at 11:14 PM.

  3. #3
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 07
    Posts
    3,000

    Re: Modify code to make floating Pictue stay within form boundries

    thanks that works
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •