|
-
Sep 29th, 2003, 09:51 AM
#1
Thread Starter
Fanatic Member
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:
Private Sub Form_Activate()
Dim eX, eY, eR, eRGB1, mX, mY, mR, mRGB1 'declare variables
ScaleMode = 5 'set scale to inches
'FillColor = RGB(255, 255, 255) 'set color to fill circle
'FillStyle = 0 'set transparent or solid
'DrawWidth = 3 'set line weight of cirle
DrawStyle = 0 'set solid =1, dashed=2 or dotted=3
eX = ScaleWidth / 2 'centers circle on form
eY = ScaleHeight / 2 'centers circle on form
mX = eX + 1.5 'centers circle on form
mY = eY + 0 'centers circle on form
eR = 1
mR = 0.25
eRGB1 = RGB(255, 255, 255) 'set line color of circle
mRGB1 = RGB(255, 255, 255) 'set line color of circle
'draw the circles
Circle (eX, eY), eR, eRGB1
Circle (mX, mY), mR, mRGB1
End Sub
He who never made a mistake never made a discovery?
-
Sep 29th, 2003, 01:21 PM
#2
Fanatic Member
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:
Private Type tCircle
X As Double
Y As Double
R As Single
Color As Long
End Type
Private xMove As Double
Private yMove As Double
Private BigCircle As tCircle
Private SmallCircle As tCircle
Private Const PI = 3.14159265
Private Radius As Single
Private dDegree As Single
Const SPEED = 90
Private Function Cosine(ByVal degrees As Single) As Double
Cosine = Cos(degrees * PI / 180)
End Function
Private Function Sine(ByVal degrees As Single) As Double
Sine = Sin(degrees * PI / 180)
End Function
Private Sub Form_Activate()
ScaleMode = 5 'set scale to inches
'FillColor = RGB(255, 255, 255) 'set color to fill circle
'FillStyle = 0 'set transparent or solid
'DrawWidth = 3 'set line weight of cirle
DrawStyle = 0 'set solid =1, dashed=2 or dotted=3
BigCircle.X = ScaleWidth / 2 'centers circle on form
BigCircle.Y = ScaleHeight / 2 'centers circle on form
BigCircle.R = 1
SmallCircle.X = BigCircle.X + BigCircle.R + 0.5
SmallCircle.Y = BigCircle.Y
SmallCircle.R = 0.25
Radius = BigCircle.R + 0.5
dDegree = 0
BigCircle.Color = RGB(255, 255, 255) 'set line color of circle
SmallCircle.Color = RGB(255, 255, 255) 'set line color of circle
'draw the circles
Circle (BigCircle.X, BigCircle.Y), BigCircle.R, BigCircle.Color
Circle (SmallCircle.X, SmallCircle.Y), SmallCircle.R, SmallCircle.Color
End Sub
Private Sub Timer1_Timer()
Dim xDif As Single
'erase the old circle
SmallCircle.Color = Me.BackColor
Circle (SmallCircle.X, SmallCircle.Y), SmallCircle.R, SmallCircle.Color
'move the circle
If dDegree > 360 Then
dDegree = 1
End If
yMove = Sine(dDegree) * Radius
xMove = Cosine(dDegree) * Radius
SmallCircle.Y = BigCircle.Y + yMove
SmallCircle.X = BigCircle.X + xMove
dDegree = dDegree + .5
'draw the circle
SmallCircle.Color = RGB(255, 255, 255) 'set line color of circle
Circle (SmallCircle.X, SmallCircle.Y), SmallCircle.R, SmallCircle.Color
Timer1.Interval = SPEED
End Sub
Motto: Anything for a laugh.
Getting second place only means you are the first loser to cross the finish line.
-
Sep 29th, 2003, 01:24 PM
#3
Fanatic Member
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.
-
Sep 29th, 2003, 01:29 PM
#4
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|