Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexable strip specific code #1

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
782 changes: 782 additions & 0 deletions src/system/colors/animations.cpp

Large diffs are not rendered by default.

131 changes: 131 additions & 0 deletions src/system/colors/animations.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#ifndef ANIMATIONS_ANIMATIONS_H
#define ANIMATIONS_ANIMATIONS_H

#include "../utils/colorspace.h"
#include "../utils/strip.h"
#include "colors.h"

namespace animations {

/**
* \brief Fill the display with a color, with an optional cutoff value
* \param[in] color class that returns a color to display
* \param[in, out] strip The led strip to control
* \param[in] cutOff between 0 and 1, how much this gradient will fill the
* display before suddently cutting of
*/
void fill(const Color& color, LedStrip& strip, const float cutOff = 1);

/**
* \brief Do a wipe down followed by a wipe up animation
* \param[in] color class that returns a color to display
* \param[in] duration The duration of the animation, in milliseconds
* \param[in] fadeOut The animation fade speed (0: no fade)
* \param[in] restart If true, the animation will restart
* \param[in, out] strip The led strip to control
* \param[in] cutOff between 0 and 1, how much this gradient will fill the
* display before suddently cutting of \return True if the animation is finished
*/
bool dot_ping_pong(const Color& color, const uint32_t duration,
const uint8_t fadeOut, const bool restart, LedStrip& strip,
const float cutOff = 1);

/**
* \brief Do color pulse
* \param[in] color class that returns a color to display
* \param[in] durationPulseUp The duration of the color fill up animation, in
* milliseconds \param[in] durationPulseDown The duration of the pong animation,
* in milliseconds \param[in] restart If true, the animation will restart
* \param[in, out] strip The led strip to control
* \param[in] cutOff between 0 and 1, how much this color will fill the display
* before suddently cutting of \return True if the animation is finished
*/
bool color_pulse(const Color& color, const uint32_t durationPulseUp,
const uint32_t durationPulseDown, const bool restart,
LedStrip& strip, const float cutOff = 1);

/**
* \brief Fill the display from both side simultaneously
* \param[in] color class that returns a color to display
* \param[in] duration The duration of the animation, in milliseconds
* \param[in] restart If true, the animation will restart
* \param[in, out] strip The led strip to control
* \return True if the animation is finished
*/
bool double_side_fill(const Color& color, const uint32_t duration,
const bool restart, LedStrip& strip);

/**
* \brief Do police light animation
* \param[in] duration The duration of the animation, in milliseconds
* \param[in] restart If true, the animation will restart
* \param[in, out] strip The led strip to control
* \return True if the animation is finished
*/
bool police(const uint32_t duration, const bool restart, LedStrip& strip);

/**
* \brief Do a fade out of the colors currently displayed
* \param[in] duration The duration of the animation, in milliseconds
* \param[in] restart If true, the animation will restart
* \param[in, out] strip The led strip to control
* \return True if the animation is finished
*/
bool fade_out(const uint32_t duration, const bool restart, LedStrip& strip);

/**
* \brief Do a fade in of a color
* \param[in] color class that returns a color to display
* \param[in] duration The duration of the animation, in milliseconds
* \param[in] restart If true, the animation will restart
* \param[in, out] strip The led strip to contro
* \param[in] firstCutOff between 0 and 1, how much this color will fill the
* display before suddently cutting of \param[in] secondCutOff between 0 and 1,
* how much this color will fill the display before suddently cutting of \return
* True if the animation is finished
*/
bool fade_in(const Color& color, const uint32_t duration, const bool restart,
LedStrip& strip, const float firstCutOff = 0.0,
const float secondCutOff = 1.0);

/**
* Fire animation
* https://editor.soulmatelights.com/gallery/234-fire
*/
void fire(const uint8_t scalex, const uint8_t scaley, const uint8_t speed,
const palette_t& palette, LedStrip& strip);

void random_noise(const palette_t& palette, LedStrip& strip, const bool restart,
const bool isColorLoop, const uint16_t scale);

void candle(const palette_t& palette, LedStrip& strip);

/**
* \brief Display some sinewave of colors, going back and forth
* \param[in] moder: add some random noise
*/
void phases(const bool moder, const uint8_t speed, const palette_t& palette,
LedStrip& strip);
void mode_2DPolarLights(const uint8_t scale, const uint8_t speed,
const palette_t& palette, const bool reset,
LedStrip& strip);
void mode_2DDrift(const uint8_t intensity, const uint8_t speed,
const palette_t& palette, LedStrip& strip);
void hiphotic(const uint8_t speed, LedStrip& strip);

void mode_2Ddistortionwaves(const uint8_t scale, const uint8_t speed,
LedStrip& strip);

void mode_lake(const uint8_t speed, const palette_t& palette, LedStrip& strip);

// Adjustable sinewave. By Andrew Tuline
void mode_sinewave(const uint8_t speed, const uint8_t intensity,
const palette_t& palette, LedStrip& strip);

void running_base(bool saw, bool dual, const uint8_t speed,
const uint8_t intensity, const palette_t& palette,
LedStrip& strip);

}; // namespace animations

#endif
80 changes: 80 additions & 0 deletions src/system/colors/colors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "colors.h"

#include <cmath>
#include <cstdint>

#include "../utils/colorspace.h"
#include "../utils/constants.h"
#include "../utils/strip.h"
#include "../utils/utils.h"
#include "palettes.h"

uint32_t GenerateSolidColor::get_color_internal(const uint16_t index,
const uint16_t maxIndex) const {
return _color;
}

uint32_t GenerateRainbowColor::get_color_internal(
const uint16_t index, const uint16_t maxIndex) const {
const uint16_t hue = map(constrain(index, 0, maxIndex), 0, maxIndex, 0, 360);
return utils::hue_to_rgb_sinus(hue);
}

uint32_t GenerateGradientColor::get_color_internal(
const uint16_t index, const uint16_t maxIndex) const {
return utils::get_gradient(_colorStart, _colorEnd, index / (float)maxIndex);
}

uint32_t GenerateRoundColor::get_color_internal(const uint16_t index,
const uint16_t maxIndex) const {
const double segmentsPerTurns = 3.1;
const double modulo = std::fmod(index, segmentsPerTurns) / segmentsPerTurns;
return utils::hue_to_rgb_sinus(modulo * 360.0);
}

uint32_t GenerateRainbowSwirl::get_color_internal(
const uint16_t index, const uint16_t maxIndex) const {
const uint16_t pixelHue = _firstPixelHue + (index * UINT16_MAX / maxIndex);
return utils::hue_to_rgb_sinus(map(pixelHue, 0, UINT16_MAX, 0, 360));
}

uint32_t GeneratePaletteStep::get_color_internal(
const uint16_t index, const uint16_t maxIndex) const {
return get_color_from_palette(_index, *_paletteRef);
}

uint32_t GeneratePaletteIndexed::get_color_internal(
const uint16_t index, const uint16_t maxIndex) const {
return get_color_from_palette(_index, *_paletteRef);
}

uint32_t GenerateRainbowPulse::get_color_internal(
const uint16_t index, const uint16_t maxIndex) const {
return LedStrip::ColorHSV(_currentPixelHue);
}

uint32_t GenerateRainbowIndex::get_color_internal(
const uint16_t index, const uint16_t maxIndex) const {
return LedStrip::ColorHSV(_currentPixelHue);
}

uint32_t GeneratePastelPulse::get_color_internal(
const uint16_t index, const uint16_t maxIndex) const {
const double hue = double(_currentPixelHue) / double(UINT16_MAX) * 360.0;

// using OKLCH will create softer colors
auto res = utils::ColorSpace::OKLCH(0.752, 0.126, hue);
return res.get_rgb().color;
}

GenerateRandomColor::GenerateRandomColor()
: _color(utils::get_random_color()) {}

void GenerateRandomColor::internal_update(const uint32_t deltaTimeMilli) {
_color = utils::get_random_color();
}

void GenerateComplementaryColor::internal_update(
const uint32_t deltaTimeMilli) {
_color = utils::get_random_complementary_color(_color, _randomVariation);
};
Loading