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 {
protected:
Window* window;
uint8_t x, y;
accum88 x, y;
uint8_t length = 1;
uint8_t _direction = 2;
bool _random_direction = false;

View File

@ -15,25 +15,25 @@ void MatrixEffectColumn::restart(bool completely_random) {
}
if (completely_random) {
x = random8(window->width);
y = random8(window->height);
x = random8(window->width)<<8;
y = random8(window->height)<<8;
} else {
switch(_direction) {
case DIR_NORTH:
x = random8(window->width);
y = window->height - 1;
x = random8(window->width)<<8;
y = (window->height - 1)<<8;
break;
case DIR_EAST:
x = 0;
y = random8(window->height);
y = random8(window->height)<<8;
break;
case DIR_SOUTH:
x = random8(window->width);
x = random8(window->width)<<8;
y = 0;
break;
case DIR_WEST:
x = window->width - 1;
y = random8(window->height);
x = (window->width - 1)<<8;
y = random8(window->height)<<8;
break;
}
}
@ -46,36 +46,36 @@ void MatrixEffectColumn::restart(bool completely_random) {
void MatrixEffectColumn::advance() {
switch(_direction) {
case DIR_NORTH:
y--;
if (y > window->height && y + length > window->height) running=false;
y-=speed;
if ((y>>8) > window->height && (y>>8) + length > window->height) running=false;
break;
case DIR_EAST:
x++;
if (x - length > window->width) running=false;
x+=speed;
if ((x>>8) - length > window->width) running=false;
break;
case DIR_SOUTH:
y++;
if (y - length > window->height) running=false;
y+=speed;
if ((y>>8) - length > window->height) running=false;
break;
case DIR_WEST:
x--;
if (x > window->width && y + length > window->width) running=false;
x-=speed;
if ((x>>8) > window->width && (y>>8) + length > window->width) running=false;
break;
}
}
void MatrixEffectColumn::draw() {
int8_t xdir = 0;
int8_t ydir = 0;
int16_t xdir = 0;
int16_t ydir = 0;
switch (_direction) {
case DIR_NORTH: ydir = 1; break;
case DIR_EAST: xdir = -1; break;
case DIR_SOUTH: ydir = -1; break;
case DIR_WEST: xdir = 1; break;
case DIR_NORTH: ydir = 0xFF; break;
case DIR_EAST: xdir = -0xFF; break;
case DIR_SOUTH: ydir = -0xFF; break;
case DIR_WEST: xdir = 0xFF; break;
}
for(int i=0; i<length; 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.
restart(false);
}
} else {
if (millis() - last_move > speed) {
advance();
last_move = millis();
}
draw();
} else {
advance();
draw();
}
}