Results 1 to 4 of 4

Thread: get circles to orbit

  1. #1

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Smile get circles to orbit

    I have been learning how to draw circles. Now I want to learn how to make a circle orbit another. I imagine there are many ways to do this? Given my code below, what would be the simplest method to have the smaller circle orbit the larger one?

    VB Code:
    1. Private Sub Form_Activate()
    2.     Dim eX, eY, eR, eRGB1, mX, mY, mR, mRGB1 'declare variables
    3.     ScaleMode = 5 'set scale to inches
    4.     'FillColor = RGB(255, 255, 255) 'set color to fill circle
    5.     'FillStyle = 0 'set transparent or solid
    6.     'DrawWidth = 3 'set line weight of cirle
    7.     DrawStyle = 0 'set solid =1, dashed=2 or dotted=3
    8.     eX = ScaleWidth / 2 'centers circle on form
    9.     eY = ScaleHeight / 2 'centers circle on form
    10.     mX = eX + 1.5 'centers circle on form
    11.     mY = eY + 0 'centers circle on form
    12.     eR = 1
    13.     mR = 0.25
    14.     eRGB1 = RGB(255, 255, 255) 'set line color of circle
    15.     mRGB1 = RGB(255, 255, 255) 'set line color of circle
    16.     'draw the circles
    17.     Circle (eX, eY), eR, eRGB1
    18.     Circle (mX, mY), mR, mRGB1
    19. End Sub
    He who never made a mistake never made a discovery?

  2. #2
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    Here you go. All you need to do is copy this code and paste over your old code. Then add a timer to the form and set the interval to 90.

    VB Code:
    1. Private Type tCircle
    2.     X As Double
    3.     Y As Double
    4.     R As Single
    5.     Color As Long
    6. End Type
    7. Private xMove As Double
    8. Private yMove As Double
    9. Private BigCircle As tCircle
    10. Private SmallCircle As tCircle
    11. Private Const PI = 3.14159265
    12. Private Radius As Single
    13. Private dDegree As Single
    14. Const SPEED = 90
    15. Private Function Cosine(ByVal degrees As Single) As Double
    16.     Cosine = Cos(degrees * PI / 180)
    17. End Function
    18. Private Function Sine(ByVal degrees As Single) As Double
    19.     Sine = Sin(degrees * PI / 180)
    20. End Function
    21. Private Sub Form_Activate()
    22.    
    23.     ScaleMode = 5 'set scale to inches
    24.     'FillColor = RGB(255, 255, 255) 'set color to fill circle
    25.     'FillStyle = 0 'set transparent or solid
    26.     'DrawWidth = 3 'set line weight of cirle
    27.     DrawStyle = 0 'set solid =1, dashed=2 or dotted=3
    28.    
    29.     BigCircle.X = ScaleWidth / 2 'centers circle on form
    30.     BigCircle.Y = ScaleHeight / 2 'centers circle on form
    31.     BigCircle.R = 1
    32.    
    33.     SmallCircle.X = BigCircle.X + BigCircle.R + 0.5
    34.     SmallCircle.Y = BigCircle.Y
    35.     SmallCircle.R = 0.25
    36.    
    37.     Radius = BigCircle.R + 0.5
    38.     dDegree = 0
    39.    
    40.     BigCircle.Color = RGB(255, 255, 255) 'set line color of circle
    41.     SmallCircle.Color = RGB(255, 255, 255) 'set line color of circle
    42.  
    43.    
    44.     'draw the circles
    45.     Circle (BigCircle.X, BigCircle.Y), BigCircle.R, BigCircle.Color
    46.     Circle (SmallCircle.X, SmallCircle.Y), SmallCircle.R, SmallCircle.Color
    47. End Sub
    48. Private Sub Timer1_Timer()
    49.     Dim xDif As Single
    50.    
    51.     'erase the old circle
    52.     SmallCircle.Color = Me.BackColor
    53.     Circle (SmallCircle.X, SmallCircle.Y), SmallCircle.R, SmallCircle.Color
    54.    
    55.     'move the circle
    56.     If dDegree > 360 Then
    57.         dDegree = 1
    58.     End If
    59.    
    60.     yMove = Sine(dDegree) * Radius
    61.     xMove = Cosine(dDegree) * Radius
    62.    
    63.     SmallCircle.Y = BigCircle.Y + yMove
    64.     SmallCircle.X = BigCircle.X + xMove
    65.    
    66.     dDegree = dDegree + .5
    67.    
    68.     'draw the circle
    69.     SmallCircle.Color = RGB(255, 255, 255) 'set line color of circle
    70.     Circle (SmallCircle.X, SmallCircle.Y), SmallCircle.R, SmallCircle.Color
    71.    
    72.     Timer1.Interval = SPEED
    73. End Sub
    Motto: Anything for a laugh.

    Getting second place only means you are the first loser to cross the finish line.

  3. #3
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    You can change the SPEED constant to whatever you like, but I left it at 90, but you lower it make it move faster.
    Motto: Anything for a laugh.

    Getting second place only means you are the first loser to cross the finish line.

  4. #4

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740
    Hey thanks

    I'll give this a try.
    He who never made a mistake never made a discovery?

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