r54037 - in /branches/upstream/libmath-gradient-perl: ./ current/ current/Changes current/Gradient.pm current/MANIFEST current/Makefile.PL current/README current/t/ current/t/1.t

jawnsy-guest at users.alioth.debian.org jawnsy-guest at users.alioth.debian.org
Wed Mar 10 17:40:11 UTC 2010


Author: jawnsy-guest
Date: Wed Mar 10 17:40:03 2010
New Revision: 54037

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=54037
Log:
[svn-inject] Installing original source of libmath-gradient-perl

Added:
    branches/upstream/libmath-gradient-perl/
    branches/upstream/libmath-gradient-perl/current/
    branches/upstream/libmath-gradient-perl/current/Changes
    branches/upstream/libmath-gradient-perl/current/Gradient.pm
    branches/upstream/libmath-gradient-perl/current/MANIFEST
    branches/upstream/libmath-gradient-perl/current/Makefile.PL
    branches/upstream/libmath-gradient-perl/current/README
    branches/upstream/libmath-gradient-perl/current/t/
    branches/upstream/libmath-gradient-perl/current/t/1.t

Added: branches/upstream/libmath-gradient-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-gradient-perl/current/Changes?rev=54037&op=file
==============================================================================
--- branches/upstream/libmath-gradient-perl/current/Changes (added)
+++ branches/upstream/libmath-gradient-perl/current/Changes Wed Mar 10 17:40:03 2010
@@ -1,0 +1,19 @@
+Revision history for Perl extension Math::Gradient.
+
+0.04  Fri Oct 24 16:41:44 2003
+	- still getting used to this PAUSE thing... i forgot
+		to up the version number for 0.03... sorry :-/
+
+0.03  Fri Oct 24 16:24:20 2003
+	- fixed spurious "use 5.008;" in Makefile.PL
+		(cpan #4205)
+	- fixed date for version 0.02 in ChangeLog :-)
+
+0.02  Thu Oct 23 12:02:38 2003
+	- fixed a few bits in the documentation, got rid
+		of requirement for perl 5.8.0
+
+0.01  Tue Oct 21 11:47:09 2003
+	- original version; created by h2xs 1.22 with options
+		-AX -n Math::Gradient
+

Added: branches/upstream/libmath-gradient-perl/current/Gradient.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-gradient-perl/current/Gradient.pm?rev=54037&op=file
==============================================================================
--- branches/upstream/libmath-gradient-perl/current/Gradient.pm (added)
+++ branches/upstream/libmath-gradient-perl/current/Gradient.pm Wed Mar 10 17:40:03 2010
@@ -1,0 +1,236 @@
+package Math::Gradient;
+use strict;
+use warnings;
+
+=head1 NAME
+
+Math::Gradient - Perl extension for calculating gradients for colour transitions, etc.
+
+=head1 SYNOPSIS
+
+use Math::Gradient qw(multi_gradient);
+
+# make a 100-point colour pallette to smothly transition between 6 RGB values
+
+my(@hot_spots) = ([ 0, 255, 0 ], [ 255, 255, 0 ], [ 127, 127, 127 ], [ 0, 0, 255 ], [ 127, 0, 0 ], [ 255, 255, 255 ]);
+
+my(@gradient) = multi_array_gradient(100, @hot_spots);
+
+=head1 DESCRIPTION
+
+Math::Gradient is used to calculate smooth transitions between numerical values (also known as a "Gradient"). I wrote this module mainly to mix colours, but it probably has several other applications. Methods are supported to handle both basic and multiple-point gradients, both with scalars and arrays.
+
+=head1 FUNCTIONS
+
+=over 4
+
+=item gradient($start_value, $end_value, $steps)
+
+This function will return an array of evenly distributed values between $start_value and $end_value. All three values supplied should be numeric. $steps should be the number of steps that should occur  between the two points; for instance, gradient(0, 10, 4) would return the array (2, 4, 6, 8); the 4 evenly-distributed steps neccessary to get from 0 to 10, whereas gradient(0, 1, 3) would return (0.25, 0.5, 0.75). This is the basest function in the Math::Gradient module and isn't very exciting, but all of the other functions below derive their work from it.
+
+=item array_gradient($start_value, $end_value, $steps)
+
+While gradient() takes numeric values for $start_value and $end_value, array_gradient() takes arrayrefs instead. The arrays supplied are expected to be lists of numerical values, and all of the arrays should contain the same number of elements. array_gradient() will return a list of arrayrefs signifying the gradient of all values on the lists $start_value and $end_value.
+
+For example, calling array_gradient([ 0, 100, 2 ], [ 100, 50, 70], 3) would return: ([ 25, 87.5, 19 ], [ 50, 75, 36 ], [ 75, 62.5, 53 ]).
+
+=item multi_gradient($steps, @values)
+
+multi_gradient() calculates multiple gradients at once, returning one list that is an even transition between all points, with the values supplied interpolated evenly within the list. If $steps is less than the number of entries in the list @values, items are deleted from @values instead.
+
+For example, calling multi_gradient(10, 0, 100, 50) would return: (0, 25, 50, 75, 100, 90, 80, 70, 60, 50)
+
+=item multi_array_gradient($steps, @values)
+
+multi_array_gradient() is the same as multi_gradient, except that it works on arrayrefs instead of scalars (like array_gradient() is to gradient()).
+
+=back
+  
+=cut  
+
+use 5.005;
+use strict;
+use warnings;
+
+require Exporter;
+
+sub gradient ($$$);
+sub array_gradient ($$$);
+sub multi_array_gradient ($@);
+sub multi_gradient ($@);
+
+our @ISA = qw(Exporter);
+
+# Items to export into callers namespace by default. Note: do not export
+# names by default without a very good reason. Use EXPORT_OK instead.
+# Do not simply export all your public functions/methods/constants.
+
+# This allows declaration	use Math::Gradient ':all';
+# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
+# will save memory.
+our %EXPORT_TAGS = ( 'all' => [ qw(
+	gradient array_gradient multi_gradient multi_array_gradient
+) ] );
+
+our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
+
+our @EXPORT = qw(
+	
+);
+
+our $VERSION = '0.04';
+
+
+# Preloaded methods go here.
+
+# Math::Gradient
+
+# Take sets of numbers and a specified number of steps, and return a
+# gradient for going betewen those steps
+
+# for example,
+
+# [ 2, 4, 6 ], [ 4, 8, 12 ], [ 16, 32, 48 ] with 5 steps would result in
+
+# [ 2, 4, 6 ], [ 3, 6, 9 ], [ 4, 8, 12 ], [ 10, 24, 30 ], [ 16, 32, 48 ]
+
+# This involves two distinct steps;
+# making a gradient between two points,
+# and calculating the gradient between X points.
+
+
+# To make a gradient between two points, we are given the points,
+# and the number of steps to create between them.
+
+
+# basic_gradient - get start and end number and # of steps to
+# create in-between the two. returns an array of the intermediary steps.
+sub gradient ($$$)
+{
+ my($low, $high, $steps) = @_;
+ my $xsteps = $steps + 1; # steps incl. low
+ my $xdistance = $high - $low; # distance; may be negative
+ my $step_value = $xdistance/$xsteps; # how much to add to each step to create a gradient
+ my $value = $low; # start off with the starting value
+ 
+ my @values;
+ foreach my $step (1 .. $steps)
+ {
+  $value += $step_value;
+  push(@values, $value);
+ }
+ return(@values); # we have a gradient!
+}
+
+# takes two arrayrefs, and # of steps. arrayrefs should have same number
+# of values in each.
+sub array_gradient ($$$)
+{
+ my($low, $high, $steps) = @_;
+ my(@values);
+ my $g_count = scalar(@$low);
+ foreach my $x (1 .. scalar(@$low))
+ {
+  my(@y) = (gradient($low->[$x - 1], $high->[$x - 1], $steps));
+  foreach my $y (1 .. scalar(@y))
+  {
+   $values[$y - 1] ||= [];
+   push(@{$values[$y - 1]}, $y[$y - 1]);
+  }
+ }
+ return(@values);
+}
+
+# takes a number of steps and any number of steps already filled in (at least two)
+# returns the full gradient, including supplied steps
+
+sub multi_array_gradient ($@)
+{
+ my($steps, @start_steps) = @_;
+ if($steps == scalar(@start_steps))
+ {
+  return(@start_steps); # already have the # of steps we want
+ }
+ my @values;
+ # "steppage" is how many steps we should request on average between
+ # steps we've been supplied.
+ my $steppage = ($steps - scalar(@start_steps)) / (scalar(@start_steps) - 1);
+ my $steps_left = $steps - scalar(@start_steps);
+ my $xstep = 0;
+ while(my $cstep = shift(@start_steps))
+ {
+  push(@values, $cstep);
+  $xstep += $steppage;
+  if(@start_steps && $xstep >= 1)
+  {
+   my $xxstep = int($xstep);
+   $xstep -= $xxstep;
+   $steps_left -= $xxstep;
+   push(@values, array_gradient($cstep, $start_steps[0], $xxstep));
+  }
+  elsif(@start_steps && $xstep <= 1)
+  {
+   my $xxstep = int($xstep);
+   $xstep -= $xxstep;
+   $steps_left -= $xxstep;
+   splice(@values, scalar(@values) + $xxstep, abs($xxstep));
+  }
+ }
+ return(@values);
+}
+
+sub multi_gradient ($@)
+{
+ my($steps, @start_steps) = (@_);
+ if($steps == scalar(@start_steps))
+ {
+  return(@start_steps); # already have the # of steps we want
+ }
+ my @values;
+ # "steppage" is how many steps we should request on average between
+ # steps we've been supplied.
+ my $steppage = ($steps - scalar(@start_steps)) / (scalar(@start_steps) - 1);
+ my $steps_left = $steps - scalar(@start_steps);
+ my $xstep = 0;
+ while(scalar(@start_steps))
+ {
+  my $cstep = shift(@start_steps);
+  push(@values, $cstep);
+  $xstep += $steppage;
+  if(@start_steps && $xstep >= 1)
+  {
+   my $xxstep = int($xstep);
+   $xstep -= $xxstep;
+   $steps_left -= $xxstep;
+   push(@values, gradient($cstep, $start_steps[0], $xxstep));
+  }
+  elsif(@start_steps && $xstep <= 1)
+  {
+   my $xxstep = int($xstep);
+   $xstep -= $xxstep;
+   $steps_left -= $xxstep;
+   splice(@values, scalar(@values) + $xxstep, abs($xxstep));
+  }
+ }
+ return(@values);
+}
+
+
+1;
+__END__
+# Below is stub documentation for your module. You'd better edit it!
+
+
+
+=head1 AUTHOR
+
+Tyler MacDonald, E<lt>japh at crackerjack.netE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2003 by Tyler MacDonald
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself. 
+
+=cut

Added: branches/upstream/libmath-gradient-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-gradient-perl/current/MANIFEST?rev=54037&op=file
==============================================================================
--- branches/upstream/libmath-gradient-perl/current/MANIFEST (added)
+++ branches/upstream/libmath-gradient-perl/current/MANIFEST Wed Mar 10 17:40:03 2010
@@ -1,0 +1,6 @@
+Changes
+Gradient.pm
+Makefile.PL
+MANIFEST
+README
+t/1.t

Added: branches/upstream/libmath-gradient-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-gradient-perl/current/Makefile.PL?rev=54037&op=file
==============================================================================
--- branches/upstream/libmath-gradient-perl/current/Makefile.PL (added)
+++ branches/upstream/libmath-gradient-perl/current/Makefile.PL Wed Mar 10 17:40:03 2010
@@ -1,0 +1,12 @@
+use 5.005;
+use ExtUtils::MakeMaker;
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
+# the contents of the Makefile that is written.
+WriteMakefile(
+    'NAME'		=> 'Math::Gradient',
+    'VERSION_FROM'	=> 'Gradient.pm', # finds $VERSION
+    'PREREQ_PM'		=> {}, # e.g., Module::Name => 1.1
+    ($] >= 5.005 ?    ## Add these new keywords supported since 5.005
+      (ABSTRACT_FROM => 'Gradient.pm', # retrieve abstract from module
+       AUTHOR     => 'Tyler MacDonald <faraway at c47.org>') : ()),
+);

Added: branches/upstream/libmath-gradient-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-gradient-perl/current/README?rev=54037&op=file
==============================================================================
--- branches/upstream/libmath-gradient-perl/current/README (added)
+++ branches/upstream/libmath-gradient-perl/current/README Wed Mar 10 17:40:03 2010
@@ -1,0 +1,32 @@
+Math/Gradient version 0.01
+==========================
+
+The README is used to introduce the module and provide instructions on
+how to install the module, any machine dependencies it may have (for
+example C compilers and installed libraries) and any other information
+that should be provided before the module is installed.
+
+A README file is required for CPAN modules since CPAN extracts the
+README file from a module distribution so that people browsing the
+archive can use it get an idea of the modules uses. It is usually a
+good idea to provide version information here so that people can
+decide whether fixes for the module are worth downloading.
+
+INSTALLATION
+
+To install this module type the following:
+
+   perl Makefile.PL
+   make
+   make test
+   make install
+
+COPYRIGHT AND LICENCE
+
+Put the correct copyright and licence information here.
+
+Copyright (C) 2003 Tyler MacDonald
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself. 
+

Added: branches/upstream/libmath-gradient-perl/current/t/1.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-gradient-perl/current/t/1.t?rev=54037&op=file
==============================================================================
--- branches/upstream/libmath-gradient-perl/current/t/1.t (added)
+++ branches/upstream/libmath-gradient-perl/current/t/1.t Wed Mar 10 17:40:03 2010
@@ -1,0 +1,15 @@
+# Before `make install' is performed this script should be runnable with
+# `make test'. After `make install' it should work as `perl 1.t'
+
+#########################
+
+# change 'tests => 1' to 'tests => last_test_to_print';
+
+use Test::More tests => 1;
+BEGIN { use_ok('Math::Gradient') };
+
+#########################
+
+# Insert your test code below, the Test::More module is use()ed here so read
+# its man page ( perldoc Test::More ) for help writing this test script.
+




More information about the Pkg-perl-cvs-commits mailing list