List of all members | Public Member Functions | Related Functions
thor::ColorGradient Class Reference

Class to implement color gradients. More...

Public Member Functions

 ColorGradient ()
 Default constructor. More...
 
sf::Color & operator[] (float position)
 Inserts a color to the gradient. More...
 
sf::Color sampleColor (float position) const
 Interpolates a color in the gradient. More...
 

Related Functions

sf::Color blendColors (const sf::Color &firstColor, const sf::Color &secondColor, float interpolation)
 Blends the colors firstColor and secondColor, according to the given interpolation. More...
 

Detailed Description

Class to implement color gradients.

This class can represent color gradients and calculate the interpolated color at a given point. A color gradient consists of a list of positions (float values in [0, 1]) and corresponding colors. At each position, a color is sampled exactly; between two positions, a color is interpolated linearly.

Constructor & Destructor Documentation

thor::ColorGradient::ColorGradient ( )

Default constructor.

Creates an empty, invalid color gradient. To initialize it correctly, set the colors via ColorGradient::operator[].

Member Function Documentation

sf::Color& thor::ColorGradient::operator[] ( float  position)

Inserts a color to the gradient.

Parameters
positionNumber in [0, 1] that specifies a position in the gradient.

A map-like syntax allows you to specify the color at a certain position. For example, the following code creates a gradient consisting of two parts: Red to blue and blue to cyan. The first partial gradient (red to blue) takes up 80% of the whole gradient.

gradient[0.0f] = sf::Color::Red;
gradient[0.8f] = sf::Color::Blue;
gradient[1.0f] = sf::Color::Cyan;
Warning
At least both positions 0.f and 1.f must be set before a gradient is valid.
sf::Color thor::ColorGradient::sampleColor ( float  position) const

Interpolates a color in the gradient.

Parameters
positionNumber in [0, 1] that specifies a position in the gradient. When you pass 0 (1), the color at the very beginning (end) is returned.

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