1 #ifndef TERMOX_PAINTER_DYNAMIC_COLORS_HPP
2 #define TERMOX_PAINTER_DYNAMIC_COLORS_HPP
9 #include <termox/painter/color.hpp>
11 namespace ox::dynamic {
17 Rainbow(std::uint8_t saturation, std::uint8_t lightness);
24 std::uint16_t hue_ = 0;
25 std::uint8_t
const saturation_;
26 std::uint8_t
const lightness_;
30 [[nodiscard]]
auto rainbow(
31 Dynamic_color::Period_t period = std::chrono::milliseconds{40},
32 std::uint8_t saturation = 75,
49 unsigned const step_total_;
54 [[nodiscard]]
auto post_increment_step() -> int;
57 template <
typename Function>
60 using Function::Function;
63 [[nodiscard]]
auto operator()() ->
double
65 return -1. * Function::operator()() + 1.;
69 template <
typename Function>
72 using Function::Function;
75 [[nodiscard]]
auto operator()() ->
double
77 return std::pow(Function::operator()(), 2.);
81 template <
typename Function>
84 using Function::Function;
87 [[nodiscard]]
auto operator()() ->
double
89 return std::sqrt(Function::operator()());
106 Sine(
unsigned resolution);
125 using Invert::Invert;
131 Square(
unsigned resolution);
141 Random(
unsigned resolution);
148 std::mt19937 gen_{std::random_device{}()};
149 std::uniform_real_distribution<double> dist_{0., 1.};
154 template <
typename Shape>
160 Fade(HSL
const a, HSL
const b, Shape&& shape_fn)
162 distance_{find_distance(a, b)},
163 shape_fn_{std::forward<Shape>(shape_fn)}
167 [[nodiscard]]
auto operator()() -> True_color {
return this->step(); }
179 HSL_diff
const distance_;
184 [[nodiscard]]
auto step() -> HSL
186 double const ratio = shape_fn_();
188 double const h = base_.hue + distance_.hue_diff * ratio;
189 double const s = base_.saturation + distance_.saturation_diff * ratio;
190 double const l = base_.lightness + distance_.lightness_diff * ratio;
192 return narrow(h, s, l);
197 [[nodiscard]]
static auto find_distance(HSL
const a, HSL
const b)
200 return {b.hue - a.hue, b.saturation - a.saturation,
201 b.lightness - a.lightness};
205 [[nodiscard]]
static auto narrow(
double const hue,
206 double const saturation,
207 double const lightness) -> HSL
209 return {
static_cast<std::uint16_t
>(hue),
210 static_cast<std::uint8_t
>(saturation),
211 static_cast<std::uint8_t
>(lightness)};
216 template <
typename Shape>
217 [[nodiscard]]
auto fade(HSL
const a,
219 unsigned const resolution = 400,
220 Dynamic_color::Period_t
const interval =
221 std::chrono::milliseconds{40}) -> Dynamic_color
223 return {interval, Fade{a, b, Shape{resolution}}};
227 template <
typename Shape>
228 [[nodiscard]]
auto fade(True_color
const a,
230 unsigned const resolution = 400,
231 Dynamic_color::Period_t
const interval =
232 std::chrono::milliseconds{40}) -> Dynamic_color
234 return fade<Shape>(esc::rgb_to_hsl({a.red, a.green, a.blue}),
235 esc::rgb_to_hsl({b.red, b.green, b.blue}), resolution,
Definition: dynamic_colors.hpp:70
Definition: dynamic_colors.hpp:82
Dynamic_color type that fades between two HSL Colors.
Definition: dynamic_colors.hpp:155
Fade(HSL const a, HSL const b, Shape &&shape_fn)
Dynamic Color that cycles between a and b and back.
Definition: dynamic_colors.hpp:160
Definition: dynamic_colors.hpp:58
Definition: dynamic_colors.hpp:37
auto get_next_ratio() -> double
Finds the next ratio between from the current step and resolution.
Definition: dynamic_colors.cpp:47
Modulation_base(unsigned resolution, unsigned offset=0)
Resolution is the number of steps to complete a full cycle.
Definition: dynamic_colors.cpp:40
Dynamic_color type that cycles through every hue value in HSL color wheel.
Definition: dynamic_colors.hpp:14
Rainbow(std::uint8_t saturation, std::uint8_t lightness)
Creates a Rainbow Dynamic Color w/fixed saturation and lightness values.
Definition: dynamic_colors.cpp:24
auto operator()() -> True_color
Increment and return the next True_color.
Definition: dynamic_colors.cpp:28
Definition: dynamic_colors.hpp:138
Random(unsigned resolution)
Resolution is the number of steps to complete a full cycle.
Definition: dynamic_colors.cpp:85
auto operator()() -> double
Returns value in range [0.0, 1.0].
Definition: dynamic_colors.cpp:87
Definition: dynamic_colors.hpp:123
Definition: dynamic_colors.hpp:113
Sawtooth_up(unsigned resolution)
Resolution is the number of steps to complete a full cycle.
Definition: dynamic_colors.cpp:72
auto operator()() -> double
Returns value in range [0.0, 1.0].
Definition: dynamic_colors.cpp:76
Definition: dynamic_colors.hpp:103
auto operator()() -> double
Returns value in range [0.0, 1.0].
Definition: dynamic_colors.cpp:66
Sine(unsigned resolution)
Resolution is the number of steps to complete a full cycle.
Definition: dynamic_colors.cpp:64
Definition: dynamic_colors.hpp:128
Square(unsigned resolution)
Resolution is the number of steps to complete a full cycle.
Definition: dynamic_colors.cpp:78
auto operator()() -> double
Returns value in range [0.0, 1.0].
Definition: dynamic_colors.cpp:80
Definition: dynamic_colors.hpp:93
Triangle(unsigned resolution)
Resolution is the number of steps to complete a full cycle.
Definition: dynamic_colors.cpp:57
auto operator()() -> double
Returns value in range [0.0, 1.0].
Definition: dynamic_colors.cpp:59
Defines an animated color.
Definition: color.hpp:105