Dear friends, how to convert distance into color values? The application is to plot distance values to spatial coordinates with color coding.
Sub InterpolateColor(StartClr As Int, EndClr As Int, Fraction As Float) As Int
Dim clr As Int
For i = 0 To 3
Dim shift As Int = 8 * i
Dim src As Int = Bit.UnsignedShiftRight(Bit.And(StartClr, Bit.ShiftLeft(0xff, shift)), shift)
Dim target As Int = Bit.UnsignedShiftRight(Bit.And(EndClr, Bit.ShiftLeft(0xff, shift)), shift)
clr = clr + Bit.ShiftLeft(Max(0, Min(255, src + (target - src) * Fraction)), shift)
Next
Return clr
End Sub
Dim x As B4XView = MainForm.RootPane
For i = 0 To 100
x.Color = InterpolateColor(xui.Color_Green, xui.Color_Magenta, i / 100)
Sleep(30)
Next
cvs1.DrawCircle(i,j,3,fx.Colors.Blue,True,1)
Dim v As B4XView =Pane2
For i=0 To 350 Step 20
For j=0 To 500 Step 20
v.Color = InterpolateColor(xui.Color_red, xui.Color_blue, Rnd(0,100)/ 100)
cvs1.DrawCircle(i,j,5,v.Color,True,1)
Next
Next