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... | |
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.
thor::ColorGradient::ColorGradient | ( | ) |
Default constructor.
Creates an empty, invalid color gradient. To initialize it correctly, set the colors via ColorGradient::operator[].
sf::Color& thor::ColorGradient::operator[] | ( | float | position | ) |
Inserts a color to the gradient.
position | Number 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.
sf::Color thor::ColorGradient::sampleColor | ( | float | position | ) | const |
Interpolates a color in the gradient.
position | Number in [0, 1] that specifies a position in the gradient. When you pass 0 (1), the color at the very beginning (end) is returned. |