Gradient

References
public abstract class Gradient : IStorable
Base class for all Grasshopper gradients. Consider using GripGradient as a ready-made implementation.

Constructors

Gradient

#
protected Gradient(GradientMapping mapping)
Constructor.
mapping (GradientMapping)

Gradient

#
protected Gradient(IReader reader)
reader (IReader)

Properties

ApparentDomain

#
public (double lower, double upper) ApparentDomain { get; }
Gets the domain based on the Mapping of this gradient. Note that this domain may be decreasing.

Interaction

#
public virtual GripGradientInteraction Interaction { get; }
Gets a user interaction object based on this gradient. Not all gradient types will have interaction objects.

IntrinsicDomain

#
public abstract (double lower, double upper) IntrinsicDomain { get; }
Gets the interval containing the defined interior of this gradient. Note that this refers to the mathematics underlying the gradient, the ApparentDomain encodes the publicly facing domain of this gradient.

Mapping

#
public GradientMapping Mapping { get; }
Gets the mapping from sampling space to gradient space.

Methods

ColourAt

#
public bool ColourAt(double parameter, out Colour colour)
Gets the exact colour at the given parameter.
parameter (double)Evaluation parameter.
colour (out Colour)Colour result.
True if the parameter is a valid one.

ColourAt

#
public Color ColourAt(double parameter)
Gets the colour at the given parameter.
parameter (double)Evaluation parameter.
True if the parameter is a valid one.

ColourAtInternal

#
protected abstract Colour ColourAtInternal(double gradientParameter)
Sample the gradient at the given gradient parameter.
gradientParameter (double)Parameter.
Colour at parameter or null if gradient is undefined.

CreateTextureCache

#
protected virtual Gradient.GradientTexture CreateTextureCache()
Create a texture cache object for displaying this texture in the UI. The width of the texture bitmap ought to be decided by the callee.

Draw

#
public virtual void Draw(Graphics graphics, RectangleF rectangle, double lower, double upper)
Draw this gradient as a horizontal progression. This method is optimized for speed and may not necessarily yield the exact result.
graphics (Graphics)Graphics object to draw with.
rectangle (RectangleF)Rectangle to fill.
lower (double)Gradient parameter along left edge of rectangle.
upper (double)Gradient parameter along right edge of rectangle.

Draw

#
public void Draw(Graphics graphics, RectangleF rectangle)
Draw this gradient as a horizontal progression. This method is optimized for speed and may not necessarily yield the exact result.
graphics (Graphics)Graphics object to draw with.
rectangle (RectangleF)Rectangle to fill.

FromColour

#
public static Gradient FromColour(Colour colour)
Create a standard gradient from black (0.0) to white (1.0) via colour. The colour grip is placed at its luminance equivalent within the gradient.
colour (Colour)Colour on the interior of the gradient.

FromSolidColour

#
public static Gradient FromSolidColour(Colour colour)
Create a gradient with a single colour.
colour (Colour)

IsConstant

#
public bool IsConstant(out Colour colour)
Tests whether this gradient has a zero-length domain and whether the colours on either side are identical.
colour (out Colour)Colour inside domain.
True if gradient only has a single colour.

Remap

#
public Gradient Remap(double t0, double t1)
Create a new gradient which is similar to this gradient but remapped to a different interval.
t0 (double)New gradient lower limit.
t1 (double)New gradient upper limit.
Mapped gradient.

Remap

#
public abstract Gradient Remap(GradientMapping newMapping)
Create a new gradient which is similar to this gradient but remapped to a different interval.
newMapping (GradientMapping)
Mapped gradient.

RemapAutomatic

#
public Gradient RemapAutomatic(double lower, double upper)
Remap this gradient to a new domain if the mapping has automatic lower or upper bounds.
lower (double)
upper (double)

Store

#
public virtual void Store(IWriter writer)
Serialisation method.
writer (IWriter)
Store

ToBitmap

#
public Bitmap ToBitmap(int width, int height, double lower, double upper)
Render this gradient to a bitmap using exact per-pixel colours.
width (int)Bitmap width.
height (int)Bitmap height.
lower (double)Gradient parameter at left edge of bitmap.
upper (double)Gradient parameter at right edge of bitmap.
Bitmap.

ToBitmap

#
public Bitmap ToBitmap(int width, int height)
Render this gradient to a bitmap.
width (int)Bitmap width.
height (int)Bitmap height.
Bitmap.

TryParse

#
public static Result<Gradient> TryParse(string text)
Try and pase a gradient from text. This will both find standard and custom gradients by name, remapped standard or custom gradients and grip gradients defined from scratch.
text (string)

WithAutomaticLimits

#
public Gradient WithAutomaticLimits(bool autoLower = true, bool autoUpper = true)
Adjust the automatic bounds flags for this gradient.
autoLower (bool = true)
autoUpper (bool = true)

Operators