package Chaos; #Chaos.pm - Self Contained Chaos Object #Copyright (C) 2001 Jacob T. Joaquin # #This program is free software; you can redistribute it and/or #modify it under the terms of the GNU General Public License #as published by the Free Software Foundation; either version 2 #of the License, or (at your option) any later version. # #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program; if not, write to the Free Software #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #use strict; # Constructor sub new { my $class = shift; my $self = {}; if(@_){$self->{CHAOS}=shift} else {$self->{CHAOS} = 0.5} if(@_){$self->{SEED}=shift} else {$self->{SEED} = 0.5} bless($self, $class); return $self; } # Returns next chaos value sub iterate { my $self = shift; $self->{SEED} = 2 * (1 - $self->{CHAOS} * $self->{SEED} * $self->{SEED} ); return $self->{SEED}; } # Set Amount of Chaos sub chaos { my $self = shift; if (@_) { $self->{CHAOS} = shift } return $self->{CHAOS}; } # Set Seed or Current Value sub seed { my $self = shift; if (@_) { $self->{SEED} = shift } return $self->{SEED}; } # Iterate and return a normalized value of [0.0 .. 1.0) sub normalized { my $self = shift; return ($self->iterate() + 2) / 4; } 1;