Dymetric class
Public Class Dymetric
Private line_region As New StraightLineRegion
Private do_simulation = False
Public Sub decideAction(sender As Object, g As Graphics, click_check As Boolean)
If do_simulation And click_check Then
line_region.play(sender, g)
do_simulation = False
Else
line_region.prep(sender, g)
do_simulation = True
End If
End Sub
End Class
VB.Net code for StraightLineRegion class
Public Class StraightLineRegion
Private x_ball, y_ball As Integer
Private previous_x As Integer = 0
Private previous_y As Integer = 0
Private Const ballDIAMETER = 80
Private x1, y1, x2, y2 As Integer
Private m, c As Double
Private x_line As Double
Dim ball_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)
x_ball = 10
y_ball = Math.Round(sender.Height / 2)
ball_colour = New System.Drawing.SolidBrush(System.Drawing.Color.Yellow)
x1 = Math.Round(sender.Width / 2) - 100
y1 = 70
x2 = Math.Round(sender.Width / 2) + 100
y2 = sender.Height - 50
m = (y2 - y1) / (x2 - x1)
c = (x2 * y1 - x1 * y2) / (x2 - x1)
x_line = (y_ball - c) / m
g.DrawLine(Pens.Black, x1, y1, x2, y2)
If previous_x > 0 Then
g.FillEllipse(bg_colour, previous_x, previous_y, ballDIAMETER, ballDIAMETER)
End If
g.FillEllipse(ball_colour, x_ball, y_ball, ballDIAMETER, ballDIAMETER)
previous_x = x_ball
previous_y = y_ball
End Sub
Public Sub play(sender As Object, g As Graphics)
Do While x_ball < sender.Width - ballDIAMETER
If x_ball >= x_line Then
ball_colour = New System.Drawing.SolidBrush(System.Drawing.Color.Green)
End If
g.FillEllipse(bg_colour, previous_x, previous_y, ballDIAMETER, ballDIAMETER)
g.FillEllipse(ball_colour, x_ball, y_ball, ballDIAMETER, ballDIAMETER)
previous_x = x_ball
x_ball += 10
Threading.Thread.Sleep(50)
Loop
End Sub
End Class