![]() |
Class to implement color gradients. More...
Public Member Functions | |
ColorGradient () | |
Default constructor. | |
sf::Color & | operator[] (float position) |
Inserts a color to the gradient. | |
sf::Color | sampleColor (float position) const |
Interpolates a color in the gradient. | |
Related Functions | |
(Note that these are not member functions.) | |
sf::Color | thor::blendColors (const sf::Color &firstColor, const sf::Color &secondColor, float interpolation) |
Blends the colors firstColor and secondColor, according to the given interpolation. |
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.
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.
thor::ColorGradient gradient; gradient[0.0f] = sf::Color::Red; gradient[0.8f] = sf::Color::Blue; gradient[1.0f] = sf::Color::Cyan;
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. |