This is the perfect example of how useful B4A is for VB programmers
I took some VB code for getting a color out of a rainbow (the lower code) and converted it to B4A (the upper code) with only minor changes (the dev didn't declare his variables properly for the most part)
You can compare to see just how little work I did to convert it
I took some VB code for getting a color out of a rainbow (the lower code) and converted it to B4A (the upper code) with only minor changes (the dev didn't declare his variables properly for the most part)
You can compare to see just how little work I did to convert it
B4X:
Sub HSLtoRGB(Hue As Int, Saturation As Int, Luminance As Int, Alpha As Int ) As Int
Dim temp3(3) As Double , Red As Int, Green As Int, Blue As Int ,temp1 As Double, temp2 As Double ,n As Int
Dim pHue As Double, pSat As Double, pLum As Double , pRed As Double, pGreen As Double, pBlue As Double
pHue = Min(239, Hue) / 239
pSat = Min(239, Saturation) / 239
pLum = Min(239, Luminance) / 239
If pSat = 0 Then
pRed = pLum
pGreen = pLum
pBlue = pLum
Else
If pLum < 0.5 Then
temp2 = pLum * (1 + pSat)
Else
temp2 = pLum + pSat - pLum * pSat
End If
temp1 = 2 * pLum - temp2
temp3(0) = pHue + 1 / 3
temp3(1) = pHue
temp3(2) = pHue - 1 / 3
For n = 0 To 2
If temp3(n) < 0 Then temp3(n) = temp3(n) + 1
If temp3(n) > 1 Then temp3(n) = temp3(n) - 1
If 6 * temp3(n) < 1 Then
temp3(n) = temp1 + (temp2 - temp1) * 6 * temp3(n)
Else
If 2 * temp3(n) < 1 Then
temp3(n) = temp2
Else
If 3 * temp3(n) < 2 Then
temp3(n) = temp1 + (temp2 - temp1) * ((2 / 3) - temp3(n)) * 6
Else
temp3(n) = temp1
End If
End If
End If
Next
pRed = temp3(0)
pGreen = temp3(1)
pBlue = temp3(2)
End If
Red = pRed * 255
Green = pGreen * 255
Blue = pBlue * 255
Return Colors.ARGB(Alpha, Red,Green,Blue)
End Sub
B4X:
Public Sub HSLtoRGB(ByVal Hue As Integer, ByVal Saturation As Integer, ByVal Luminance As Integer, ByRef Red As Integer, ByRef Green As Integer, ByRef Blue As Integer)
ReDim temp3!(0 To 2)
pHue! = Hue / 239
pSat! = Saturation / 239
pLum! = Luminance / 239
If pSat! = 0 Then
pRed! = pLum!
pGreen! = pLum!
pBlue! = pLum!
Else
If pLum! < 0.5 Then
temp2! = pLum! * (1 + pSat!)
Else
temp2! = pLum! + pSat! - pLum! * pSat!
End If
temp1! = 2 * pLum! - temp2!
temp3!(0) = pHue! + 1 / 3
temp3!(1) = pHue!
temp3!(2) = pHue! - 1 / 3
For n% = 0 To 2
If temp3!(n%) < 0 Then temp3!(n%) = temp3!(n%) + 1
If temp3!(n%) > 1 Then temp3!(n%) = temp3!(n%) - 1
If 6 * temp3!(n%) < 1 Then
temp3!(n%) = temp1! + (temp2! - temp1!) * 6 * temp3!(n%)
Else
If 2 * temp3!(n%) < 1 Then
temp3!(n%) = temp2!
Else
If 3 * temp3!(n%) < 2 Then
temp3!(n%) = temp1! + (temp2! - temp1!) * ((2 / 3) - temp3!(n%)) * 6
Else
temp3!(n%) = temp1!
End If
End If
End If
Next n%
pRed! = temp3!(0)
pGreen! = temp3!(1)
pBlue! = temp3!(2)
End If
Red = Int(pRed! * 255)
Green = Int(pGreen! * 255)
Blue = Int(pBlue! * 255)
End Sub