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