Gradient Class Reference

color gradient More...

#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

typedef std::vector<Stop> StopList

Definition at line 83 of file gradient.hh.


Constructor & Destructor Documentation

Gradient (  ) 

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

Gradient ( const String name  ) 

initialize with a pre-define gradient name


Member Function Documentation

Color GetColorAt ( float  t  )  const

get color

bool GetHSVMode (  )  const [inline]

return the HSV interpolation mode flag

Definition at line 119 of file gradient.hh.

StopList GetStops (  )  const

get list of color stops

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

create gradient from info

void GradientToInfo ( info::InfoGroup group  )  const

convert gradient to info

void SetColorAt ( float  t,
const Color color 
)

set color

Parameters:
t is the position where the new stop should be inserted
color is the color of the stop
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:
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 20 Jun 2016 for OpenStructure by  doxygen 1.6.1