File Coverage

blib/lib/Algorithm/Easing/Backdraft.pm
Criterion Covered Total %
statement 34 34 100.0
branch 11 14 78.5
condition n/a
subroutine 7 7 100.0
pod 3 3 100.0
total 55 58 94.8


line stmt bran cond sub pod time code
1             package Algorithm::Easing::Backdraft;
2              
3 1     1   343 use Moose;
  1         1  
  1         4  
4              
5 1     1   3665 use Math::Trig qw(:pi);
  1         1  
  1         85  
6              
7 1     1   4 use constant EPSILON => 0.000001;
  1         1  
  1         51  
8              
9             extends 'Algorithm::Easing::Ease';
10              
11 1     1   3 use namespace::clean;
  1         1  
  1         8  
12              
13             sub ease_in {
14 402     402 1 264 my $self = shift;
15 402         385 my ($t,$b,$c,$d) = (shift,shift,shift,shift);
16              
17 402 100       494 return $b if ($t < EPSILON);
18 401 50       398 return $c if ($d < EPSILON);
19              
20 401         251 my $s = 1.70158;
21 401         587 my $post_fix = $t /= $d;
22 401         681 return $c * ($post_fix) * $t * (($s + 1) * $t - $s) + $b;
23             }
24              
25             sub ease_out {
26 402     402 1 254 my $self = shift;
27 402         382 my ($t,$b,$c,$d) = (shift,shift,shift,shift);
28              
29 402 100       452 return $b if ($t < EPSILON);
30 401 50       406 return $c if ($d < EPSILON);
31              
32 401         243 my $s = 1.70158;
33 401         751 return $c * (($t = $t / $d - 1) * $t * (($s + 1) * $t + $s) + 1) + $b;
34             }
35              
36             sub ease_both {
37 402     402 1 255 my $self = shift;
38 402         359 my ($t,$b,$c,$d) = (shift,shift,shift,shift);
39              
40 402 100       499 return $b if ($t < EPSILON);
41 401 50       414 return $c if ($d < EPSILON);
42              
43 401         242 my $s = 1.70158;
44 401 100       575 if (($t /= $d / 2) < 1) {
45 199         355 return $c / 2 * ($t * $t * ((($s *= (1.525)) + 1 )* $t - $s)) + $b;
46             }
47 202         139 my $post_fix = $t-= 2;
48 202         329 return $c / 2 * (($post_fix) * $t * ((($s *= (1.525)) + 1) * $t + $s) + 2) + $b;
49             }
50              
51             1;
52              
53             __END__
54              
55             # MAN3 POD
56              
57             =head1 NAME
58              
59             Algorithm::Easing::Backdraft - Calculate eased translations between two positive whole integer values over time
60              
61             =cut
62              
63             =head1 SYNOPSIS
64              
65             use Algorithm::Easing;
66             use Algorithm::Easing::Backdraft;
67              
68             # this example produces traditional 'backdraft' output;
69              
70             my $translation = Algorithm::Easing::Backdraft->new;
71              
72             # total time for eased translation as a real positive integer value
73             my $d = 2.5;
74              
75             # begin
76             my $b = 0;
77              
78             # change
79             my $c = 240;
80              
81             # time passed in seconds as a real positive integer between each frame
82             my $frame_time = 0.0625;
83              
84             my @p = [319,0];
85              
86             for(my $t = 0; $t < 2.5; $t += 0.0625) {
87             $p[1] = $translation->ease_out($t,$b,$c,$d)
88              
89             # plot
90             ...;
91             }
92              
93             =cut
94              
95             =head1 METHODS
96              
97             =cut
98              
99             =head2 ease_none
100             usage :
101            
102             Parameters :
103             Let t be time,
104             Let b be begin,
105             Let c be change,
106             Let d be duration,
107             Results :
108             Let p be position,
109            
110             my $p = $obj->ease_none($t,$b,$c,$d);
111              
112             This method is used for a linear translation between two positive real whole integers using a positive real integer as the parameter for time.
113              
114             =cut
115              
116             =head2 ease_in
117             usage :
118            
119             Parameters :
120             Let t be time,
121             Let b be begin,
122             Let c be change,
123             Let d be duration,
124             Results :
125             Let p be position,
126            
127             my $p = $obj->ease_in($t,$b,$c,$d);
128              
129             This method is used to ease in between two positive real whole integers as an inward tween using a positive real integer as the parameter for time in the fashion of a backdraft.
130              
131             =cut
132              
133             =head2 ease_out
134             usage :
135            
136             Parameters :
137             Let be time,
138             Let b be begin,
139             Let c be change,
140             Let d be duration,
141             Results :
142             Let p be position,
143            
144             my $p = $obj->ease_out($t,$b,$c,$d);
145              
146             This method is used to ease out between two positive real whole integers as an inward tween using a positive real integer as the parameter for time in the fashion of a backdraft.
147              
148             =cut
149              
150             =head2 ease_both
151             usage :
152            
153             Parameters :
154             Let t be time,
155             Let b be begin,
156             Let c be change,
157             Let d be duration,
158             Results :
159             Let p be position,
160            
161             my $p = $obj->ease_both($t,$b,$c,$d);
162              
163             This method is used to ease both in then out between two positive real whole integers as an inward tween using a positive real integer as the parameter for time in the fashion of a backdraft.
164              
165             =cut
166              
167             =head1 AUTHOR
168              
169             Jason McVeigh, <jmcveigh@outlook.com>
170              
171             =cut
172              
173             =head1 COPYRIGHT AND LICENSE
174              
175             Copyright 2016 by Jason McVeigh
176              
177             This library is free software; you can redistribute it and/or modify
178             it under the same terms as Perl itself.
179              
180             =cut