Animációk
A rugalmas ütközés (falnak) és pattogás animációja
Public Class Form1
Dim X, Y As Single
Dim Xold, Yold, irány As Single
Dim Vx As Single = 0
Dim Vy As Single = 0
Dim rajzlap As New Bitmap(150, 150)
Dim rajzlap2 As New Bitmap(150, 150)
Dim gr As Graphics = Graphics.FromImage(rajzlap)
Dim gr2 As Graphics = Graphics.FromImage(rajzlap2)
Dim ecset As New Pen(Color.Blue, 3)
Sub Ini()
irány = 1
Randomize()
gr.Clear(PictureBox2.BackColor)
gr2.Clear(PictureBox2.BackColor)
X = 0
Y = 0
Vx = 1 - Rnd(1)
Vy = 1 - Rnd(1)
Xold = X
Yold = Y
Timer1.Enabled = True
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If CheckBox1.Checked = True Then
' a gravitációs erotér szimulációja
Vy = Vy + irány * 0.05 * 5
End If
X = X + Vx * 5 'dx=vx*dt dt=5
Y = Y + Vy * 5 'dy=vy*dt dt=5
'a golyó aktuális koordinátái
gr.Clear(PictureBox2.BackColor)
gr.FillEllipse(Brushes.Blue, X, Y, 10, 10)
'a pálya képe a picture2-ben
gr2.DrawLine(Pens.Black, Xold, Yold, X, Y)
Xold = X
Yold = Y
'a falak figyelése és a rugalmas ütközés szimulációja fal esetén
If X >= 145 Then Vx = -Vx : Beep()
If Y >= 145 Then
Vy = -Vy : Beep()
irány = 1
End If
If Y <= 0 Then
Vy = -Vy : Beep()
irány = -1
End If
If X <= 0 Then Vx = -Vx : Beep()
PictureBox1.Image = rajzlap
PictureBox2.Image = rajzlap2
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call Ini()
Timer1.Enabled = True
End Sub
End Class