| 1 | package Term::Fabulous::Chart::Easing; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use v5.32; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use feature 'signatures'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | no warnings 'experimental::signatures'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our @EXPORT_OK = qw(easing easing_names is_easing_name); | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use constant PI => 4 * atan2( 1, 1 ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | # The "in" form of each family; "out" and "in-out" are derived from it, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # except where the classic formulas differ (back, elastic, bounce). | ||||||||||||||||||||||||||||||||||||||||||
| 19 | my %IN = ( | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sine => sub ($t) { 1 - cos( $t * PI / 2 ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | quad => sub ($t) { $t**2 }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | cubic => sub ($t) { $t**3 }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | quart => sub ($t) { $t**4 }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | quint => sub ($t) { $t**5 }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | expo => sub ($t) { $t <= 0 ? 0 : 2**( 10 * $t - 10 ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | circ => sub ($t) { 1 - sqrt( 1 - $t**2 ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | back => sub ($t) { 2.70158 * $t**3 - 1.70158 * $t**2 }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | elastic => sub ($t) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | return $t if $t <= 0 || $t >= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$t <= 0 or $t >= 1
MC/DC0%0/2
$t <= 0 or $t >= 1
$t <= 0
$t >= 1
Truth table0%0/3
A or B
A= $t <= 0B= $t >= 1
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | return -( 2**( 10 * $t - 10 ) ) * sin( ( $t * 10 - 10.75 ) * ( 2 * PI ) / 3 ); | |||||||||||||||||||||||||||||||||||||||||
| 31 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | bounce => sub ($t) { 1 - _bounce_out( 1 - $t ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub _bounce_out ($t) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bounce_out: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my ( $n, $d ) = ( 7.5625, 2.75 ); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | return $n * $t**2 if $t < 1 / $d; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | return $n * ( $t - 1.5 / $d )**2 + 0.75 if $t < 2 / $d; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | return $n * ( $t - 2.25 / $d )**2 + 0.9375 if $t < 2.5 / $d; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | return $n * ( $t - 2.625 / $d )**2 + 0.984375; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 10 | ▶ | sub _out ($in) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_out: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | return sub ($t) { 1 - $in->( 1 - $t ) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 10 | ▶ | sub _in_out ($in) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_in_out: called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | return sub ($t) { $t < 0.5 ? $in->( 2 * $t ) / 2 : 1 - $in->( 2 - 2 * $t ) / 2 }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my %EASING = ( linear => sub ($t) { $t } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | foreach my $family ( keys %IN ) { | |||||||||||||||||||||||||||||||||||||||||
| 53 | 10 | $EASING{"ease-in-$family"} = $IN{$family}; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 10 | $EASING{"ease-out-$family"} = _out( $IN{$family} ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | 10 | $EASING{"ease-in-out-$family"} = _in_out( $IN{$family} ); | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub easing_names () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
easing_names: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my @names = sort keys %EASING; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | return @names; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub is_easing_name ($name) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_easing_name: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | return defined $name && !ref $name && exists $EASING{$name} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $name and not ref $name and exists $EASING{$name}
defined $name and not ref $name
MC/DC0%0/3
defined $name and not ref $name and exists $EASING{$name}
defined $name
not ref $name
exists $EASING{$name}
Truth table0%0/4
A and not(B) and C
A= defined $nameB= not ref $nameC= exists $EASING{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub easing ($name) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
easing: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | return $EASING{ $name // '' } // croak "Term::Fabulous::Chart::Easing: unknown easing '" . ( $name // 'undef' ) . "' (known: " . join( ', ', easing_names() ) . ")"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$EASING{$name // ""} // croak(q[Term::Fabulous::Chart::Easing: unknown easing '] . ($name // "undef") . q[' (known: ] . join(", ", easing_names()) . ')')
$name // ""
$name // "undef"
MC/DC0%0/1
$EASING{$name // ""} // croak(q[Term::Fabulous::Chart::Easing: unknown easing '] . ($name // "undef") . q[' (known: ] . join(", ", easing_names()) . ')')
$EASING{$name // ""}
MC/DC0%0/1
$name // ""
$name
MC/DC0%0/1
$name // "undef"
$name
Truth table0%0/2
A
A= $EASING{$name // ""}
Truth table0%0/2
A
A= $name
Truth table0%0/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||||||||||||||||