Click or drag to resize

GH_GraphicsUtilBlendInteger Method

Calculates a linear blend between two extremes. Although the inputs are unlimited integers, the output is an integer in the byte range (0-255).

Namespace:  Grasshopper.GUI
Assembly:  Grasshopper (in Grasshopper.dll)
Syntax
public static int BlendInteger(
	double t0,
	double t1,
	int a0,
	int a1,
	double t
)

Parameters

t0
Type: SystemDouble
Value of first extreme.
t1
Type: SystemDouble
Value of second extreme.
a0
Type: SystemInt32
Integer value at first extreme.
a1
Type: SystemInt32
Integer value at second extreme.
t
Type: SystemDouble
Interpolation parameter.

Return Value

Type: Int32
Interpolated value.
Examples
This function is useful when you need to link colour alpha amounts to zoom levels:
VB
Sub DrawZoomAwareCircle(ByVal G As Graphics, _
                        ByVal center As PointF, _
                        ByVal radius As Single, _
                        ByVal fill As Color)
  'Find the zoom level of the Graphics transform.
  Dim zoom As Single = G.Transform.Elements(0)

  'Abort if zoom less than 25%
  If (zoom < 0.25f) Then Return

  'Blend the alpha channel byte between 25% and 95% zoom.
  Dim alpha As Int32 = GH_GraphicsUtil.BlendByte(0.25, 0.95, 0, 255, zoom)
  G.FillEllipse(center.X - radius, center.Y - radius, _
                2.0f * radius, 2.0f * radius, _
                New SolidBrush(Color.FromARGB(alpha, fill)))
End Sub
See Also