Results 1 to 3 of 3

Thread: [RESOLVED] Orbit a PictureBox around another PictureBox...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013

    Resolved [RESOLVED] Orbit a PictureBox around another PictureBox...

    I've found code that DRAWS circles and makes them orbit each other, but I can't for the life of me figure out how to implement this using two PictureBox controls (one orbiting around the other).

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Southern Tier NY

    Re: Orbit a PictureBox around another PictureBox...

    The pictureboxes won't be able to rotate, although you could rotate their contents assuming the drawing inside is small enough not to be clipped by the rotation.

    If you just want to orbit to pictureboxes, and not need to rotate them, then just use the circle code, which I assume is calculating the center of two circles. The two points would be the center of the pictureboxes (half width and half height).
    You would then offset the position by that half width, and half height, to locate the pictureboxes left,top corner so that the center of the box is at the center point calculated.

    Here's an example just written from scratch. Just need two pictureboxes, relatively small, perhaps 40 pixels or so in size and a timer control.
    Option Explicit
    Dim cx1 As Single, cx2 As Single
    Dim cy1 As Single, cy2 As Single
    Dim fcx As Single, fcy As Single
    Dim orbitDist As Single
    Dim orbitX As Single, orbitY As Single
    Dim Ang As Double
    Dim PI As Double
    Dim Rad_360 As Double
    Private Sub Form_Load()
    'atn(1) corresponds to 45 degrees (in radians)
    'PI corresponds to 180 degrees in Radians
    'so multiply 45 * 4 = 180  Atn(1) * 4 = PI
      PI = Atn(1) * 4
      Rad_360 = 2 * PI
      ScaleMode = vbPixels
      Picture1.ScaleMode = vbPixels
      Picture2.ScaleMode = vbPixels
      cx1 = Picture1.Width / 2
      cy1 = Picture1.Height / 2
      cx2 = Picture2.Width / 2
      cy2 = Picture2.Height / 2
      fcx = ScaleWidth / 2
      fcy = ScaleHeight / 2
      If fcx > fcy Then
        orbitDist = fcy / 2
        orbitDist = fcx / 2
      End If
      Picture1.Left = fcx - cx1  'Put Picture1 in the center of the form
      Picture1.Top = fcy - cy1
      Timer1.Interval = 10
      Timer1.Enabled = True
    End Sub
    Private Sub Timer1_Timer()
      Ang = Ang + 0.01
      If Ang > Rad_360 Then
        Ang = Ang - Rad_360
      End If
      orbitX = fcx + orbitDist * Sin(Ang)
      orbitY = fcy + orbitDist * Cos(Ang)
      Picture2.Move orbitX - cx2, orbitY - cy2
    End Sub
    Last edited by passel; Apr 20th, 2015 at 08:53 PM.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013

    Re: Orbit a PictureBox around another PictureBox...

    Thank you.

Tags for this Thread

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