Dymetric class
Public Class Dymetric
Private cycle_zone As New CircularRegion
Private do_simulation = False
Public Sub decideAction(sender As Object, g As Graphics, click_check As Boolean)
If do_simulation And click_check Then
cycle_zone.play(sender, g)
do_simulation = False
Else
cycle_zone.prep(sender, g)
do_simulation = True
End If
End Sub
End Class
VB.Net code for CircularRegion class
Public Class CircularRegion
Private x_square, y_square As Integer
Private previous_x As Integer = 0
Private previous_y As Integer = 0
Private Const squareLENGTH = 100
Dim square_pen As New System.Drawing.Pen(System.Drawing.Color.Yellow)
Private a, b, r As Integer
Private Const dotDIAMETER = 10
Dim bg_colour As New System.Drawing.SolidBrush(System.Drawing.Color.LightGray)
Public Sub prep(sender As Object, g As Graphics)
x_square = 10
y_square = Math.Round(sender.Height / 2)
square_pen.Width = 5
a = Math.Round(sender.Width / 2)
b = Math.Round(sender.Height / 2)
r = sender.Height / 3
g.DrawEllipse(Pens.Black, a - r, b - r, 2 * r, 2 * r)
If previous_x > 0 Then
g.FillRectangle(bg_colour, previous_x - 5, previous_y - 5, squareLENGTH + 10, squareLENGTH + 10)
End If
g.DrawRectangle(square_pen, x_square, y_square, squareLENGTH, squareLENGTH)
previous_x = x_square
previous_y = y_square
End Sub
Public Sub play(sender As Object, g As Graphics)
Do While x_square < sender.Width - squareLENGTH
Dim square_left = x_square
Dim square_right = x_square + squareLENGTH
Dim square_top = y_square
Dim square_bottom = y_square + squareLENGTH
Dim x_left_det = Math.Round(Math.Sqrt(Math.Pow(r, 2) - Math.Pow((square_left - a), 2)))
Dim x_right_det = Math.Round(Math.Sqrt(Math.Pow(r, 2) - Math.Pow((square_right - a), 2)))
Dim y_up_det = Math.Round(Math.Sqrt(Math.Pow(r, 2) - Math.Pow((square_top - b), 2)))
Dim y_down_det = Math.Round(Math.Sqrt(Math.Pow(r, 2) - Math.Pow((square_bottom - b), 2)))
square_pen.Dispose()
square_pen = New System.Drawing.Pen(System.Drawing.Color.Yellow)
If square_top > b - x_left_det And square_bottom < b + x_left_det _
And square_top > b - x_right_det And square_bottom < b + x_right_det _
And square_left > a - y_up_det And square_right < a + y_up_det _
And square_left > a - y_down_det And square_right < a + y_down_det Then
square_pen = New System.Drawing.Pen(System.Drawing.Color.Green)
End If
square_pen.Width = 5
g.FillRectangle(bg_colour, previous_x - 5, previous_y - 5, squareLENGTH + 10, squareLENGTH + 10)
g.DrawRectangle(square_pen, x_square, y_square, squareLENGTH, squareLENGTH)
previous_x = x_square
x_square += 10
Threading.Thread.Sleep(50)
Loop
End Sub
End Class