1 module dinu.animation;
2 
3 
4 import
5 	std.math,
6 	std.algorithm,
7 	std.datetime,
8 	ws.time;
9 
10 
11 class Animation {
12 	double start;
13 	double end;
14 	double timeStart;
15 	double duration;
16 	this(double start, double end, double duration){
17 		this.start = start;
18 		this.end = end;
19 		this.timeStart = now;
20 		this.duration = duration;
21 	}
22 	abstract double func(double completion);
23 	double calculate(){
24 		double completion = (timeCurrent - timeStart).min(duration)/duration;
25 		return start + (end-start)*func(completion);
26 	}
27 	bool done(){
28 		return timeStart+duration < timeCurrent;
29 	}
30 	double timeCurrent(){
31 		return now;
32 	}
33 }
34 
35 
36 class AnimationExpIn: Animation {
37 
38 	this(double start, double end, double duration){
39 		super(start, end, duration);
40 	}
41 
42 	override double func(double completion){
43 		return 1-(completion-1).pow(2);
44 	}
45 
46 }
47 
48 class AnimationExpOut: Animation {
49 
50 	this(double start, double end, double duration){
51 		super(start, end, duration);
52 	}
53 
54 	override double func(double completion){
55 		return completion.pow(2);
56 	}
57 
58 }
59