Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class RelationalColorSwitcher
- Private _currentColor As Color
- Private _transitions As Integer
- Private _transitionsLapsed As Integer
- Private currentValues(3) As Double
- Private increments(3) As Double
- Public Property OriginalColor As Color
- Public Property NewColor As Color
- Public ReadOnly Property CurrentColor As Color
- Get
- Return _currentColor
- End Get
- End Property
- Public ReadOnly Property Transitions As Integer
- Get
- Return _transitions
- End Get
- End Property
- Public ReadOnly Property TransitionsLapsed As Integer
- Get
- Return _transitionsLapsed
- End Get
- End Property
- Sub New(originalColor As Color, newColor As Color, Optional transitions As Integer = 10)
- Me.OriginalColor = originalColor
- Me.NewColor = newColor
- _transitions = transitions
- _transitionsLapsed = 0
- currentValues = GetValues(originalColor)
- GetIncrements(GetValues(originalColor), GetValues(newColor))
- End Sub
- Public Sub Transition()
- For i As Integer = 0 To 3
- currentValues(i) += increments(i)
- Next
- _currentColor = Color.FromArgb(
- SetInteger(CInt(currentValues(0))), _
- SetInteger(CInt(currentValues(1))), _
- SetInteger(CInt(currentValues(2))), _
- SetInteger(CInt(currentValues(3))))
- _transitionsLapsed += 1
- End Sub
- Private Sub GetIncrements(originalValues As Double(), newValues As Double())
- For i As Integer = 0 To 3
- increments(i) = (newValues(i) - originalValues(i)) / _transitions
- Next
- End Sub
- Private Function GetValues(color As Color) As Double()
- Return New Double() {CDbl(color.A), CDbl(color.R), CDbl(color.G), CDbl(color.B)}
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment