Algorithm-Easing
view release on metacpan or search on metacpan
use strict;
use warnings;
use Test::More tests => 29;
use Algorithm::Easing::Mediator;
use Algorithm::Easing::Linear;
use Algorithm::Easing::Bounce;
use Algorithm::Easing::Circular;
use Algorithm::Easing::Cubic;
use Algorithm::Easing::Exponential;
use Algorithm::Easing::Quadratic;
use Algorithm::Easing::Quartinion;
use Algorithm::Easing::Quintonion;
use Algorithm::Easing::Sinusoidal;
use Algorithm::Easing::Backdraft;
use Time::HiRes qw(usleep);
use feature 'say';
select (STDOUT);
$|++;
sub test_ease_in {
my ($name, $ease, $max) = @_;
# total time for eased translation as a real positive integer value
my $d = 1.0;
# begin
my $b = 0;
# change
my $c = 80;
# time passed in seconds as a real positive integer between each frame
my $frame_time = 0.0025;
my ($mediator,$x,$old_x) = (Algorithm::Easing::Mediator->new(kind => $ease),0,-1);
print "\nTesting ${name} ease in.";
print "\n";
for (my $t = 0; $t <= $d + $frame_time; $t += $frame_time) {
$x = $mediator->ease_in($t,$b,$c,$d);
$x += 80 - $max;
if ($x != $old_x && $x < 80 && $x > 0) {
my ($line, $pad) = ('', '');
$line = '#' x sprintf('%i', $x);
$pad = ' ' x sprintf('%i', 80 - $x) if $x <= 80;
print "\b" x 80;
print sprintf("%s%s", $line, $pad);
usleep(sprintf("%i",$frame_time * 1000));
}
$old_x = $x;
}
print "\n";
ok(sprintf("%i",$x) >= 80,"The ${name} ease in test has completed with successful result.");
1;
}
sub test_ease_both {
my ($name, $ease, $max) = @_;
# total time for eased translation as a real positive integer value
my $d = 1.0;
# begin
my $b = 0;
# change
my $c = 80;
# time passed in seconds as a real positive integer between each frame
my $frame_time = 0.0025;
my ($mediator,$x,$old_x) = (Algorithm::Easing::Mediator->new(kind => $ease),0,-1);
print "\nTesting ${name} ease in and out.";
( run in 0.426 second using v1.01-cache-2.11-cpan-140bd7fdf52 )