OpenStructure
Data Structures | Public Types | Public Member Functions | Static Public Member Functions
Gradient Class Reference

#include <gradient.hh>

Data Structures

struct  Stop
 

Public Types

typedef std::vector< StopStopList
 

Public Member Functions

 Gradient ()
 
 Gradient (const String &name)
 
Color GetColorAt (float t) const
 
void SetColorAt (float t, const Color &color)
 
void GradientToInfo (info::InfoGroup &group) const
 
StopList GetStops () const
 
void SetHSVMode (bool m)
 
bool GetHSVMode () const
 

Static Public Member Functions

static gfx::Gradient GradientFromInfo (const info::InfoGroup &group)
 

Detailed Description

color gradient

Gradients map a scalar value in the range of 0 to 1 to a color. The gradient consists of zero or more color stops. These stop points define the output of GetColorAt(). New stops can be added with SetColorAt().

Usually, the gradient operates in RGB colorspace, which means a linear interpolation of each color component between stops. As an alternative, interpolation can also be done in HSV colorspace, by setting HSV mode to true with SetHSVMode(). However, carefully using HSV colorspace will yield better results, if some potential caveats are taken into consideration. The best example is a simple gradient from red to blue. The half-point in RGB colorspace is (0.5,0.0,0.5), so a darkish purple. Converting to HSV one can see that the saturation is at 50%, which is unfortunate. Using hsv mode can circument this issue, but in the above example, naively using hsv mode will give green at the half-point and not purple. Why? Because red translates to HSV(0,1,1) and blue to HSV(2/3,1,1), which at the half-point is HSV(1/3,1,1), or green. To interpolate on the hue in the other direction, use HSV and unwrapped hue values, e.g. [HSV(0.0,1,1),HSV(-1/3,1,1)] or [HSV(1,1,1),HSV(2/3,1,1)] - both of these will give a half-point or a nice purple with full saturation

See also
Gradient Example

Definition at line 59 of file gradient.hh.

Member Typedef Documentation

◆ StopList

typedef std::vector<Stop> StopList

Definition at line 83 of file gradient.hh.

Constructor & Destructor Documentation

◆ Gradient() [1/2]

Gradient ( )

In python, the gradient can also be initialize with a dictionary, mapping stops to either float triplets or gfx.Color objects

◆ Gradient() [2/2]

Gradient ( const String name)

initialize with a pre-define gradient name

Member Function Documentation

◆ GetColorAt()

Color GetColorAt ( float  t) const

get color

◆ GetHSVMode()

bool GetHSVMode ( ) const
inline

return the HSV interpolation mode flag

Definition at line 119 of file gradient.hh.

◆ GetStops()

StopList GetStops ( ) const

get list of color stops

◆ GradientFromInfo()

static gfx::Gradient GradientFromInfo ( const info::InfoGroup group)
static

create gradient from info

◆ GradientToInfo()

void GradientToInfo ( info::InfoGroup group) const

convert gradient to info

◆ SetColorAt()

void SetColorAt ( float  t,
const Color color 
)

set color

Parameters
tis the position where the new stop should be inserted
coloris the color of the stop

◆ SetHSVMode()

void SetHSVMode ( bool  m)
inline

turn HSV interpolation mode on or off

Definition at line 117 of file gradient.hh.


The documentation for this class was generated from the following file: