Анимация простых фигур - Visual Basic .NET
Формулировка задачи:
как сделать вот такое на вб нет ?) https://www.youtube.com/watch?v=sGXIsXtpN0k
Решение задачи: «Анимация простых фигур»
textual
Листинг программы
- Public Class Form1
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Dim mex As New Mexanizm(PictureBox1)
- mex.Animate()
- End Sub
- End Class
- Public Class Mexanizm
- Private bg As Drawing.BufferedGraphics
- Private bgc As Drawing.BufferedGraphicsContext
- Private cntrl As Control
- Private g As Graphics
- Private AB, BC, CD, DB, CE As Single
- Private Ax, AY, Bx, By, Cx, Cy, Dx, Dy, Ey, Ex As Single
- Private angleAB, angleDB, angleBC, angleCE As Double
- Const angle90 As Double = (90.0R * Math.PI) / 180.0R
- Sub New([Control] As Control)
- cntrl = [Control]
- Ax = 100
- AY = 200
- AB = 30
- BC = 100
- CD = 90
- CE = 65
- Dx = Ax + 65
- Dy = AY - 100
- angleAB = (135.0R * Math.PI) / 180
- bgc = Drawing.BufferedGraphicsManager.Current
- bgc.MaximumBuffer = New Size([Control].Size.Width + 1, [Control].Size.Height + 1)
- bg = bgc.Allocate([Control].CreateGraphics, New Rectangle(0, 0, [Control].Size.Width, [Control].Size.Height))
- End Sub
- Private Sub Calculate()
- Bx = Math.Cos(angleAB) * AB + Ax
- By = Math.Sin(angleAB) * AB * -1 + AY
- DB = Math.Sqrt((Dx - Bx) ^ 2 + (Dy - By) ^ 2)
- angleDB = Math.Acos((DB ^ 2 + (Dx - Bx) ^ 2 - (Dy - By) ^ 2) / (2 * DB * (Dx - Bx)))
- angleBC = Math.Acos((BC ^ 2 + DB ^ 2 - CD ^ 2) / (2 * BC * DB)) + angleDB
- Cx = Math.Cos(angleBC) * BC + Bx
- Cy = Math.Sin(angleBC) * BC * -1 + By
- angleCE = Math.Acos((Dy - Cy) / CD)
- Ex = Math.Cos(angleCE) * CE + Cx
- Ey = Math.Sin(angleCE) * CE * -1 + Cy
- End Sub
- Public Sub Animate()
- Dim r As Integer
- Do
- angleAB += 0.01R
- If angleAB >= Math.PI Then angleAB = -Math.PI : r += 1
- Me.Calculate()
- bg.Graphics.Clear(Color.White)
- bg.Graphics.DrawEllipse(Pens.Black, Ax - AB, AY - AB, AB * 2, AB * 2)
- bg.Graphics.DrawLine(Pens.Black, Ax, AY, Bx, By)
- bg.Graphics.DrawLine(Pens.Black, Bx, By, Cx, Cy)
- bg.Graphics.DrawLine(Pens.Black, Cx, Cy, Dx, Dy)
- bg.Graphics.DrawLine(Pens.Black, Cx, Cy, Ex, Ey)
- bg.Render(Graphics.FromHwnd(cntrl.Handle))
- My.Application.DoEvents()
- Threading.Thread.Sleep(10)
- Loop While (r < 5)
- End Sub
- End Class
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д