Added effect sines.

This commit is contained in:
Fabian Schlenz 2019-09-25 06:25:16 +02:00
parent 96e144f96b
commit b5c99c320b
2 changed files with 80 additions and 0 deletions

32
include/effect_sines.h Normal file
View File

@ -0,0 +1,32 @@
#pragma once
#include "prototypes.h"
#include "functions.h"
#include "Effect.h"
class SinesEffectSinus {
private:
uint8_t _value;
uint8_t _frequency;
uint8_t _amplitude;
uint8_t _x;
uint8_t _step;
Window* _window;
CRGB _color;
public:
SinesEffectSinus(Window* w);
void loop();
};
class SinesEffect : public Effect {
private:
SinesEffectSinus* _sinus[EFFECT_SINES_COUNT];
uint8_t _step = 0;
public:
SinesEffect();
~SinesEffect();
boolean supports_window = true;
boolean can_be_shown_with_clock();
void loop();
};

48
src/effect_sines.cpp Normal file
View File

@ -0,0 +1,48 @@
#include "effect_sines.h"
SinesEffectSinus::SinesEffectSinus(Window* w) {
_window = w;
_frequency = random8(40)+8;
_amplitude = random(5)+2;
_x = random8(_window->width);
_step = 0;
_color = CHSV(random8(), 255, 255);
}
void SinesEffectSinus::loop() {
_value += _frequency;
if ((_value == 0 || _value==128) && random8(16)==0) {
int8_t sign = _value == 0 ? -1 : +1;
if (_x > 200) sign = -1;
else if (_x >= _window->width) sign = 1;
_amplitude = random(3)+2;
_frequency = random8(40)+8;
_color = CHSV(random8(), 255, 255);
_x = _x - sign*_amplitude;
}
uint8_t x = _x + ((sin8(_value) - 128) * _amplitude / 128);
_window->setPixel(x, 0, &_color);
}
SinesEffect::SinesEffect() {
for (int i=0; i<EFFECT_SINES_COUNT; i++) {
_sinus[i] = new SinesEffectSinus(window);
}
}
SinesEffect::~SinesEffect() {
for (int i=0; i<EFFECT_SINES_COUNT; i++) { delete _sinus[i]; }
}
boolean SinesEffect::can_be_shown_with_clock() {
return true;
}
void SinesEffect::loop() {
// do stuff
if (_step++ % 4) return; // Skip 3 out of 4 steps.
window->shift_down_and_blur();
for (int i=0; i<EFFECT_SINES_COUNT; i++) {
_sinus[i]->loop();
}
}