2

Hi I have the following snippet in java I need to convert to vb.net

float position =(value - startValue) / (middleValue - startValue);
Color4f result = new Color4f();
result.interpolate(startColor, middleColor, position);
return result;

Does anyone know how I can do the color4f.interpolate in vb.net? Have found an article here for c# which use lambda operators but I have no idea what they mean and how to implement them in vb.net

Stackoverflow link to c# article (Color Interpolation Between 3 Colors in .NET)

And what is the best alternative for color4f in vb.net?

Thanks.

Community
  • 1
  • 1
benst
  • 553
  • 2
  • 12
  • 32
  • Not sure why you would need lambda for that, sounds like very basic math: [How do I interpolate colors](http://www.gamedev.net/topic/537295-how-do-i-interpolate-colors/) with this: `c = (1 - t) * c0 + t * c1` – Victor Zakharov Nov 27 '12 at 16:20

1 Answers1

0

This function seems to work more or less:

Public Function interPolateColor(ByVal firstcolor As Color, ByVal secondcolor As Color, ByVal alpha As Double) As Color
    Dim R As Double = ((1 - alpha) * Convert.ToInt32(firstcolor.R)) + (alpha * Convert.ToInt32(secondcolor.R))
    Dim B As Double = ((1 - alpha) * Convert.ToInt32(firstcolor.B)) + (alpha * Convert.ToInt32(secondcolor.B))
    Dim G As Double = ((1 - alpha) * Convert.ToInt32(firstcolor.G)) + (alpha * Convert.ToInt32(secondcolor.G))
    Dim A As Byte = 255
    Return Color.FromArgb(A, Convert.ToByte(R), Convert.ToByte(G), Convert.ToByte(B))
End Function
benst
  • 553
  • 2
  • 12
  • 32