LapisSea

Untitled

Dec 28th, 2016
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. public class Transition{
  2.    
  3.     private float   startV,endV;
  4.     private long    activeChange;
  5.     private int     speed;
  6.    
  7.     public Transition(float initalValue, int speed){
  8.         this.speed=speed;
  9.         setInstant(initalValue);
  10.     }
  11.    
  12.     public void setInstant(float value){
  13.         startV=endV=value;
  14.         activeChange=System.currentTimeMillis()-speed;
  15.     }
  16.    
  17.     public void setSpeed(int ms){
  18.         speed=ms;
  19.     }
  20.    
  21.     public void setGoal(float value){
  22.         startV=get();
  23.         endV=value;
  24.         activeChange=System.currentTimeMillis();
  25.     }
  26.    
  27.     public float get(){
  28.         float precent=getPrecent();
  29.        
  30.         if(precent<0) return startV;
  31.         if(precent>1) return endV;
  32.        
  33.         return startV+(endV-startV)*precent;
  34.     }
  35.    
  36.     public boolean changing(){
  37.         if(startV==endV) return false;
  38.        
  39.         float precent=getPrecent();
  40.        
  41.         return precent>0&&precent<1;
  42.     }
  43.    
  44.     private float getPrecent(){
  45.         long past=System.currentTimeMillis()-activeChange;
  46.        
  47.         if(past>speed) return 1;
  48.         if(past<0) return 0;
  49.        
  50.         return (float)(((double)past)/speed);
  51.     }
  52. }
Add Comment
Please, Sign In to add comment