I'm trying to figure out the logic to set an arbitrary time, and then have that time "play back" at different speeds (like .5x or 4x real time).
Here is the logic I have thus far, which will playback the time at normal speed:
import java.util.Calendar;
public class Clock {
long delta;
private float speed = 1f;
public Clock(Calendar startingTime) {
delta = System.currentTimeMillis()-startingTime.getTimeInMillis();
}
private Calendar adjustedTime() {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis()-delta);
return cal;
}
public void setPlaybackSpeed(float speed){
this.speed = speed;
}
public static void main(String[] args){
Calendar calendar = Calendar.getInstance();
calendar.set(2010, 4, 4, 4, 4, 4);
Clock clock = new Clock(calendar);
while(true){
System.out.println(clock.adjustedTime().getTime());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
I'm having trouble figuring out where the "speed" attribute needs to be used in the logic.