-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from lukflug/dev
Version 0.1.0
- Loading branch information
Showing
26 changed files
with
1,415 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ plugins { | |
|
||
allprojects { | ||
group = 'com.lukflug' | ||
version = '0.0.3' | ||
version = '0.1.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.lukflug.panelstudio; | ||
|
||
/** | ||
* Class representing an animation. | ||
* @author lukflug | ||
*/ | ||
public abstract class Animation { | ||
/** | ||
* Current value. | ||
*/ | ||
protected double value; | ||
/** | ||
* Past value. | ||
*/ | ||
protected double lastValue; | ||
/** | ||
* Time of last value transition. | ||
*/ | ||
protected long lastTime=System.currentTimeMillis(); | ||
|
||
/** | ||
* Set a value immediately, without an transition animation. | ||
* @param value the new value | ||
*/ | ||
public void initValue(double value) { | ||
this.value=value; | ||
lastValue=value; | ||
} | ||
|
||
/** | ||
* The the current value. | ||
* @return an interpolated value between {@link #value} and {@link #lastValue} depending on the current time | ||
*/ | ||
public double getValue() { | ||
if (getSpeed()==0) return value; | ||
double weight=(System.currentTimeMillis()-lastTime)/(double)getSpeed(); | ||
if (weight>=1) return value; | ||
else if (weight<=0) return lastValue; | ||
return value*weight+lastValue*(1-weight); | ||
} | ||
|
||
/** | ||
* Get the target value. | ||
* @return the current {@link #value} | ||
*/ | ||
public double getTarget() { | ||
return value; | ||
} | ||
|
||
/** | ||
* Set the value, with a transition between the old and new value. | ||
* @param value the new value | ||
*/ | ||
public void setValue(double value) { | ||
lastValue=getValue(); | ||
this.value=value; | ||
lastTime=System.currentTimeMillis(); | ||
} | ||
|
||
/** | ||
* Used to obtain the animation speed. | ||
* @return time a transition should take in milliseconds | ||
*/ | ||
protected abstract int getSpeed(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.