Merge pull request #24 from lost-hope/2D-support

This commit is contained in:
Blaž Kristan 2022-05-20 07:15:45 +02:00 committed by GitHub
commit d8be286831
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -919,7 +919,8 @@ class WS2812FX {
fill_solid(CRGB* leds, const struct CRGB& color), fill_solid(CRGB* leds, const struct CRGB& color),
fadeToBlackBy(CRGB* leds, uint8_t fadeBy), fadeToBlackBy(CRGB* leds, uint8_t fadeBy),
nscale8(CRGB* leds, uint8_t scale), nscale8(CRGB* leds, uint8_t scale),
setPixels(CRGB* leds); setPixels(CRGB* leds),
drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,CRGB c);
inline void setPixelColorXY(uint16_t x, uint16_t y, uint32_t c) { setPixelColorXY(x, y, byte(c>>16), byte(c>>8), byte(c), byte(c>>24)); } inline void setPixelColorXY(uint16_t x, uint16_t y, uint32_t c) { setPixelColorXY(x, y, byte(c>>16), byte(c>>8), byte(c), byte(c>>24)); }
inline void setPixelColorXY(uint16_t x, uint16_t y, CRGB &c) { setPixelColorXY(x, y, c.red, c.green, c.blue); } inline void setPixelColorXY(uint16_t x, uint16_t y, CRGB &c) { setPixelColorXY(x, y, c.red, c.green, c.blue); }

View File

@ -332,3 +332,18 @@ void WS2812FX::setPixels(CRGB* leds) {
uint16_t h = SEGMENT.virtualHeight(); uint16_t h = SEGMENT.virtualHeight();
for (uint16_t y = 0; y < h; y++) for (uint16_t x = 0; x < w; x++) setPixelColorXY(x, y, leds[XY(x,y)]); for (uint16_t y = 0; y < h; y++) for (uint16_t x = 0; x < w; x++) setPixelColorXY(x, y, leds[XY(x,y)]);
} }
//line function
void WS2812FX::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,CRGB c) {
uint16_t dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
uint16_t dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
uint16_t err = (dx>dy ? dx : -dy)/2, e2;
for(;;){
setPixelColorXY(x0,y0,c);
if (x0==x1 && y0==y1) break;
e2 = err;
if (e2 >-dx) { err -= dy; x0 += sx; }
if (e2 < dy) { err += dx; y0 += sy; }
}
}