Движение электронов - VB
Формулировка задачи:
Здравстуйте,помогите с задачей!Есть неподвижное ядро атома и вокруг него вращаются три электрона в форме круга.Для атома нужна возможность выбора цвета,а для элетронов : радиус орбиты вращения(1-10),скорость(1-5), цвет, движение по часовой или против.Число оборотов для всех элетронов одинаковое. Также необходимо предусмотреть возможность установки параметров по умолчанию
Решение задачи: «Движение электронов»
textual
Листинг программы
- Dim Grad1 As Single, Grad2 As Single, Grad3 As Single
- Dim Spd1 As Single, Spd2 As Single, Spd3 As Single
- Dim R1 As Integer, R2 As Integer, R3 As Integer
- Dim clr1 As Long, clr2 As Long, clr3 As Long
- Dim NumberOfoborotov As Integer
- Dim oborot1 As Integer, oborot2 As Integer, oborot3 As Integer
- Const Pi As Single = 3.14159
- Private Sub Color1_Change()
- If Val(Color1.Text) > 5 Or Val(Color1.Text) < 1 Then Color1.Text = "1"
- Color1.SelStart = 0: Color1.SelLength = 1
- End Sub
- Private Sub Color1_GotFocus()
- Color1.SelStart = 0: Color1.SelLength = 1
- End Sub
- Private Sub Color1_KeyUp(KeyCode As Integer, Shift As Integer)
- Color1.SelStart = 0: Color1.SelLength = 1
- End Sub
- Private Sub Color1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Color1.SelStart = 0: Color1.SelLength = 1
- End Sub
- Private Sub Color2_Change()
- If Val(Color2.Text) > 5 Or Val(Color2.Text) < 1 Then Color2.Text = "1"
- Color2.SelStart = 0: Color2.SelLength = 1
- End Sub
- Private Sub Color2_GotFocus()
- Color2.SelStart = 0: Color2.SelLength = 1
- End Sub
- Private Sub Color2_KeyUp(KeyCode As Integer, Shift As Integer)
- Color2.SelStart = 0: Color2.SelLength = 1
- End Sub
- Private Sub Color2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Color2.SelStart = 0: Color2.SelLength = 1
- End Sub
- Private Sub Color3_Change()
- If Val(Color3.Text) > 5 Or Val(Color3.Text) < 1 Then Color3.Text = "1"
- Color3.SelStart = 0: Color3.SelLength = 1
- End Sub
- Private Sub Color3_GotFocus()
- Color3.SelStart = 0: Color3.SelLength = 1
- End Sub
- Private Sub Color3_KeyUp(KeyCode As Integer, Shift As Integer)
- Color3.SelStart = 0: Color3.SelLength = 1
- End Sub
- Private Sub Color3_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Color3.SelStart = 0: Color3.SelLength = 1
- End Sub
- Private Sub Form_Load()
- Timer1.Interval = 10
- Me.Height = 7000: Me.Width = 10000
- Picture1.Scale (-10, 10)-(10, -10)
- Picture1.FillStyle = 0
- Picture1.AutoRedraw = True
- cmdStart.Caption = "Start":
- Speed1.Text = 80: Radius1.Text = 3: Color1.Text = 3
- Speed2.Text = 50: Radius2.Text = 4: Color2.Text = 4
- Speed3.Text = 55: Radius3.Text = 6: Color3.Text = 5
- Call cmdStart_Click
- End Sub
- Private Sub Timer1_Timer()
- If oborot1 < NumberOfoborotov Then
- If Grad1 + 1 <= 2 * Pi / Spd1 Then
- Grad1 = Grad1 + 1
- Else
- Grad1 = 0
- oborot1 = oborot1 + 1
- End If
- End If
- If oborot2 < NumberOfoborotov Then
- If Grad2 + 1 <= 2 * Pi / Spd2 Then
- Grad2 = Grad2 + 1
- Else
- Grad2 = 0
- oborot2 = oborot2 + 1
- End If
- End If
- If oborot3 < NumberOfoborotov Then
- If Grad3 - 1 >= -2 * Pi / Spd3 Then
- Grad3 = Grad3 - 1
- Else
- Grad3 = 0
- oborot3 = oborot3 + 1
- End If
- End If
- If oborot1 = NumberOfoborotov And oborot2 = NumberOfoborotov And oborot3 = NumberOfoborotov Then Timer1.Enabled = False
- Picture1.Cls
- Picture1.FillColor = vbRed
- Picture1.Circle (0, 0), 0.5, vbRed
- Picture1.FillColor = clr1
- Picture1.Circle ((Cos(Grad1 * Spd1) * Val(Radius1.Text)), Sin(Grad1 * Spd1) * Val(Radius1.Text)), 0.2, clr1
- Picture1.FillColor = clr2
- Picture1.Circle ((Cos(Grad2 * Spd2) * Val(Radius2.Text)), Sin(Grad2 * Spd2) * Val(Radius2.Text)), 0.3, clr2
- Picture1.FillColor = clr3
- Picture1.Circle ((Cos(Grad3 * Spd3) * Val(Radius3.Text)), Sin(Grad3 * Spd3) * Val(Radius3.Text)), 0.2, clr3
- End Sub
- Private Sub cmdStart_Click()
- NumberOfoborotov = Val(oborot.Text)
- Grad1 = 0: Grad2 = 0: Grad3 = 0
- oborot1 = 0: oborot2 = 0: oborot3 = 0
- Spd1 = Val(Speed1.Text) / 1000
- Spd2 = Val(Speed2.Text) / 1000
- Spd3 = Val(Speed3.Text) / 1000
- clr1 = Choose(Val(Color1.Text), vbBlack, vbRed, vbGreen, vbBlue, vbMagenta)
- clr2 = Choose(Val(Color2.Text), vbBlack, vbRed, vbGreen, vbBlue, vbMagenta)
- clr3 = Choose(Val(Color3.Text), vbBlack, vbRed, vbGreen, vbBlue, vbMagenta)
- Timer1.Enabled = True
- End Sub
- Private Sub cmdStop_Click()
- Timer1.Enabled = False
- End Sub
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д