Skip to content

Commit 5535606

Browse files
Merge pull request #954 from adafruit/ooze-ice
Add icycles to Ooze Master 3000
2 parents 7e26af0 + 9cb2cc4 commit 5535606

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

OozeMaster3000/OozeMaster3000.ino

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
uint8_t dripColor[] = { 0, 255, 0 }; // Bright green ectoplasm
1212
#define PIXEL_PITCH (1.0 / 150.0) // 150 pixels/m
13+
#define ICE_BRIGHTNESS 0 // Icycle effect Brightness (0 to <100%)
1314

1415
#define GAMMA 2.6
1516
#define G_CONST 9.806 // Standard acceleration due to gravity
@@ -130,14 +131,25 @@ void loop() {
130131
}
131132

132133
// 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
133141
switch(drip[i].mode) {
134142
case MODE_IDLE:
135143
// Do nothing
136144
break;
137145
case MODE_OOZING:
138146
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);
141153
set(i, 0, x);
142154
break;
143155
case MODE_DRIBBLING_1:
@@ -193,15 +205,27 @@ void dripDraw(uint8_t dNum, float a, float b, bool fade) {
193205
float range = center - a + 1.0; // Distance from center to a, plus 1 pixel
194206
for(int i=firstPixel; i<= lastPixel; i++) {
195207
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+
}
203216
}
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;
204227
}
228+
#endif
205229
x = pow(x, GAMMA);
206230
set(dNum, i, x);
207231
}

0 commit comments

Comments
 (0)