Dymetric class
Public Class Dymetric
Private ellipse_ride As New EllipticalPath
Private do_simulation = False
Public Sub decideAction(sender As Object, g As Graphics, click_check As Boolean)
If do_simulation And click_check Then
ellipse_ride.play(sender, g)
do_simulation = False
Else
ellipse_ride.prep(sender, g)
do_simulation = True
End If
End Sub
End Class
VB.Net code for EllipticalPath class
Public Class EllipticalPath
Private h, k, a, b, x, y As Integer
Private Const dotDIAMETER = 10
Dim dot_colour As New System.Drawing.SolidBrush(System.Drawing.Color.Yellow)
Dim bg_colour As New System.Drawing.SolidBrush(System.Drawing.Color.LightGray)
Public Sub prep(sender As Object, g As Graphics)
h = Math.Round(sender.Width / 2)
k = Math.Round(sender.Height / 2)
a = Math.Round(sender.Width / 3)
b = Math.Round(sender.Height / 3)
x = h - a
y = k
g.FillRectangle(bg_colour, 0, 60, sender.Width, sender.Height)
g.FillEllipse(dot_colour, x, y, dotDIAMETER, dotDIAMETER)
End Sub
Public Sub play(sender As Object, g As Graphics)
Do While x <= h + a
y = CInt(Math.Round(k - (b / a) * Math.Sqrt(Math.Pow(a, 2) - Math.Pow((x - h), 2))))
g.FillEllipse(dot_colour, x, y, dotDIAMETER, dotDIAMETER)
y = CInt(Math.Round(k + (b / a) * Math.Sqrt(Math.Pow(a, 2) - Math.Pow((x - h), 2))))
g.FillEllipse(dot_colour, x, y, dotDIAMETER, dotDIAMETER)
x += 20
Threading.Thread.Sleep(50)
Loop
End Sub
End Class