Tie::Cycle::Sinewave - Cycle through a series of values on a sinewave
This document describes version 0.05 of Tie::Cycle::Sinewave, released 2007-11-07.
This module allows you to make a scalar iterate through the values on a sinewave. You set the maximum and minimum values and the number of steps and you're set.
use strict; use Tie::Cycle::Sinewave; tie my $cycle, 'Tie::Cycle::Sinewave', { min => 10, max => 50, period => 12, }; printf("%0.2f\n", $cycle) for 1..10;
A number of parameters can be passed in to the creation of the tied object. They are as follows (in order of likely usefulness):
Sets the minimum value. If not specified, 0 will be used as a default minimum.
Sets the maximum value. Should be higher than min, but the values will be swapped if necessary. If not specified, 100 will be used as a default maximum.
Sets the period of the curve. The cycle will go through this many values from min to max. If not specified, 20 will be used as a default. If period is set to 0, it will be silently changed to 1, to prevent internal calculations from attempting to divide by 0.
Optional. When set to 1 (or anything), the cyle will start at the maximum value. (startmax exists as a an alias).
startmax
Optional. When set to 1 (or anything), the cyle will start at the minimum value. (startmin exists as a an alias). If neither start_max nor start_min are specified, it will at the origin (thus, mid-way between min and max and will move to max).
startmin
start_max
start_min
Optional. When set to a coderef, will be executed when the cycle reaches the maximum value. This allows the modification of the cycle, e.g. modifying the minimum value or the period. (The key atmax exists as an alias).
atmax
Optional. When set to a coderef, will be executed when the cycle reaches the minimum value. This allows the modification of the cycle, e.g. modifying the maximum value or the period. (The key atmin exists as an alias).
atmin
You can call methods on the underlying object (which you access with the tied() function). Have a look at the file eg/callback for an example on what you might want to do with these.
tied()
eg/callback
When called without a parameter, returns the current minimum value. When called with a (numeric) parameter, sets the new current minimum value. The previous value is returned.
my $min = (tied $cycle)->min(); (tied $cycle)->min($min - 20);
When called without a parameter, returns the current maximum value. When called with a (numeric) parameter, sets the new current maximum value. The previous value is returned.
my $max = (tied $cycle)->max(); (tied $cycle)->max($max * 10);
When min or max are modified, a consistency check is run to ensure that min <= max. If this check fails, the two values are quietly swapped around.
min
max
min <= max
When called without a parameter, returns the current period. When called with a (numeric) parameter, sets the new current period. The previous value is returned.
Returns the current angle of the sine, which is guaranteed to be in the range 0 <= angle <= 2*PI.
0 <= angle <= 2*PI
David Landgren.
L<Tie::Cycle> L<HTML::Rainbow>
Please report any bugs or feature requests to bug-tie-cycle-sinewave@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Tie-Cycle-Sinewave.
bug-tie-cycle-sinewave@rt.cpan.org
Copyright 2005-2007 David Landgren, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Tie::Cycle::Sinewave, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::Cycle::Sinewave
CPAN shell
perl -MCPAN -e shell install Tie::Cycle::Sinewave
For more information on module installation, please visit the detailed CPAN module installation guide.