|
10 | 10 |
|
11 | 11 | uint8_t dripColor[] = { 0, 255, 0 }; // Bright green ectoplasm |
12 | 12 | #define PIXEL_PITCH (1.0 / 150.0) // 150 pixels/m |
| 13 | +#define ICE_BRIGHTNESS 0 // Icycle effect Brightness (0 to <100%) |
13 | 14 |
|
14 | 15 | #define GAMMA 2.6 |
15 | 16 | #define G_CONST 9.806 // Standard acceleration due to gravity |
@@ -130,14 +131,25 @@ void loop() { |
130 | 131 | } |
131 | 132 |
|
132 | 133 | // Render drip state to NeoPixels... |
| 134 | +#if ICE_BRIGHTNESS > 0 |
| 135 | + // Draw icycles if ICE_BRIGHTNESS is set |
| 136 | + x = pow((float)ICE_BRIGHTNESS * 0.01, GAMMA); |
| 137 | + for(int d=0; d<=drip[i].dribblePixel; d++) { |
| 138 | + set(i, d, x); |
| 139 | + } |
| 140 | +#endif |
133 | 141 | switch(drip[i].mode) { |
134 | 142 | case MODE_IDLE: |
135 | 143 | // Do nothing |
136 | 144 | break; |
137 | 145 | case MODE_OOZING: |
138 | 146 | x = dtReal / drip[i].eventDurationReal; // 0.0 to 1.0 over ooze interval |
139 | | - x = sqrt(x); // Perceived area increases linearly |
140 | | - x = pow(x, GAMMA); |
| 147 | + x = sqrt(x); // Perceived area increases linearly |
| 148 | +#if ICE_BRIGHTNESS > 0 |
| 149 | + x = ((float)ICE_BRIGHTNESS * 0.01) + |
| 150 | + x * (float)(100 - ICE_BRIGHTNESS) * 0.01; |
| 151 | +#endif |
| 152 | + x = pow(x, GAMMA); |
141 | 153 | set(i, 0, x); |
142 | 154 | break; |
143 | 155 | case MODE_DRIBBLING_1: |
@@ -193,15 +205,27 @@ void dripDraw(uint8_t dNum, float a, float b, bool fade) { |
193 | 205 | float range = center - a + 1.0; // Distance from center to a, plus 1 pixel |
194 | 206 | for(int i=firstPixel; i<= lastPixel; i++) { |
195 | 207 | float x = fabs(center - (float)i); // Pixel distance from center point |
196 | | - if(x >= range) continue; // Outside of drip, skip pixel |
197 | | - x = (range - x) / range; // 0.0 (edge) to 1.0 (center) |
198 | | - if(fade) { |
199 | | - int dLen = drip[dNum].length - drip[dNum].dribblePixel; // Length of drip |
200 | | - if(dLen > 0) { // Scale x by 1.0 at top to 1/3 at bottom of drip |
201 | | - int dPixel = i - drip[dNum].dribblePixel; // Pixel position along drip |
202 | | - x *= 1.0 - ((float)dPixel / (float)dLen * 0.66); |
| 208 | + if(x < range) { // Inside drip |
| 209 | + x = (range - x) / range; // 0.0 (edge) to 1.0 (center) |
| 210 | + if(fade) { |
| 211 | + int dLen = drip[dNum].length - drip[dNum].dribblePixel; // Length of drip |
| 212 | + if(dLen > 0) { // Scale x by 1.0 at top to 1/3 at bottom of drip |
| 213 | + int dPixel = i - drip[dNum].dribblePixel; // Pixel position along drip |
| 214 | + x *= 1.0 - ((float)dPixel / (float)dLen * 0.66); |
| 215 | + } |
203 | 216 | } |
| 217 | + } else { |
| 218 | + x = 0.0; |
| 219 | + } |
| 220 | +#if ICE_BRIGHTNESS > 0 |
| 221 | + // Upper pixels may be partially lit for an icycle effect |
| 222 | + if(i <= drip[dNum].dribblePixel) { |
| 223 | + // Math because preprocessor doesn't allow float constant in #if. |
| 224 | + // Optimizer will reduce the math to float constants, it's fine. |
| 225 | + x = ((float)ICE_BRIGHTNESS * 0.01) + |
| 226 | + x * (float)(100 - ICE_BRIGHTNESS) * 0.01; |
204 | 227 | } |
| 228 | +#endif |
205 | 229 | x = pow(x, GAMMA); |
206 | 230 | set(dNum, i, x); |
207 | 231 | } |
|
0 commit comments