Skip to content

Instantly share code, notes, and snippets.

@jbobrow
Created July 24, 2020 23:22
Show Gist options
  • Save jbobrow/c39872f24509590c731e8f3c5b7340d3 to your computer and use it in GitHub Desktop.
Save jbobrow/c39872f24509590c731e8f3c5b7340d3 to your computer and use it in GitHub Desktop.
void deathDisplay() {
// Note: DEATH_INTERVAL is 1000 (1 second animation)
if (!deathTimer.isExpired()) {
// then we are healing
// 4 containers to remove energy from
FOREACH_FACE(f) {
long offset = DEATH_INTERVAL / 6;
byte dist = (6 - f) % 6;
byte phase;
switch (dist) {
case 0: phase = 3; break;
case 1: phase = 2; break;
case 2: phase = 1; break;
case 3: phase = 0; break;
case 4: phase = 1; break;
case 5: phase = 2; break;
}
long t0 = (phase * offset) + (DEATH_INTERVAL - (offset * 3));
long t1 = (phase * offset);
long progress = deathTimer.getRemaining();
byte brightness = map_m(progress, t0, t1, 255, 0);
if (progress > t0) brightness = 0;
if (progress < t1) brightness = 0;
setFaceColor(f, makeColorHSB(currentHue, 255, brightness));
}
}
else {
FOREACH_FACE(f) {
byte currentBrightness = random(50);
if (f > 0) { //regular faces
setColorOnFace(makeColorHSB(currentHue, 255, currentBrightness), f);
} else {//face 0
byte filamentBrightness = max(currentBrightness, 100);
setColorOnFace(makeColorHSB(currentHue, 255, filamentBrightness), f);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment