0Hawk0

Relational Color Switcher

Jan 20th, 2016
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.90 KB | None | 0 0
  1. Class RelationalColorSwitcher
  2.  
  3.     Private _currentColor As Color
  4.  
  5.     Private _transitions As Integer
  6.     Private _transitionsLapsed As Integer
  7.  
  8.     Private currentValues(3) As Double
  9.     Private increments(3) As Double
  10.  
  11.     Public Property OriginalColor As Color
  12.     Public Property NewColor As Color
  13.  
  14.     Public ReadOnly Property CurrentColor As Color
  15.         Get
  16.             Return _currentColor
  17.         End Get
  18.     End Property
  19.  
  20.     Public ReadOnly Property Transitions As Integer
  21.         Get
  22.             Return _transitions
  23.         End Get
  24.     End Property
  25.  
  26.     Public ReadOnly Property TransitionsLapsed As Integer
  27.         Get
  28.             Return _transitionsLapsed
  29.         End Get
  30.     End Property
  31.  
  32.     Sub New(originalColor As Color, newColor As Color, Optional transitions As Integer = 10)
  33.  
  34.         Me.OriginalColor = originalColor
  35.         Me.NewColor = newColor
  36.         _transitions = transitions
  37.  
  38.         _transitionsLapsed = 0
  39.  
  40.         currentValues = GetValues(originalColor)
  41.  
  42.         GetIncrements(GetValues(originalColor), GetValues(newColor))
  43.  
  44.     End Sub
  45.  
  46.     Public Sub Transition()
  47.  
  48.         For i As Integer = 0 To 3
  49.             currentValues(i) += increments(i)
  50.         Next
  51.  
  52.         _currentColor = Color.FromArgb(
  53.             SetInteger(CInt(currentValues(0))), _
  54.             SetInteger(CInt(currentValues(1))), _
  55.             SetInteger(CInt(currentValues(2))), _
  56.             SetInteger(CInt(currentValues(3))))
  57.  
  58.         _transitionsLapsed += 1
  59.  
  60.     End Sub
  61.  
  62.     Private Sub GetIncrements(originalValues As Double(), newValues As Double())
  63.  
  64.         For i As Integer = 0 To 3
  65.             increments(i) = (newValues(i) - originalValues(i)) / _transitions
  66.         Next
  67.  
  68.     End Sub
  69.  
  70.     Private Function GetValues(color As Color) As Double()
  71.         Return New Double() {CDbl(color.A), CDbl(color.R), CDbl(color.G), CDbl(color.B)}
  72.     End Function
  73.  
  74. End Class
Advertisement
Add Comment
Please, Sign In to add comment