Color Gradient

class zhetapi::image::Gradient

A parametrized gradient class, from color A to B, and operating on a range a to b. A value c in the range \([a, b]\) will equate to a color appropriately in between A and B.

This class can essentially be thought of as a slider from color A to color B (with the slider value ranging from a to b).

The reason we do not restrict a and b to 0 and 1 is to allow for more meaningful values. For example, if the gradient is intended to represent heat, the Celcius measurements in \([0, 100]\) are more meaningful to use than are the values in \([0, 1]\).

Public Functions

Gradient(const Color&, const Color&, long double = 0, long double = 1)

Gradient constructor from two colors and two values.

Parameters
  • A – the starting color.

  • B – the ending color.

  • start – the start value (corresponding to the starting color).

  • end – the ending value (corresponding to th ending color).

Gradient(const std::string&, const std::string&, long double = 0, long double = 1)

Gradient constructor from two colors and two values.

Parameters
  • A – the starting color as a hex string.

  • B – the ending color as a hex string.

  • start – the start value (corresponding to the starting color).

  • end – the ending value (corresponding to th ending color).

Color get(long double)

Retrieves the Color corresponding to the passed value. Throws bad_value if the passed value is out of bounds.

Parameters

x – the gradient value.

Color operator()(long double)

Retrieves the Color corresponding to the passed value. Does not check the bounds of the passed value.

Parameters

x – the gradient value.

class bad_value : public runtime_error

Thrown in the get method if the passed value is out of the bounds of the starting and ending values of the Gradient’s scale.