The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tie::Cycle::Sinewave - Cycle through a series of values on a sinewave

VERSION

This document describes version 0.05 of Tie::Cycle::Sinewave, released 2007-11-07.

SYNOPSIS

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;

PARAMETERS

A number of parameters can be passed in to the creation of the tied object. They are as follows (in order of likely usefulness):

min

Sets the minimum value. If not specified, 0 will be used as a default minimum.

max

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.

period

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.

start_max

Optional. When set to 1 (or anything), the cyle will start at the maximum value. (startmax exists as a an alias).

start_min

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).

at_max

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).

at_min

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).

OBJECT METHODS

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.

min

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);
max

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.

period

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.

angle

Returns the current angle of the sine, which is guaranteed to be in the range 0 <= angle <= 2*PI.

AUTHOR

David Landgren.

SEE ALSO

 L<Tie::Cycle>
 L<HTML::Rainbow>

BUGS

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.

COPYRIGHT & LICENSE

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.