«Виртуальный» циклотрон
Option Explicit
Dim ax(3) As Single
Dim ay(3) As Single
Dim vx(3) As Single
Dim vy(3) As Single
Dim x(3) As Single
Dim y(3) As Single
Dim g As Single
Dim q As Single
Dim c As Single
Dim m As Single
Dim e As Single
Dim i As Byte
Dim k As Single
Private Sub Command1_Click()
g = Text1
m = Text6
q = Text7
e = Text8
vy(0) = Text2
vy(1) = Text3
vy(2) = Text4
vy(3) = Text5
Randomize
For i = 0 To 3 Step 1
Next i
For i = 0 To 3 Step 1
x(i) = -85 '- Rnd * 2
Next i
For i = 0 To 3 Step 1
y(i) = 0 ' -1 + Rnd * 2
Next i
c = q * g / m
Timer1.Enabled = True
For i = 0 To 3 Step 1
ax(i) = 0
ay(i) = 0
vx(i) = 0
Next i
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
vy(0) = Text2
vy(1) = Text3
vy(2) = Text4
vy(3) = Text5
For i = 0 To 3 Step 1
ax(i) = 0
ay(i) = 0
vx(i) = 0
vy(i) = 0
Next i
Picture1.Cls
Picture1.FillColor = vbWhite
Picture1.Circle (0, 0), 90
Picture1.FillColor = RGB(150, 150, 150)
Picture1.Circle (0, 87), 3
Picture1.Line (0, 84)-(100, 90.5), RGB(150, 150, 150), BF
Picture1.FillColor = vbWhite
Picture1.Circle (-3, 86), 3.8, vbWhite
End Sub
Private Sub Form_Load()
Picture1.Scale (-100, 100)-(100, -100)
Picture1.FillColor = vbWhite
Picture1.Circle (0, 0), 90
Text1 = 1
g = Text1
Text6 = 1
m = Text6
Text7 = 1
q = Text7
Text8 = 150
e = Text8
Text2 = 2
Text3 = 3
Text4 = 5
Text5 = 7
vy(0) = Text2
vy(1) = Text3
vy(2) = Text4
vy(3) = Text5
i = 0
Text2.BackColor = RGB(50 + 50 * i, 250 - 50 * i, 2.5 * i * i)
i = 1
Text3.BackColor = RGB(50 + 50 * i, 250 - 50 * i, 2.5 * i * i)
i = 2
Text4.BackColor = RGB(50 + 50 * i, 250 - 50 * i, 2.5 * i * i)
i = 3
Text5.BackColor = RGB(50 + 50 * i, 250 - 50 * i, 2.5 * i * i)
Picture1.FillColor = RGB(150, 150, 150)
Picture1.Circle (0, 87), 3
Picture1.Line (0, 84)-(100, 90.5), RGB(150, 150, 150), BF
Picture1.FillColor = vbWhite
Picture1.Circle (-3, 86), 3.8, vbWhite
End Sub
Private Sub Timer1_Timer()
Picture1.Cls
Picture1.FillColor = vbWhite
Picture1.Circle (0, 0), 90
Picture1.FillColor = RGB(150, 150, 150)
Picture1.Circle (0, 87), 3
Picture1.Line (0, 84)-(100, 90.5), RGB(150, 150, 150), BF
Picture1.FillColor = vbWhite
Picture1.Circle (-3, 86), 3.8, vbWhite
Dim dt As Single
Dim j As Integer
dt = 0.0006
While j < 120
For i = 0 To 3 Step 1
ax(i) = c * vy(i)
ay(i) = -c * vx(i)
If y(i) > 84 And x(i) > 0 Then ax(i) = 0: ay(i) = 0
vx(i) = vx(i) + ax(i) * dt
vy(i) = vy(i) + ay(i) * dt
x(i) = x(i) + vx(i) * dt
y(i) = y(i) + vy(i) * dt
If x(i) < -84 And 0 < y(i) And y(i) - vy(i) * dt <= 0.0000001 Then
k = vy(i) + q * e * 2 / (m * vy(i))
vy(i) = vy(i) + q * e * 2 / (m * (vy(i) + k) / 2)
x(i) = -85
End If
Next i
j = j + 1
Wend
j = 0
While j < 8
For i = 0 To 3 Step 1
ax(i) = c * vy(i)
ay(i) = -c * vx(i)
If y(i) > 84 And x(i) >= 0 Then ax(i) = 0: ay(i) = 0
vx(i) = vx(i) + ax(i) * dt
vy(i) = vy(i) + ay(i) * dt
x(i) = x(i) + vx(i) * dt
y(i) = y(i) + vy(i) * dt
If x(i) < -84 And 0 <= y(i) And y(i) - vy(i) * dt < 0 Then
vy(i) = vy(i) + q * e * 2 / (1 * m * vy(i))
x(i) = -85
End If
If x(i) ^ 2 + y(i) ^ 2 > 8100 And x(i) < 0 Or y(i) > 90.5 Or x(i) > 0 And y(i) > 83.9 And y(i) < 84.1 Then
Picture1.FillColor = vbRed
Picture1.Circle (x(i), y(i)), 0.3, vbRed
x(i) = 101
y(i) = 101
vx(i) = 0
vy(i) = 0
ax(i) = 0
ay(i) = 0
Else
Picture1.FillColor = RGB(50 + 50 * i, 250 - 50 * i, 2.5 * i * i)
Picture1.Circle (x(i), y(i)), 0.3, RGB(50 + 50 * i, 250 - 50 * i, 2.5 * i * i)
End If
Next i
j = j + 1
Wend
End Sub