Skip to content

Commit

Permalink
simplify Gradient<>
Browse files Browse the repository at this point in the history
  • Loading branch information
profezzorn committed Dec 15, 2023
1 parent 7f9abda commit ed38ec6
Showing 1 changed file with 2 additions and 49 deletions.
51 changes: 2 additions & 49 deletions styles/gradient.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,8 @@
// Gradient, color A at base, B at tip.
// Any number of colors can be put together into a gradient.

class BlaseBase;
#include "../functions/ramp.h"

template<class... A>
class GradientHelper {};

template<class A>
class GradientHelper<A> {
public:
static const size_t size = 0;
void run(BladeBase* blade) { a_.run(blade); }
PONUA A a_;
auto get(int led, int partition) -> decltype(a_.getColor(led)) {
return a_.getColor(led);
}
};

template<class A, class B, class... C>
class GradientHelper<A, B, C...> {
public:
static const size_t size = GradientHelper<B, C...>::size + 1;
void run(BladeBase* blade) {
a_.run(blade);
b_.run(blade);
}
PONUA A a_;
PONUA GradientHelper<B, C...> b_;
auto get(int led, int partition) -> decltype(MixColors(a_.getColor(0), b_.get(0,0), 1, 1)) {
if (partition <= 16384) {
return MixColors(a_.getColor(led), b_.a_.getColor(led), partition, 14);
} else {
return b_.get(led, partition - 16384);
}
}
};

template<class... COLOR>
class Gradient {
public:
void run(BladeBase* blade) {
colors_.run(blade);
mul_ = (GradientHelper<COLOR...>::size << 14) / (blade->num_leds() - 1);
}
private:
PONUA GradientHelper<COLOR...> colors_;
int mul_;
public:
auto getColor(int led) -> decltype(colors_.get(led, led * mul_)) {
return colors_.get(led, led * mul_);
}
};
template<class... COLORS> using Gradient = Mix<RampF, COLORS...>;

#endif

0 comments on commit ed38ec6

Please sign in to comment.