Skip to content

Instantly share code, notes, and snippets.

@fiskurgit
Created February 22, 2015 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fiskurgit/74e3a71b4b346f694e31 to your computer and use it in GitHub Desktop.
Save fiskurgit/74e3a71b4b346f694e31 to your computer and use it in GitHub Desktop.
package com.primer.accidentanimation;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Khronos {
private Date startDate;
private Date endDate;
private Date eventDate;
private int fps;
private long numberFrames;
private long startMS;
private long endMS;
private long totalMS;
private long eventMS;
private long totalAnimationMS;
private DateFormat formatter;
public Khronos() {
formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm");
}
public void setup(int minutes, int fps) {
this.fps = fps;
numberFrames = minutes * fps * 60;
totalAnimationMS = minutes * 60 * 1000;
}
public long getNumberOfFrames() {
return numberFrames;
}
//Format: '01/01/2010 01:55'
public void setKhronosStart(String dateTime) throws ParseException {
startDate = (Date) formatter.parse(dateTime);
startMS = startDate.getTime();
if (endMS > 0) {
totalMS = endMS - startMS;
}
}
//Format: '01/01/2010 01:55'
public void setKhronosEnd(String dateTime) throws ParseException {
endDate = (Date) formatter.parse(dateTime);
endMS = endDate.getTime();
if (startMS > 0) {
totalMS = endMS - startMS;
}
}
//Format: '01/01/2010 01:55'
public int getFrameIndex(String eventDateTime) throws ParseException {
eventDate = (Date) formatter.parse(eventDateTime);
eventMS = eventDate.getTime() - startMS;
long animationEventMS = (totalAnimationMS * eventMS) / totalMS;
float frm = ((float) animationEventMS / (float) 1000) * fps;
int frameNumber = (int) frm;
frameNumber = (frameNumber > 0) ? frameNumber : 1;
return frameNumber;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment