diff --git a/wled00/FX.h b/wled00/FX.h index d716d77f..0fe8c50a 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -919,7 +919,8 @@ class WS2812FX { fill_solid(CRGB* leds, const struct CRGB& color), fadeToBlackBy(CRGB* leds, uint8_t fadeBy), 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, CRGB &c) { setPixelColorXY(x, y, c.red, c.green, c.blue); } diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index 3924d3b5..0b4bed57 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -332,3 +332,18 @@ void WS2812FX::setPixels(CRGB* leds) { 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)]); } + +//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 = x0dy ? 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; } + } +}