Skip to content

Instantly share code, notes, and snippets.

@isarojdahal
Created September 29, 2020 10:09
Show Gist options
  • Save isarojdahal/19f208190922a29a94a237fbb6d6f8b9 to your computer and use it in GitHub Desktop.
Save isarojdahal/19f208190922a29a94a237fbb6d6f8b9 to your computer and use it in GitHub Desktop.
public class AnimationBeat {
private long started;
private long a; // length of phase a
private long b; // length of phase b
private long c; // length of phase c
public AnimationBeat(){
started = System.currentTimeMillis();
this.a = 5000;
this.b = 500;
this.c = 500;
}
// returns which phase the animation is currently in
public char getInPhase(){
long currTime = System.currentTimeMillis();
long rem = (currTime - started) % (a + b);
if (rem > a + b){
return 'c';
} else if (rem > a) {
return 'b';
} else {
return 'c';
}
}
// returns a number (out of 100) showing the percentage completion of this phase
public long getPhaseCompletion(){
long currTime = System.currentTimeMillis();
long rem = (currTime - started) % (a + b+c);
if (rem > a+b){
return ((rem -a-b)*100)/c;
} else if (rem > a){
return ((rem - a)*100)/b;
} else {
return rem*100/a;
}
}
public static void main(String[] args){
AnimationBeat animationBeat = new AnimationBeat();
char inPhase = animationBeat.getInPhase();
long phaseCompletion = animationBeat.getPhaseCompletion();
System.out.print("Inphase : "+inPhase+" and Phase Completion : "+phaseCompletion);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment