Оставить программу движения на экране точки, оставляющей светящийся след - VB
Формулировка задачи:
Составить программу движения на экране точки, оставляющей светящийся след, которая движется по орбите увеличивающегося: а)квадрата; б)окружности; в) треугольника.
Решение задачи: «Оставить программу движения на экране точки, оставляющей светящийся след»
textual
Листинг программы
Private Type Vec X As Double Y As Double End Type Private Const Speed As Single = 0.05 Private Const RelCount As Long = 70 Dim WithEvents cboType As ComboBox Dim WithEvents tmrTimer As Timer Dim Pt As Vec, Rel() As Vec, Dir As Vec, Size As Double Private Sub Iteration() Dim flip As Boolean Pt.X = Pt.X + Dir.X: Pt.Y = Pt.Y + Dir.Y If Pt.X > 1 Then Pt.X = 1: flip = True If Pt.Y > 1 Then Pt.Y = 1: flip = True If Pt.X < -1 Then Pt.X = -1: flip = True If Pt.Y < -1 Then Pt.Y = -1: flip = True Select Case cboType.ListIndex Case 0: If flip Then Dir = Rot(Dir, 1.5707963267949) Case 1: If flip Then Dir = Rot(Dir, 2.0943951023932) Case 2: Pt = Rot(Pt, Speed) End Select End Sub Private Function ToScreen(Pt As Vec) As Vec ToScreen.X = Pt.X * Me.ScaleWidth / 4 * Size + Me.ScaleWidth / 2 ToScreen.Y = Pt.Y * Me.ScaleHeight / 4 * Size + Me.ScaleHeight / 2 End Function Private Function Rot(Pt As Vec, Ang As Double) As Vec Rot.X = Pt.X * Cos(Ang) - Pt.Y * Sin(Ang) Rot.Y = Pt.X * Sin(Ang) + Pt.Y * Cos(Ang) End Function Private Sub UpdateRel() Dim i As Long For i = RelCount - 1 To 1 Step -1: Rel(i) = Rel(i - 1): Next End Sub Private Sub StartRel() Dim i As Long Rel(0) = ToScreen(Pt) For i = 1 To RelCount - 1: Rel(i) = Rel(0): Next End Sub Private Sub cboType_Click() Select Case cboType.ListIndex Case 0: Pt.X = -1: Pt.Y = -1: Dir.X = Speed: Dir.Y = 0 Case 1: Pt.X = 0: Pt.Y = -1: Dir.X = Speed: Dir.Y = 0: Dir = Rot(Dir, -1.0471975511966) Case 2: Pt.X = 0: Pt.Y = -1: Dir.X = 0: Dir.Y = 0 End Select StartRel Me.Cls End Sub Private Sub Form_Load() Me.ScaleMode = vbPixels: Me.BackColor = 0: Me.DrawWidth = 3 ReDim Rel(RelCount - 1): Size = 1 Set cboType = Me.Controls.Add("VB.Combobox", "cboType") cboType.AddItem "ГЉГўГ*äðГ*ГІ": cboType.AddItem "ÒðåóãîëüГ*ГЁГЄ": cboType.AddItem "Êðóã" cboType.ListIndex = 1: cboType.Visible = True Set tmrTimer = Me.Controls.Add("VB.Timer", "tmrTimer") tmrTimer.Interval = 32: tmrTimer.Enabled = True End Sub Private Sub tmrTimer_Timer() Dim i As Long Static sz As Long Size = (Sin(sz * 6.28318530717959E-03)) / 2 + 1 sz = (sz + 1) Mod 1000 Iteration UpdateRel Rel(0) = ToScreen(Pt) For i = RelCount - 2 To 0 Step -1 Me.Line (Rel(i + 1).X, Rel(i + 1).Y)-(Rel(i).X, Rel(i).Y), 255 * (RelCount - i - 2) / RelCount Next End Sub
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д