Math-SegmentedEnvelope
view release on metacpan or search on metacpan
bench/PurePerl.pm view on Meta::CPAN
if ($at > $total) {
if ($self->is_fold_over && int($at/$total) % 2 == ( $t < 0 && $self->is_wrap_neg ? 0 : 1 )) {
( 1 - ( ($at / $total) - int($at / $total) ) ) * $total;
} else {
( ($at / $total) - int($at / $total) ) * $total;
}
} else { $at }
};
}
sub update_current_segment {
my ($self, $i) = @_;
$i = $self->_current_segment(defined($i) ? $i : ());
$self->_level_diff($self->level($i+1) - $self->level($i));
$self->_is_neg($self->curve($i) < 0 ? 1 : 0);
$self->_is_asc($self->_level_diff < 0 || $self->_is_neg ? -1 : 1);
$self->_past_segment($i);
}
sub level {
my $self = shift;
eg/70-rolling-balls.pl view on Meta::CPAN
};
}
}
spawn_balls();
# Pre-compute slope data
my $slope_samples = 200;
my @slope_heights;
my @slope_gradients;
sub update_slope {
my $e = $slopes[$current_slope];
my $d = $e->duration;
my $s = $e->static;
my $deriv = $e->resample($slope_samples)->derivative->static;
my $dd = $e->resample($slope_samples)->derivative->duration;
@slope_heights = ();
@slope_gradients = ();
for my $i (0 .. $slope_samples) {
my $t = $i / $slope_samples;
push @slope_heights, $s->($t * $d);
( run in 0.478 second using v1.01-cache-2.11-cpan-85d3896f969 )