I want to move an object around the screen with a timer in a circle pattern(automatically). Now I can move an object from side to side and check to see if I hit the form boundary.
I'm not sure understand you 100%. Do you want to move the picture in a circular route along the screen ¿
If that's the case, why not make it so that you don't have to worry about the form's borders in the first place.
You could perhaps use our good friends Sin, Cos & PI here - just a suggestion.
Or do you want the picture to move around, and when it hits the border, it bounces off of it, and proceeds to another border, for example :
The picture moves from the Top, and hits the left border, then it proceeds to the bottom border, then the right border, and then it just repeats the pattern. I sthat what you mean ¿
I do have a very small sample, which allows the picture to move in a spiral fashion, which might help a little bit.
Code:
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim cx As Integer
Dim x As Integer
Dim cy As Integer
Dim y As Integer
Dim RR As New Rectangle(10, 10, 400, 400)
cx = RR.Width / 2
cy = RR.Height / 2
Dim a As Single
Dim b As Single
Dim i As Long
Dim ang As Double
a = 0.15
b = 0.15
For i = 0 To 8000
ang = (PI / 720) * i
x = cx + (a * (System.Math.Cos(ang)) * (ee ^ (b * ang)))
y = cy - (a * (System.Math.Sin(ang)) * (ee ^ (b * ang)))
PictureBox1.Left = x
PictureBox1.Top = y
Next i
End Sub
When you want to move objects, the more useful equation is the "parametric" equation. The parametric equation gives the x and y values in terms of a third parameter which is usually interpreted as time.
In this case, and as HanneSThEGreaT has implied, the parametric equations of a circle are:
x = radius * sin (2*pi*frequency*time)
y = radius * cos (2*pi*frequency*time)
where radius=radius of the circle, and frequency=speed of the object around the circle (in cycles/circles per second).
Bookmarks