If the code hasn't been touched in this long, its probably release-worthy.

This commit is contained in:
2022-06-11 11:02:27 +02:00
parent 0c9eb831dd
commit d14fa7fde1
59 changed files with 1610 additions and 842 deletions

View File

@@ -1,75 +1,74 @@
#include "../Figments/Figments.h"
#include "../sprites/Chime.h"
#include "../sprites/Blob.h"
#include "Chimes.h"
#include "../Static.h"
#define CHIME_LENGTH 23
#define CHIME_COUNT 4
#define BLOB_COUNT 10
ChimesAnimation::ChimesAnimation() : Figment("Chimes", Task::Stopped) {
}
class ChimesAnimation: public Figment {
public:
ChimesAnimation(Task::State initialState) : Figment("Chimes", initialState) {
m_chimes.forEach([](Chime<CHIME_LENGTH> &chime) {
chime.setPos(random(Chime<CHIME_LENGTH>::Length * 5));
chime.setHue(random(255));
chime.setSpeed(random(90) + 138);
chime.setBrightness(200);
chime.setOffset(random(1024));
});
m_blobs.forEach([](Blob &blob) {
blob.setPos(random(255));
blob.setHue(random(255));
blob.setBrightness(random(255));
if (random(255) % 2) {
blob.setVelocity(-1);
} else {
blob.setVelocity(1);
void ChimesAnimation::randomize() {
m_isRandom = true;
m_chimes.forEach([](Chime<CHIME_LENGTH> &chime) {
chime.setPos(random(Chime<CHIME_LENGTH>::Length * 5));
chime.setHue(random(255));
chime.setSpeed(random(90) + 138);
chime.setBrightness(200);
chime.setOffset(random(1024));
});
m_blobs.forEach([](Blob &blob) {
blob.setPos(random(255));
blob.setHue(random(255));
blob.setBrightness(random(255));
if (random(255) % 2) {
blob.setVelocity(-1);
} else {
blob.setVelocity(1);
}
});
}
void ChimesAnimation::handleEvent(const InputEvent& evt) {
if (evt.intent == InputEvent::UserInput) {
if (strcmp(evt.asString(), "blobs") == 0) {
m_blobs.toggle();
} else if (strcmp(evt.asString(), "chimes") == 0) {
m_chimes.toggle();
}
});
} else if (evt.intent == InputEvent::SetColor) {
m_flashBrightness.set(255, 0);
m_flashColor = evt.asRGB();
uint8_t flashHue = rgb2hsv_approximate(m_flashColor).hue;
m_blobs.forEach([&](Blob& blob) {
blob.setHue(flashHue);
});
m_chimes.forEach([&](Chime<CHIME_LENGTH>& chime) {
chime.setHue(flashHue);
});
} else if (evt.intent == InputEvent::Beat) {
m_isRandom = false;
}
}
void handleEvent(const InputEvent& evt) override {
if (evt.intent == InputEvent::UserInput) {
if (strcmp(evt.asString(), "blobs") == 0) {
m_blobs.toggle();
} else if (strcmp(evt.asString(), "chimes") == 0) {
m_chimes.toggle();
}
} else if (evt.intent == InputEvent::SetColor) {
m_flashBrightness.set(255, 0);
m_flashColor = evt.asRGB();
uint8_t flashHue = rgb2hsv_approximate(m_flashColor).hue;
m_blobs.forEach([&](Blob& blob) {
blob.setHue(flashHue);
});
m_chimes.forEach([&](Chime<CHIME_LENGTH>& chime) {
chime.setHue(flashHue);
});
}
}
void ChimesAnimation::loop() {
if (!m_isRandom) {
randomize();
}
m_chimes.update();
m_blobs.update();
m_flashColor.update();
EVERY_N_MILLISECONDS(5) {
m_flashBrightness.update();
}
}
void loop() override {
m_chimes.update();
m_blobs.update();
m_flashColor.update();
EVERY_N_MILLISECONDS(5) {
m_flashBrightness.update();
}
}
void ChimesAnimation::render(Display* dpy) const {
m_chimes.render(dpy);
m_blobs.render(dpy);
Surface fullSurface(dpy, {0, 0}, {255, 0});
CRGB scaledColor = CRGB(m_flashColor).nscale8_video(std::max((uint8_t)10, ease8InOutCubic(m_flashBrightness)));
fullSurface.paintWith([&](CRGB& pixel) {
pixel = blend(scaledColor, pixel, 200);
//pixel = scaledColor;
});
}
void render(Display* dpy) const override {
m_chimes.render(dpy);
m_blobs.render(dpy);
Surface fullSurface(dpy, {0, 0}, {255, 0});
CRGB scaledColor = CRGB(m_flashColor).nscale8_video(std::max((uint8_t)10, ease8InOutCubic(m_flashBrightness)));
fullSurface.paintWith([&](CRGB& pixel) {
pixel = blend(scaledColor, pixel, 200);
//pixel = scaledColor;
});
}
SpriteList<Chime<CHIME_LENGTH>, CHIME_COUNT> m_chimes;
SpriteList<Blob, BLOB_COUNT> m_blobs;
AnimatedRGB m_flashColor;
AnimatedNumber m_flashBrightness;
};
STATIC_ALLOC(ChimesAnimation);
STATIC_TASK(ChimesAnimation);