I'm attempting to convert this piece of Javascript to VB.net code, and I'm having some trouble getting it to work. All the JS does is some math/byte operations, so I don't think I'm going beyond the scope of either language. Here the original code, sourced from:
Pimp Trizkit's Colour Shading Code
function shadeColor2(color, percent) {
var f=parseInt(color.slice(1),16),t=percent<0?0:255,p=percent<0?percent*-1:percent,R=f>>16,G=f>>8&0x00FF,B=f&0x0000FF;
return "#"+(0x1000000+(Math.round((t-R)*p)+R)*0x10000+(Math.round((t-G)*p)+G)*0x100+(Math.round((t-B)*p)+B)).toString(16).slice(1);}
And here's what I've attempted to convert it to:
Public Function LightColor(color As String, percent As Integer) As Color
Dim f As Integer = Convert.ToInt32(color.Substring(1), 16)
Dim t As Integer
If percent < 0 Then
t = 0
Else
t = 255
End If
Dim p As Integer
If percent < 0 Then
p = percent * -1
Else
p = percent
End If
Dim R As Integer = f >> 16
Dim G As Integer = f >> 8 And &HFF
Dim B As Integer = f And &HFF
Dim finalColor As String = "#" + (Convert.ToString( _
(&H1000000 + (Math.Round((t - R) * p) + R) * &H10000 + _
(Math.Round((t - G) * p) + G) * &H100 + _
(Math.Round((t - B) * p) + B))) _
).Substring(1)
Me.txtID.Text = finalColor
Return ColorTranslator.FromHtml(finalColor)
End Function
I would greatly appreciate some help regarding my amateur conversion and whether it could work, I've researched the relevant JS syntax but I'm not sure whether I changed it properly. After running my code with these parameters:
LightColor("#2980b9", 20)
I obtain a 8-digit hex color (#00642865) which is not even a color-I think I have some problems with the formatting of the hex output.