@@ -42,14 +42,15 @@ void FastLEDRenderer::init(ParticleSysConfig *g, uint8_t left, uint8_t top, uint
42
42
this ->height = height;
43
43
this ->crop_left = crop_left;
44
44
this ->crop_top = crop_top;
45
+ this ->globalBrightness = 255 ;
45
46
}
46
47
47
48
/* GMA hier - change below ########################################################## */
48
49
49
50
void FastLEDRenderer::render (ParticleSysConfig *g, Particle_Abstract particles[], byte numParticles, CRGB *_leds) {
50
51
byte row, col;
51
52
uint16_t dx, dy;
52
- unsigned long tempVal;
53
+ uint8_t tempVal;
53
54
CRGB baseRGB;
54
55
55
56
// go over particles and update matrix cells on the way
@@ -74,36 +75,42 @@ void FastLEDRenderer::render(ParticleSysConfig *g, Particle_Abstract particles[]
74
75
// bottom left
75
76
col = part_x / g->res_x ;
76
77
row = part_y / g->res_y ;
77
- tempVal = ((unsigned long )dx*dy*particles[i].ttl )/g->res_area ;
78
- if (tempVal > 255 ) {tempVal = 255 ;}
78
+ tempVal = calcTempVal (g,dx,dy,particles[i].ttl );
79
79
addColor (col, row, &baseRGB, tempVal, _leds);
80
80
81
81
// bottom right;
82
82
col++;
83
83
if (col < g->width ) {
84
- tempVal = ((unsigned long )(g->res_x -dx)*dy*particles[i].ttl )/g->res_area ;
85
- if (tempVal > 255 ) {tempVal = 255 ;}
84
+ tempVal = calcTempVal (g,(g->res_x -dx),dy,particles[i].ttl );
86
85
addColor (col, row, &baseRGB, tempVal, _leds);
87
86
}
88
87
89
88
// top right
90
89
row++;
91
90
if (col < g->width && row < g->height ) {
92
- tempVal = ((unsigned long )(g->res_x -dx)*(g->res_y -dy)*particles[i].ttl )/g->res_area ;
93
- if (tempVal > 255 ) {tempVal = 255 ;}
91
+ tempVal = calcTempVal (g,(g->res_x -dx),(g->res_y -dy),particles[i].ttl );
94
92
addColor (col, row, &baseRGB, tempVal, _leds);
95
93
}
96
94
97
95
// top left
98
96
col--;
99
97
if (row < g->height ) {
100
- tempVal = ((unsigned long )dx*(g->res_y -dy)*particles[i].ttl )/g->res_area ;
101
- if (tempVal > 255 ) {tempVal = 255 ;}
98
+ tempVal = calcTempVal (g,dx,(g->res_y -dy),particles[i].ttl );
102
99
addColor (col, row, &baseRGB, tempVal, _leds);
103
100
}
104
101
}
105
102
}
106
103
104
+ uint8_t FastLEDRenderer::calcTempVal (ParticleSysConfig *g, uint16_t dx, uint16_t dy, uint8_t ttl) {
105
+ uint8_t _ttl = ttl;
106
+ if (globalBrightness < 255 ) {
107
+ _ttl = scale8 (_ttl,globalBrightness);
108
+ }
109
+ unsigned long r = ((unsigned long )dx*dy*_ttl)/g->res_area ;
110
+ if (r > 255 )
111
+ return 255 ;
112
+ return r;
113
+ }
107
114
108
115
void FastLEDRenderer::addColor (byte col, byte row, CRGB *colorRGB, byte value, CRGB *_leds) {
109
116
if (col >= width || row >= height) // check if pixel is outside of the render area
0 commit comments