Effect matrix now uses subpixel rendering for smoother movements.

This commit is contained in:
Fabian Schlenz 2019-09-25 06:32:35 +02:00
parent 711719921a
commit b8f39410c9
2 changed files with 27 additions and 31 deletions

View File

@ -9,7 +9,7 @@
class MatrixEffectColumn { class MatrixEffectColumn {
protected: protected:
Window* window; Window* window;
uint8_t x, y; accum88 x, y;
uint8_t length = 1; uint8_t length = 1;
uint8_t _direction = 2; uint8_t _direction = 2;
bool _random_direction = false; bool _random_direction = false;

View File

@ -15,25 +15,25 @@ void MatrixEffectColumn::restart(bool completely_random) {
} }
if (completely_random) { if (completely_random) {
x = random8(window->width); x = random8(window->width)<<8;
y = random8(window->height); y = random8(window->height)<<8;
} else { } else {
switch(_direction) { switch(_direction) {
case DIR_NORTH: case DIR_NORTH:
x = random8(window->width); x = random8(window->width)<<8;
y = window->height - 1; y = (window->height - 1)<<8;
break; break;
case DIR_EAST: case DIR_EAST:
x = 0; x = 0;
y = random8(window->height); y = random8(window->height)<<8;
break; break;
case DIR_SOUTH: case DIR_SOUTH:
x = random8(window->width); x = random8(window->width)<<8;
y = 0; y = 0;
break; break;
case DIR_WEST: case DIR_WEST:
x = window->width - 1; x = (window->width - 1)<<8;
y = random8(window->height); y = random8(window->height)<<8;
break; break;
} }
} }
@ -46,36 +46,36 @@ void MatrixEffectColumn::restart(bool completely_random) {
void MatrixEffectColumn::advance() { void MatrixEffectColumn::advance() {
switch(_direction) { switch(_direction) {
case DIR_NORTH: case DIR_NORTH:
y--; y-=speed;
if (y > window->height && y + length > window->height) running=false; if ((y>>8) > window->height && (y>>8) + length > window->height) running=false;
break; break;
case DIR_EAST: case DIR_EAST:
x++; x+=speed;
if (x - length > window->width) running=false; if ((x>>8) - length > window->width) running=false;
break; break;
case DIR_SOUTH: case DIR_SOUTH:
y++; y+=speed;
if (y - length > window->height) running=false; if ((y>>8) - length > window->height) running=false;
break; break;
case DIR_WEST: case DIR_WEST:
x--; x-=speed;
if (x > window->width && y + length > window->width) running=false; if ((x>>8) > window->width && (y>>8) + length > window->width) running=false;
break; break;
} }
} }
void MatrixEffectColumn::draw() { void MatrixEffectColumn::draw() {
int8_t xdir = 0; int16_t xdir = 0;
int8_t ydir = 0; int16_t ydir = 0;
switch (_direction) { switch (_direction) {
case DIR_NORTH: ydir = 1; break; case DIR_NORTH: ydir = 0xFF; break;
case DIR_EAST: xdir = -1; break; case DIR_EAST: xdir = -0xFF; break;
case DIR_SOUTH: ydir = -1; break; case DIR_SOUTH: ydir = -0xFF; break;
case DIR_WEST: xdir = 1; break; case DIR_WEST: xdir = 0xFF; break;
} }
for(int i=0; i<length; i++) { for(int i=0; i<length; i++) {
CRGB color = _getColor(i); CRGB color = _getColor(i);
window->raisePixel(x+(xdir*i), y+(ydir*i), &color); window->setSubPixel(x+(xdir*i), y+(ydir*i), &color);
} }
} }
@ -85,13 +85,9 @@ void MatrixEffectColumn::loop() {
// Start the column again. // Start the column again.
restart(false); restart(false);
} }
} else { } else {
if (millis() - last_move > speed) { advance();
advance(); draw();
last_move = millis();
}
draw();
} }
} }