Skip to content

Instantly share code, notes, and snippets.

@jbobrow
Last active July 24, 2020 14:16
Show Gist options
  • Save jbobrow/3c17f0043c30c09ed2853392f9aefced to your computer and use it in GitHub Desktop.
Save jbobrow/3c17f0043c30c09ed2853392f9aefced to your computer and use it in GitHub Desktop.
/*
* Rise and Fall Arc Animation
*/
byte start = 0;
byte end;
Timer arcTimer;
#define ARC_DURATION 500
#define ARC_DELAY 100
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
if(arcTimer.isExpired()) {
// pick a new start
start = random(6);
// pick a new end
end = getAdjacentFace(start);
arcTimer.set(ARC_DURATION);
}
if(!arcTimer.isExpired()) {
if(arcTimer.getRemaining() > ARC_DELAY) {
// show start of arc
byte bri = map(arcTimer.getRemaining(), ARC_DELAY, ARC_DURATION, 0, 255);
setColorOnFace(dim(WHITE, bri), start);
}
if(arcTimer.getRemaining() < ARC_DURATION - ARC_DELAY) {
// show end of arc
byte bri = map(arcTimer.getRemaining(), 0, ARC_DURATION - ARC_DELAY, 0, 255);
setColorOnFace(dim(WHITE, bri), end);
}
}
}
byte getAdjacentFace(byte enter) {
if(random(2) == 0) {
return (enter + 1) % 6;
}
else {
return (enter + 6 - 1) % 6;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment