Skip to content

Latest commit

 

History

History
56 lines (43 loc) · 2.08 KB

fade.md

File metadata and controls

56 lines (43 loc) · 2.08 KB

Fade Dynamic Color

The fade dynamic color is provided via the fade(...) free function in the termox/painter/dynamic_colors.hpp header. The resulting Dynamic_color will fade between two given color values.

template <typename Shape>
auto fade(True_color a,
          True_color b,
          unsigned resolution              = 400,
          Dynamic_color::Period_t interval = std::chrono::milliseconds{40}) -> Dynamic_color;

The Shape template parameter is the modulator that defines how the two numbers will be interpolated between, there are many pre-built Shapes, such as Sine, Sawtooth_up, etc... as well as Shape modifiers like Invert, and Convex that take a Shape type as template parameter and distort the output in some way.

The Shape parameter will provide an operator() that outputs a ratio[0, 1] of where between the two colors a and b the fade is currently at.

resolution is the number of steps the Shape will increment through before repeating itself, a new step is calculated every interval.

Shapes

  • Triangle
  • Sine
  • Sawtooth_up
  • Sawtooth_down
  • Square
  • Random

Shape Modifiers

  • Invert
  • Concave
  • Convex

Creating New Shapes

To create a new Shape type, you'll need to create a type with a public auto operator() -> double overload that will be interpreted as the ratio between the two colors that are being faded between. This ratio is applied to the difference of each of the Hue, Saturation, and Lightness between the two colors. The call operator will be called on each step of the animation.

It will also need a constructor that takes an unsigned resolution parameter.

There is a helper base class called Modulation_base that can be inherited from. This provides a Modulation_base::get_next_ratio() -> double helper method that returns the ratio of the current step count and the resolution. Each call to this method will increment the current step, wrapping to zero at the provided resolution. This ratio is helpful if the Shape is cyclical and your Shape depends on some mathematical function that depends on this ratio.