Dymetric class
Public Class Dymetric
Private sine_curve As New PeriodicFunction
Private do_simulation = False
Public Sub decideAction(sender As Object, g As Graphics, click_check As Boolean)
If do_simulation And click_check Then
sine_curve.play(sender, g)
do_simulation = False
Else
sine_curve.prep(sender, g)
do_simulation = True
End If
End Sub
End Class
VB.Net code for PeriodicFunction class
Public Class PeriodicFunction
Private theta, a, y, half_vert_screen 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)
theta = 0
a = sender.Height / 3
half_vert_screen = sender.Height / 2
y = CInt(Math.Round(a * Math.Sin(theta * Math.PI / 180)) + half_vert_screen)
g.FillRectangle(bg_colour, 0, 60, sender.Width, sender.Height)
g.DrawLine(Pens.Black, 0, half_vert_screen + 5, sender.Width, half_vert_screen + 5)
g.FillEllipse(dot_colour, theta, y, dotDIAMETER, dotDIAMETER)
End Sub
Public Sub play(sender As Object, g As Graphics)
Do While theta < sender.Width - dotDIAMETER
y = CInt(Math.Round(a * Math.Sin(theta * Math.PI / 180)) + half_vert_screen)
g.FillEllipse(dot_colour, theta, y, dotDIAMETER, dotDIAMETER)
theta += 15
Threading.Thread.Sleep(50)
Loop
End Sub
End Class