Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- orts System.Drawing.Drawing2D
- Imports System.Math
- Public Class Form1
- Private boxes As New List(Of roundedBox)
- Private bg As BufferedGraphics
- Private contesto As New BufferedGraphicsContext
- Private WithEvents renderLoop As New Timer
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- With Me
- .Size = New Size(800, 800)
- .BackColor = Color.White
- End With
- With renderLoop
- .Interval = 10
- .Enabled = True
- End With
- contesto.MaximumBuffer = Me.Size
- bg = contesto.Allocate(Me.CreateGraphics, Me.DisplayRectangle)
- bg.Graphics.Transform = New Matrix(1, 0, 0, -1, Me.Width / 2, Me.Height / 2)
- bg.Graphics.SmoothingMode = SmoothingMode.AntiAlias
- For i As Double = 10 To 180 Step 10
- boxes.Add(New roundedBox(New Point(0, 0), 400, 400, i))
- Next
- End Sub
- Private Sub TrenderLoop_Tick(sender As Object, e As EventArgs) Handles renderLoop.Tick
- bg.Graphics.Clear(Me.BackColor)
- For Each r As roundedBox In boxes
- r.disegna(bg.Graphics)
- Next
- bg.Render(Me.CreateGraphics)
- End Sub
- End Class
- Public Class roundedBox
- Private origine As Point
- Private altezza As Integer
- Private larghezza As Integer
- Private gradi As Double
- Private percorso As New GraphicsPath
- Public rotazione As Double
- Private Const rad As Double = PI / 180
- Public Sub New(p As Point, width As Integer, height As Integer, rot As Double)
- origine = p
- larghezza = width
- altezza = height
- rotazione = rot
- trasforma()
- gradi = 0
- End Sub
- Public Sub trasforma()
- Dim coefficenteDiRotazione As Double
- If gradi < 180 Then
- coefficenteDiRotazione = (Sin(gradi * rad))
- altezza = (400 - (320 * Sin(gradi * rad)))
- gradi += 0.5
- ElseIf gradi = 180 Then
- gradi = 0
- End If
- coefficenteDiRotazione *= rotazione
- Dim fX As Double = ((larghezza / 2) * Sin(gradi * rad) + 1) * 2
- Dim fY As Double = ((altezza / 2) * Sin(gradi * rad) + 1) * 2
- percorso.Reset()
- percorso.AddArc(New Rectangle(origine.X - larghezza / 2, origine.Y + (altezza / 2), fX, fY), 90, 90)
- percorso.AddArc(New Rectangle(origine.X - larghezza / 2, (origine.Y - (altezza / 2)) + fY, fX, fY), 180, 90)
- percorso.AddArc(New Rectangle((origine.X + (larghezza / 2) - fX), (origine.Y - (altezza / 2) + fY), fX, fY), 270, 90)
- percorso.AddArc(New Rectangle((origine.X + (larghezza / 2) - fX), origine.Y + (altezza / 2), fX, fY), 360, 90)
- percorso.CloseFigure()
- percorso.Transform(New Matrix(1, 0, 0, 1, 0, -fY))
- percorso.Transform(New Matrix(Cos(coefficenteDiRotazione * rad), Sin(coefficenteDiRotazione * rad), -Sin(coefficenteDiRotazione * rad), Cos(coefficenteDiRotazione * rad), 0, 0))
- End Sub
- Public Sub disegna(g As Graphics)
- trasforma()
- g.DrawPath(New Pen(Color.Black), percorso)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement