Advertisement
Roland-2

ss1

Nov 13th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 9.44 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2.  
  3. Public Class Form1
  4.  
  5.     Public balls As New List(Of Ball)
  6.     Private WithEvents tmr As Windows.Forms.Timer
  7.     Private WithEvents tmr2 As Windows.Forms.Timer
  8.     Private m_IsActive As Boolean = False
  9.     Private m_MouseLocation As Point
  10.     Private shortMode As Boolean
  11.     Public Shared Function Toggle(ByRef toggleThis As Boolean) _
  12.         As Boolean
  13.         toggleThis = Not toggleThis
  14.         Return toggleThis
  15.     End Function
  16.  
  17.     Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
  18.         If Not m_IsActive Then
  19.             Me.m_MouseLocation = New Point(e.X, e.Y)
  20.             m_IsActive = True
  21.         Else
  22.             If Math.Abs(e.X - Me.m_MouseLocation.X) > 10 Or _
  23.                 Math.Abs(e.Y - Me.m_MouseLocation.Y) > 10 Then
  24.                 ' The user has moved the mouse so leave this program
  25.                 Application.Exit()
  26.             End If
  27.         End If
  28.     End Sub
  29.  
  30.     Private Sub Tmr_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr.Tick
  31.  
  32.         For Each b As Ball In balls
  33.             '{
  34.             b.Move()
  35.  
  36.             If b.Location.X <= 0 OrElse (b.Location.X + b.Size.Width) >= Me.ClientSize.Width Then
  37.                 b.ReflectX()
  38.             End If
  39.             If b.Location.Y <= 0 OrElse (b.Location.Y + b.Size.Height) >= Me.ClientSize.Height Then
  40.                 b.ReflectY()
  41.             End If
  42.             '}
  43.         Next
  44.  
  45.         Me.Refresh()
  46.  
  47.     End Sub
  48.     Private Sub Tmr2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr2.Tick
  49.         Toggle(shortMode)
  50.     End Sub
  51.     'Draw
  52.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  53.         'MyBase.OnPaint(e)
  54.         Dim g As Graphics = e.Graphics
  55.         g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality
  56.         For Each b As Ball In balls
  57.             Dim rect As RectangleF
  58.             Dim sz As New SizeF(b.Size)
  59.  
  60.             If b.Elastic Then
  61.                 Dim pt As New PointF(b.Location.X, b.Location.Y)
  62.  
  63.  
  64.                 If pt.X < 0 Then
  65.                     sz.Width += pt.X
  66.                     pt.X = 0
  67.                 ElseIf (pt.X + sz.Width) > Me.ClientSize.Width Then
  68.                     sz.Width = Me.ClientSize.Width - pt.X
  69.                 End If
  70.  
  71.                 If pt.Y < 0 Then
  72.                     sz.Height += pt.Y
  73.                     pt.Y = 0
  74.                 ElseIf (pt.Y + sz.Height) > Me.ClientSize.Height Then
  75.                     sz.Height = Me.ClientSize.Height - pt.Y
  76.                 End If
  77.  
  78.                 rect = New RectangleF(pt, sz)
  79.  
  80.             Else
  81.  
  82.                 rect = New RectangleF(b.Location, b.Size)
  83.  
  84.             End If
  85.             Dim ss As Pen = New Pen(Color.FromArgb(75, b.Brush), 1)
  86.  
  87.  
  88.             Dim rect2 As Rectangle = New Rectangle(b.Location.X, b.Location.Y, b.width, b.width)
  89.  
  90.             'g.FillEllipse(b.Brush2, Rectangle.Inflate(rect2, -2, -2))
  91.             'g.DrawEllipse(ss, rect)
  92.  
  93.             If balls.Count > 12 Then
  94.  
  95.                 Dim pts(2) As Point
  96.                 Dim cpen As New Pen(Color.FromArgb(44, 66, 66, 66), 2)
  97.                 'cpen.DashStyle = DashStyle.DashDotDot
  98.                 pts(0) = New Point(balls(4).Location.X + (balls(4).width / 2), balls(4).Location.Y + (balls(4).width / 2))
  99.  
  100.                 pts(1) = New Point(balls(6).Location.X + (balls(6).width / 2), balls(6).Location.Y + (balls(6).width / 2))
  101.  
  102.                 pts(2) = New Point(balls(8).Location.X + balls(8).width / 2, balls(8).Location.Y + (balls(8).width / 2))
  103.  
  104.  
  105.                 g.DrawCurve(cpen, pts)
  106.  
  107.  
  108.             End If
  109.  
  110.  
  111.         Next
  112.         Dim Roland As GraphicsPath
  113.  
  114.         For Each b As Ball In balls
  115.  
  116.             Dim rect2 As Rectangle = New Rectangle(b.Location.X, b.Location.Y, b.width, b.width)
  117.             Dim newrect As Rectangle = (Rectangle.Inflate(rect2, -1, -1))
  118.             Roland = CreateBottomRadialPath(newrect)
  119.             Dim clip As GraphicsPath = CreateRoundRectangle(newrect, b.width / 2)
  120.             g.SetClip(clip, CombineMode.Intersect)
  121.  
  122.             Dim pgr As New PathGradientBrush(Roland)
  123.             Dim opacity As Integer = Convert.ToInt32(&HB2 * 1 + 0.5F)
  124.             Dim bounds As RectangleF = Roland.GetBounds()
  125.             Dim pgr2 As Pen
  126.             If shortMode = False Then pgr2 = New Pen(Color.FromArgb(45, b.Brush), 3) Else pgr2 = New Pen(Color.FromArgb(225, b.Brush), 3)
  127.             pgr.CenterPoint = New PointF((bounds.Left + bounds.Right) / 2.0F, (bounds.Top + bounds.Bottom) / 2.0F)
  128.             If shortMode = False Then pgr.CenterColor = b.Brush Else pgr.CenterColor = Color.FromArgb(47, b.Brush)
  129.             pgr.SurroundColors = New Color() {Color.FromArgb(175, Color.Black)}
  130.  
  131.             '
  132.  
  133.             g.FillPath(pgr, Roland)
  134.  
  135.  
  136.             g.DrawPath(pgr2, clip)
  137.             g.ResetClip()
  138.  
  139.  
  140.  
  141.             CType(Roland, IDisposable).Dispose()
  142.             pgr2.Dispose()
  143.         Next
  144.  
  145.  
  146.  
  147.     End Sub
  148.     Private Function CreateBottomRadialPath(ByVal rectangle As Rectangle) As GraphicsPath
  149.         Dim path As New GraphicsPath()
  150.         Dim rect As RectangleF = rectangle
  151.         rect.X -= rect.Width * 0.35F
  152.         rect.Y -= rect.Height * 0.15F
  153.         rect.Width *= 1.7F
  154.         rect.Height *= 2.2F
  155.         path.AddEllipse(rect)
  156.         path.CloseFigure()
  157.         Return path
  158.     End Function
  159.  
  160.     Public Function CreateRoundRectangle(ByVal rectangle As Rectangle, ByVal radius As Integer) As GraphicsPath
  161.         Dim path As New GraphicsPath()
  162.         Dim l As Integer = rectangle.Left
  163.         Dim t As Integer = rectangle.Top
  164.         Dim w As Integer = rectangle.Width
  165.         Dim h As Integer = rectangle.Height
  166.         Dim d As Integer
  167.  
  168.         If shortMode = True Then d = rectangle.Width / 2 Else d = rectangle.Width
  169.  
  170.         path.AddArc(l, t, d, d, 180, 90) ' topleft
  171.         path.AddLine(l + radius, t, l + w - radius, t) ' top
  172.         path.AddArc(l + w - d, t, d, d, 270, 90) ' topright
  173.         path.AddLine(l + w, t + radius, l + w, t + h - radius) ' right
  174.         path.AddArc(l + w - d, t + h - d, d, d, 0, 90) ' bottomright
  175.         path.AddLine(l + w - radius, t + h, l + radius, t + h) ' bottom
  176.         path.AddArc(l, t + h - d, d, d, 90, 90) ' bottomleft
  177.         path.AddLine(l, t + h - radius, l, t + radius) ' left
  178.         path.CloseFigure()
  179.         Return path
  180.     End Function
  181.  
  182.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  183.         SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.AllPaintingInWmPaint, True)
  184.         tmr = New Windows.Forms.Timer
  185.         tmr.Interval = 35
  186.         tmr.Start()
  187.         tmr2 = New Windows.Forms.Timer
  188.         tmr2.Interval = 8000
  189.         tmr2.Start()
  190.         Dim rnd As New Random
  191.  
  192.         For i As Integer = 0 To 21
  193.             Dim b As New Ball(New Point(Me.Width / 2, Me.Height / 2))
  194.             balls.Insert(i, b)
  195.         Next
  196.         Me.BackColor = Color.Black
  197.         Me.Width = 1000
  198.         Me.Height = 800
  199.     End Sub
  200.  
  201.     Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
  202.         Invalidate()
  203.     End Sub
  204.  
  205. End Class
  206.  
  207.  
  208. Public Class Ball
  209.  
  210.     Public Location As PointF
  211.     Public Size As SizeF
  212.     Public Speed As Single = 100
  213.     Public Brush2 As Brush
  214.     Public Elastic As Boolean
  215.     Public Brush As Color
  216.     Private _dir As Single
  217.     Private r As New Random
  218.     Public Property Direction() As Single
  219.         Get
  220.             Return (_dir / Math.PI) * 180
  221.         End Get
  222.         Set(ByVal value As Single)
  223.             Do While value >= 360
  224.                 value -= 360
  225.             Loop
  226.             Do While value < 0
  227.                 value += 360
  228.             Loop
  229.  
  230.             _dir = (value / 180) * Math.PI
  231.         End Set
  232.     End Property
  233.  
  234.     Dim bwidth As Integer
  235.     Public Property width() As Integer
  236.         Get
  237.             Return Me.Size.Width
  238.         End Get
  239.         Set(ByVal value As Integer)
  240.             bwidth = value
  241.         End Set
  242.     End Property
  243.  
  244.  
  245.     Public WriteOnly Property Color() As Color
  246.         Set(ByVal value As Color)
  247.             Me.Brush2 = New SolidBrush(value)
  248.         End Set
  249.     End Property
  250.  
  251.  
  252.     Public Property Color2() As Color
  253.         Get
  254.             Return Color2
  255.         End Get
  256.         Set(ByVal value As Color)
  257.             Me.Brush = value
  258.         End Set
  259.  
  260.     End Property
  261.  
  262.  
  263.     Public Sub New(ByVal Location As PointF)
  264.         Me.Location = Location
  265.  
  266.  
  267.         Dim c_size As Integer = Math.Floor(Rnd() * 45) + 40
  268.         Me.Size = New Size(c_size, c_size)
  269.         Me.Speed = Math.Ceiling(Rnd() * 10) + 6
  270.  
  271.         ' Me.Color2 = System.Drawing.Color.FromArgb(155, Math.Floor(r.Next(150, 255)), Math.Floor(r.Next(150, 255)), Math.Floor(r.Next(150, 255)))
  272.         Me.Color2 = System.Drawing.Color.FromArgb(255, Math.Floor(Rnd() * 256), Math.Floor(Rnd() * 256), Math.Floor(Rnd() * 256))
  273.         Me.Color = System.Drawing.Color.FromArgb(66, 1, Math.Floor(Rnd() * 256), Math.Floor(Rnd() * 256))
  274.  
  275.         Me.Direction = Rnd() * 360
  276.  
  277.         Me.Elastic = True
  278.  
  279.     End Sub
  280.  
  281.     Public Sub Move()
  282.         Location.X += Math.Sin(_dir) * Speed
  283.         Location.Y -= Math.Cos(_dir) * Speed
  284.     End Sub
  285.  
  286.     Public Sub ReflectX()
  287.         Direction = 360.0! - Direction
  288.     End Sub
  289.     Public Sub ReflectY()
  290.         Direction = 540.0! - Direction
  291.     End Sub
  292.  
  293.  
  294. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement