wip commit
This commit is contained in:
46
src/animations/Cloudy.cpp
Normal file
46
src/animations/Cloudy.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "Cloudy.h"
|
||||
#include "../Static.h"
|
||||
|
||||
Cloudy::Cloudy()
|
||||
: Figment("Cloudy")
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Cloudy::loop()
|
||||
{
|
||||
m_noiseOffset += 1;
|
||||
EVERY_N_MILLISECONDS(60) {
|
||||
m_hue.update(1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Cloudy::render(Display* dpy) const
|
||||
{
|
||||
Surface sfc = Surface(dpy, {0, 0}, {255, 128});
|
||||
uint8_t noiseY = sin8(m_noiseOffset % 255);
|
||||
uint8_t noiseX = cos8(m_noiseOffset % 255);
|
||||
sfc.paintShader([=](CRGB& pixel, const VirtualCoordinates& coords, const PhysicalCoordinates, const VirtualCoordinates& surfaceCoords) {
|
||||
uint8_t brightness = inoise8(noiseX + surfaceCoords.x, noiseY + surfaceCoords.y);
|
||||
uint8_t saturation = inoise8(noiseY + surfaceCoords.y, noiseX + surfaceCoords.x);
|
||||
nblend(pixel, CHSV(m_hue, scale8(saturation, 128), brightness), 255 - surfaceCoords.y);
|
||||
});
|
||||
Surface horizon = Surface(dpy, {0, 64}, {255, 128});
|
||||
horizon.paintShader([=](CRGB& pixel, const VirtualCoordinates& coords, const PhysicalCoordinates, const VirtualCoordinates& surfaceCoords) {
|
||||
uint8_t brightness = inoise8(noiseX + surfaceCoords.x, noiseY + surfaceCoords.y);
|
||||
uint8_t saturation = inoise8(noiseY + surfaceCoords.y, noiseX + surfaceCoords.x);
|
||||
nblend(pixel, CHSV(m_hue + (saturation % 45), std::max((uint8_t)64, (uint8_t)saturation), brightness), surfaceCoords.y);
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
Cloudy::handleEvent(const InputEvent& evt) {
|
||||
if (evt.intent == InputEvent::SetColor) {
|
||||
CHSV next = rgb2hsv_approximate(evt.asRGB());
|
||||
m_hue.set(next.h);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC_ALLOC(Cloudy);
|
||||
STATIC_TASK(Cloudy);
|
13
src/animations/Cloudy.h
Normal file
13
src/animations/Cloudy.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include <Figments.h>
|
||||
|
||||
class Cloudy: public Figment {
|
||||
private:
|
||||
uint16_t m_noiseOffset;
|
||||
AnimatedNumber m_hue;
|
||||
public:
|
||||
Cloudy();
|
||||
void render(Display* dpy) const override;
|
||||
void loop() override;
|
||||
void handleEvent(const InputEvent& evt) override;
|
||||
};
|
@@ -8,11 +8,13 @@ RainAnimation::RainAnimation() : Figment("Rain")
|
||||
void
|
||||
RainAnimation::render(Display* dpy) const
|
||||
{
|
||||
Surface sfc = Surface(dpy, {0, 0}, {255, 255});
|
||||
Surface ground = Surface(dpy, {0, 64}, {255, 255});
|
||||
uint8_t noiseY = sin8(m_noiseOffset % 255);
|
||||
uint8_t noiseX = cos8(m_noiseOffset % 255);
|
||||
sfc.paintShader([=](CRGB& pixel, const VirtualCoordinates& coords, const PhysicalCoordinates, const VirtualCoordinates& surfaceCoords) {
|
||||
pixel = CHSV(m_hue, inoise8(noiseX + coords.x, coords.y), inoise8(m_noiseOffset + coords.x, noiseY + coords.y));
|
||||
ground.paintShader([=](CRGB& pixel, const VirtualCoordinates& coords, const PhysicalCoordinates, const VirtualCoordinates& surfaceCoords) {
|
||||
uint8_t brightness = inoise8(noiseX + surfaceCoords.x, noiseY + surfaceCoords.y);
|
||||
uint8_t saturation = inoise8(noiseY + surfaceCoords.y, noiseX + surfaceCoords.x);
|
||||
nblend(pixel, CHSV(m_hue, saturation, brightness), 255 - surfaceCoords.y);
|
||||
});
|
||||
m_drops.render(dpy);
|
||||
}
|
||||
@@ -20,7 +22,7 @@ RainAnimation::render(Display* dpy) const
|
||||
void
|
||||
RainAnimation::loop()
|
||||
{
|
||||
EVERY_N_MILLISECONDS(250) {
|
||||
EVERY_N_MILLISECONDS(120) {
|
||||
m_drops.update();
|
||||
}
|
||||
EVERY_N_MILLISECONDS(60) {
|
||||
|
@@ -4,7 +4,7 @@
|
||||
class RainAnimation: public Figment {
|
||||
private:
|
||||
struct Raindrop {
|
||||
int size = 20;
|
||||
int size = 10;
|
||||
int x = random(255);
|
||||
int y = random(255);
|
||||
CHSV fg{180, 255, 255};
|
||||
|
@@ -47,22 +47,20 @@ void SolidAnimation::loop() {
|
||||
});
|
||||
m_blobs.update();
|
||||
}
|
||||
m_noiseOffset += 1;
|
||||
}
|
||||
|
||||
void SolidAnimation::render(Display* dpy) const {
|
||||
CRGB color(m_red.value(), m_green.value(), m_blue.value());
|
||||
CRGB scaledPrev = m_prevColor;
|
||||
scaledPrev = color.nscale8(30);
|
||||
uint8_t frame = ease8InOutApprox(m_changePct);
|
||||
if (F_LIKELY(frame == 255)) {
|
||||
Surface(dpy, {0, 0}, {255, 255}) = color.nscale8(10);
|
||||
} else {
|
||||
uint8_t cutoff = (frame / 2);
|
||||
uint8_t rotation = m_horizontal ? 0 : 128;
|
||||
Surface(dpy, {0, 0}, {128 - cutoff, 255}, rotation) = scaledPrev;
|
||||
Surface(dpy, {128 - cutoff, 0}, {128 + cutoff, 255}, rotation) = scaledPrev;
|
||||
Surface(dpy, {128 + cutoff, 0}, {255, 255}, rotation) = scaledPrev;
|
||||
}
|
||||
Surface sfc = Surface(dpy, {0, 0}, {255, 255});
|
||||
uint8_t noiseY = sin8(m_noiseOffset % 255);
|
||||
uint8_t noiseX = cos8(m_noiseOffset % 255);
|
||||
CHSV color(rgb2hsv_approximate(CRGB(m_red, m_green, m_blue)));
|
||||
|
||||
sfc.paintShader([=](CRGB& pixel, const VirtualCoordinates& coords, const PhysicalCoordinates, const VirtualCoordinates& surfaceCoords) {
|
||||
uint8_t brightness = inoise8(noiseX + surfaceCoords.x, noiseY + surfaceCoords.y);
|
||||
uint8_t saturation = inoise8(noiseY + surfaceCoords.y, noiseX + surfaceCoords.x);
|
||||
nblend(pixel, CHSV(color.h, std::max((uint8_t)128, saturation), scale8(color.v, brightness)), 128);
|
||||
});
|
||||
m_blobs.render(dpy);
|
||||
}
|
||||
STATIC_ALLOC(SolidAnimation);
|
||||
|
@@ -5,6 +5,7 @@
|
||||
class SolidAnimation: public Figment {
|
||||
private:
|
||||
AnimatedNumber m_red, m_green, m_blue, m_changePct;
|
||||
uint16_t m_noiseOffset;
|
||||
CRGB m_curColor;
|
||||
CRGB m_prevColor;
|
||||
static constexpr int blobCount = 20;
|
||||
|
@@ -5,27 +5,106 @@
|
||||
void
|
||||
TestAnimation::loop()
|
||||
{
|
||||
m_x += 1;
|
||||
m_y += 1;
|
||||
m_x += 1;
|
||||
m_y += 1;
|
||||
m_hue += 1;
|
||||
}
|
||||
|
||||
void
|
||||
TestAnimation::handleEvent(const InputEvent& evt)
|
||||
{
|
||||
if (evt.intent == InputEvent::SetColor) {
|
||||
m_color = evt.asRGB();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TestAnimation::render(Display* dpy) const
|
||||
{
|
||||
for(unsigned int i = 0; i < dpy->pixelCount(); i++) {
|
||||
dpy->pixelAt(i) = CRGB{255, 255, 255};
|
||||
CRGB drawColor = blend(m_color, CHSV(m_hue, 255, 255), 128);
|
||||
if (m_mode == Raw) {
|
||||
for(unsigned int i = 0; i < dpy->pixelCount(); i++) {
|
||||
dpy->pixelAt(i) = drawColor;
|
||||
}
|
||||
} else if (m_mode == Top) {
|
||||
Surface{dpy, {0, 0}, {255, 0}} = drawColor;
|
||||
} else if (m_mode == Left) {
|
||||
Surface{dpy, {0, 0}, {0, 255}} = drawColor;
|
||||
} else if (m_mode == Right) {
|
||||
Surface{dpy, {255, 0}, {255, 255}} = drawColor;
|
||||
} else if (m_mode == Bottom) {
|
||||
Surface{dpy, {0, 255}, {255, 255}} = drawColor;
|
||||
} else if (m_mode == Outline) {
|
||||
// Draw red line on top row
|
||||
Surface{dpy, {0, 0}, {255, 0}} = CRGB{255, 0, 0};
|
||||
// Green line on first column
|
||||
Surface{dpy, {0, 0}, {0, 255}} = CRGB{0, 255, 0};
|
||||
} else if (m_mode == White) {
|
||||
Surface{dpy, {0, 0}, {255, 255}} = CRGB{255, 255, 255};
|
||||
} else if (m_mode == Red) {
|
||||
Surface{dpy, {0, 0}, {255, 255}} = CRGB{255, 0, 0};
|
||||
} else if (m_mode == Green) {
|
||||
Surface{dpy, {0, 0}, {255, 255}} = CRGB{0, 255, 0};
|
||||
} else if (m_mode == Blue) {
|
||||
Surface{dpy, {0, 0}, {255, 255}} = CRGB{0, 0, 255};
|
||||
} else if (m_mode == HSV) {
|
||||
Surface{dpy, {0, 0}, {255, 255}}.paintShader([=](CRGB& pixel, const VirtualCoordinates& coords, const PhysicalCoordinates&, const VirtualCoordinates& surfaceCoords) {
|
||||
pixel = CHSV(coords.x, coords.y, 255);
|
||||
});
|
||||
} else if (m_mode == RGB) {
|
||||
Surface{dpy, {0, 0}, {255, 255}}.paintShader([=](CRGB& pixel, const VirtualCoordinates& coords, const PhysicalCoordinates&, const VirtualCoordinates& surfaceCoords) {
|
||||
pixel = CRGB(coords.x, coords.y, (coords.x/2) + (coords.y/2));
|
||||
});
|
||||
}
|
||||
return;
|
||||
// Blank the canvas to white
|
||||
Surface{dpy, {0, 0}, {255, 255}} = CRGB{255, 255, 255};
|
||||
// Draw red line on top row
|
||||
Surface{dpy, {0, 0}, {255, 0}} = CRGB{255, 0, 0};
|
||||
// Green line on first column
|
||||
Surface{dpy, {0, 0}, {0, 255}} = CRGB{0, 255, 0};
|
||||
}
|
||||
|
||||
//Surface{dpy, {m_x, 0}, {m_x, 255}} = CRGB{255, 0, 0};
|
||||
///Surface{dpy, {0, m_y}, {255, m_y}} = CRGB{255, 0, 0};
|
||||
//dpy->pixelAt(VirtualCoordinates{m_x, m_y}) = CRGB{255, 0, 255};
|
||||
void
|
||||
TestAnimation::doMode(Args& args, Print& out)
|
||||
{
|
||||
String s = args[1];
|
||||
if (s == "") {
|
||||
out.println("Available modes: raw outline white red green blue hsv rgb none top left right bottom");
|
||||
out.print("Current mode: ");
|
||||
out.println((int)m_mode);
|
||||
} else if (s == "raw") {
|
||||
m_mode = Raw;
|
||||
} else if (s == "outline") {
|
||||
m_mode = Outline;
|
||||
} else if (s == "white") {
|
||||
m_mode = White;
|
||||
} else if (s == "red") {
|
||||
m_mode = Red;
|
||||
} else if (s == "green") {
|
||||
m_mode = Green;
|
||||
} else if (s == "blue") {
|
||||
m_mode = Blue;
|
||||
} else if (s == "hsv") {
|
||||
m_mode = HSV;
|
||||
} else if (s == "rgb") {
|
||||
m_mode = RGB;
|
||||
} else if (s == "top") {
|
||||
m_mode = Top;
|
||||
} else if (s == "left") {
|
||||
m_mode = Left;
|
||||
} else if (s == "right") {
|
||||
m_mode = Right;
|
||||
} else if (s == "bottom") {
|
||||
m_mode = Bottom;
|
||||
} else if (s == "none") {
|
||||
m_mode = None;
|
||||
} else {
|
||||
out.println("Unknown test mode");
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<Command>&
|
||||
TestAnimation::commands() const
|
||||
{
|
||||
static const std::vector<Command> _commands{
|
||||
{"test", &TestAnimation::doMode}
|
||||
};
|
||||
return _commands;
|
||||
}
|
||||
|
||||
STATIC_ALLOC(TestAnimation);
|
||||
|
@@ -5,8 +5,31 @@ public:
|
||||
TestAnimation() : Figment("Test") {}
|
||||
void loop() override;
|
||||
void render(Display* dpy) const override;
|
||||
void handleEvent(const InputEvent& evt) override;
|
||||
const std::vector<Command>& commands() const override;
|
||||
|
||||
private:
|
||||
uint8_t m_x;
|
||||
uint8_t m_y;
|
||||
CRGB m_color;
|
||||
uint8_t m_hue;
|
||||
|
||||
enum Mode {
|
||||
None,
|
||||
Raw,
|
||||
Outline,
|
||||
White,
|
||||
Red,
|
||||
Green,
|
||||
Blue,
|
||||
HSV,
|
||||
RGB,
|
||||
Top,
|
||||
Left,
|
||||
Right,
|
||||
Bottom
|
||||
};
|
||||
|
||||
Mode m_mode = None;
|
||||
void doMode(Args&, Print&);
|
||||
};
|
||||
|
26
src/animations/Thinking.cpp
Normal file
26
src/animations/Thinking.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <Figments.h>
|
||||
#include "../Static.h"
|
||||
|
||||
class Thinking: public Figment {
|
||||
public:
|
||||
Thinking() : Figment("Thinking") {}
|
||||
void render(Display* dpy) const override {
|
||||
Surface sfc = Surface(dpy, {0, 0}, {255, 255});
|
||||
uint8_t noiseY = sin8(m_noiseOffset % 255);
|
||||
uint8_t noiseX = cos8(m_noiseOffset % 255);
|
||||
sfc.paintShader([=](CRGB& pixel, const VirtualCoordinates& coords, const PhysicalCoordinates, const VirtualCoordinates& surfaceCoords) {
|
||||
pixel = CHSV(inoise8(noiseX + surfaceCoords.x, noiseY + surfaceCoords.y), 255, inoise8(noiseY + surfaceCoords.y, noiseX + surfaceCoords.x));
|
||||
});
|
||||
}
|
||||
|
||||
void loop() override {
|
||||
EVERY_N_MILLISECONDS(15) {
|
||||
m_noiseOffset += 1;
|
||||
}
|
||||
}
|
||||
private:
|
||||
int m_noiseOffset;
|
||||
};
|
||||
|
||||
STATIC_ALLOC(Thinking);
|
||||
STATIC_TASK(Thinking);
|
Reference in New Issue
Block a user