-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Analog clock 2d branch0 15 #3943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
154da94
7e8a667
5d93543
8930a6e
3473794
2ee702e
fd16120
1b799f7
aab45af
9dcad8d
7960805
d5faa26
c9c0d7d
93d5ba4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -370,7 +370,7 @@ void Segment::box_blur(uint16_t i, bool vertical, fract8 blur_amount) { | |
| for (unsigned j = 0; j < dim1; j++) { | ||
| unsigned x = vertical ? i : j; | ||
| unsigned y = vertical ? j : i; | ||
| setPixelColorXY(x, y, tmp[j]); | ||
| setPixelColorXY((int)x, (int)y, tmp[j]); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -471,6 +471,34 @@ void Segment::draw_circle(uint16_t cx, uint16_t cy, uint8_t radius, CRGB col) { | |
| } | ||
| } | ||
|
|
||
| #ifdef WLED_USE_AA_PIXELS | ||
| void Segment::drawCircleAntialiased(uint16_t cx, uint16_t cy, uint8_t radius, CRGB col) { | ||
| if (!isActive() || radius == 0) return; // not active | ||
| const uint16_t cols = virtualWidth(); | ||
| const uint16_t rows = virtualHeight(); | ||
| // Bresenham’s Algorithm | ||
| int d = 3 - (2*radius); | ||
| int y = radius, x = 0; | ||
| while (y >= x) { | ||
| setPixelColorXY(((float)cx+x-0.5)/cols, ((float)cy+y-0.5)/rows, col, true); | ||
| setPixelColorXY(((float)cx-x+0.5)/cols, ((float)cy+y-0.5)/rows, col, true); | ||
| setPixelColorXY(((float)cx+x-0.5)/cols, ((float)cy-y+0.5)/rows, col, true); | ||
| setPixelColorXY(((float)cx-x+0.5)/cols, ((float)cy-y+0.5)/rows, col, true); | ||
| setPixelColorXY(((float)cx+y-0.5)/cols, ((float)cy+x-0.5)/rows, col, true); | ||
| setPixelColorXY(((float)cx-y+0.5)/cols, ((float)cy+x-0.5)/rows, col, true); | ||
| setPixelColorXY(((float)cx+y-0.5)/cols, ((float)cy-x+0.5)/rows, col, true); | ||
| setPixelColorXY(((float)cx-y+0.5)/cols, ((float)cy-x+0.5)/rows, col, true); | ||
| x++; | ||
| if (d > 0) { | ||
| y--; | ||
| d += 4 * (x - y) + 10; | ||
| } else { | ||
| d += 4 * x + 6; | ||
| } | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
| // by stepko, taken from https://editor.soulmatelights.com/gallery/573-blobs | ||
| void Segment::fill_circle(uint16_t cx, uint16_t cy, uint8_t radius, CRGB col) { | ||
| if (!isActive() || radius == 0) return; // not active | ||
|
|
@@ -491,7 +519,7 @@ void Segment::nscale8(uint8_t scale) { | |
| const unsigned cols = virtualWidth(); | ||
| const unsigned rows = virtualHeight(); | ||
| for (unsigned y = 0; y < rows; y++) for (unsigned x = 0; x < cols; x++) { | ||
| setPixelColorXY(x, y, CRGB(getPixelColorXY(x, y)).nscale8(scale)); | ||
| setPixelColorXY((int)x, (int)y, CRGB(getPixelColorXY(x, y)).nscale8(scale)); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -513,6 +541,33 @@ void Segment::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint3 | |
| } | ||
| } | ||
|
|
||
| //line function | ||
| void Segment::drawLineAntialiased(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint32_t c) { | ||
| if (!isActive()) return; // not active | ||
| const uint16_t cols = virtualWidth(); | ||
| const uint16_t rows = virtualHeight(); | ||
| if (x0 >= cols || x1 >= cols || y0 >= rows || y1 >= rows) return; | ||
| const int16_t dx = abs(x1-x0), sx = x0<x1 ? 1 : -1; | ||
softhack007 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const int16_t dy = abs(y1-y0), sy = y0<y1 ? 1 : -1; | ||
| int16_t err = (dx-dy)/2, e2, x2; | ||
| int16_t ed = (dx+dy == 0) ? 1 : sqrt((float)dx*dx + (float)dy*dy); | ||
softhack007 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| for (;;) { | ||
|
||
| setPixelColorXY(x0,y0,color_blend(c,getPixelColorXY(x0,y0),0xFFFF * abs(err - dx + dy) / ed, true)); | ||
| e2 = err; x2 = x0; | ||
| if (e2 >= -dx) { | ||
| if(x0 == x1) break; | ||
| if (e2+dy < ed) setPixelColorXY(x0,y0+sy, color_blend(c,getPixelColorXY(x0,y0+sy), 0xFFFF * (e2+dy)/ed, true)); | ||
| err -= dy; x0 += sx; | ||
| } | ||
| if (e2 <= dy) { | ||
| if (y0 == y1) break; | ||
| if (dx-e2 < ed) setPixelColorXY(x2+sx, y0, color_blend(c,getPixelColorXY(x2+sx,y0), 0xFFFF * (dx-e2)/ed, true)); | ||
| err += dx; y0 += sy; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #include "src/font/console_font_4x6.h" | ||
| #include "src/font/console_font_5x8.h" | ||
| #include "src/font/console_font_5x12.h" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.