Algorithm-Easing
view release on metacpan or search on metacpan
lib/Algorithm/Easing/Cubic.pm view on Meta::CPAN
package Algorithm::Easing::Cubic;
use Moose;
use Math::Trig qw(:pi);
use constant EPSILON => 0.000001;
extends 'Algorithm::Easing::Ease';
use namespace::autoclean;
sub ease_in {
my $self = shift;
my ($t,$b,$c,$d) = (shift,shift,shift,shift);
return $b if ($t < EPSILON);
return $c if ($d < EPSILON);
return $c * ($t /= $d) * $t * $t + $b;
}
sub ease_out {
my $self = shift;
my ($t,$b,$c,$d) = (shift,shift,shift,shift);
return $b if ($t < EPSILON);
return $c if ($d < EPSILON);
return $c * (($t = $t / $d - 1) * $t * $t + 1) + $b;
}
sub ease_both {
my $self = shift;
my ($t,$b,$c,$d) = (shift,shift,shift,shift);
return $b if ($t < EPSILON);
return $c if ($d < EPSILON);
if (($t /= $d/2) < 1) {
return $c / 2 * $t * $t * $t + $b;
}
return $c / 2 * (($t -= 2) * $t * $t + 2) + $b;
}
1;
__END__
# MAN3 POD
=head1 NAME
Algorithm::Easing::Cubic - Calculate eased translations between two positive whole integer values over time
=cut
=head1 SYNOPSIS
use Algorithm::Easing;
use Algorithm::Easing::Ease;
# this example produces traditional 'cubic' output;
my $translation = Algorithm::Easing::Cubic->new;
# total time for eased translation as a real positive integer value
my $d = 2.5;
# begin
( run in 0.624 second using v1.01-cache-2.11-cpan-119454b85a5 )