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