-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDithering Test.cpp
More file actions
42 lines (39 loc) · 1.59 KB
/
Dithering Test.cpp
File metadata and controls
42 lines (39 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
void applyDithering() {
for (uint8_t y = 0; y < LED_ROWS; y++) {
for (uint8_t x = 0; x < LED_COLS; x++) {
uint16_t index = XY(x, y);
CRGB oldColor = leds[index];
CRGB newColor((oldColor.r > 127) ? 255 : 0, (oldColor.g > 127) ? 255 : 0, (oldColor.b > 127) ? 255 : 0);
leds[index] = newColor;
int8_t errorR = oldColor.r - newColor.r;
int8_t errorG = oldColor.g - newColor.g;
int8_t errorB = oldColor.b - newColor.b;
if (x < LED_COLS - 1) {
index = XY(x + 1, y); //right
leds[index] = CRGB(qadd8(leds[index].r, (errorR * 7) >> 4), qadd8(leds[index].g, (errorG * 7) >> 4), qadd8(leds[index].b, (errorB * 7) >> 4));
}
if (y < LED_ROWS - 1) {
if (x) {
index = XY(x - 1, y + 1);//leftbottom
leds[index] = CRGB(qadd8(leds[index].r, (errorR * 3) >> 4), qadd8(leds[index].g, (errorG * 3) >> 4), qadd8(leds[index].b, (errorB * 3) >> 4));
}
index = XY(x, y + 1);//bottom
leds[index] = CRGB(qadd8(leds[index].r, (errorR *5) >> 4), qadd8(leds[index].g, (errorG * 5) >> 4), qadd8(leds[index].b, (errorB * 5) >> 4));
if (x < LED_COLS - 1) {
index = XY(x + 1, y + 1);//rightbottom
leds[index] = CRGB(qadd8(leds[index].r, errorR >> 4), qadd8(leds[index].g, errorG >> 4), qadd8(leds[index].b, errorB >> 4));
}
}
}
}
}
uint16_t t;
void draw() {
t++;
for (uint8_t y = 0; y < LED_ROWS; y++) {
for (uint8_t x = 0; x < LED_COLS; x++) {
leds[XY(x, y)] = CHSV(inoise8(x << 3, (y << 3) + t << 2), 255, 255);
}
applyDithering();
}
}