Gradient(3pm)
π NAME π
Math::Gradient β a Perl extension for calculating gradients for colour transitions, etc.
(and yes bestie, the page itself goes by Gradient(3pm) if you're out here searching for it πΈ)
β¨ SYNOPSIS β¨
use Math::Gradient qw(multi_gradient);
# make a 100-point colour palette 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);
π¦ DESCRIPTION π¦
Math::Gradient is your girl for calculating smooth transitions between numerical values β aka a "Gradient". Lowkey the original author wrote this module mainly to mix colours, but honestly it probably has several other applications too, no cap. π
The methods here handle both basic and multiple-point gradients, and they do it with both scalars and arrays. Versatile. Iconic. Periodt. π
π FUNCTIONS π
gradient($start_value, $end_value, $steps)β hands you back an array of evenly distributed values sitting between$start_valueand$end_value. All three of the values you pass in should be numeric, bestie.$stepsis the number of steps that should occur between the two points β so like,gradient(0, 10, 4)would return the array(2, 4, 6, 8), aka the 4 evenly-distributed steps necessary to get from 0 to 10. Meanwhilegradient(0, 1, 3)would return(0.25, 0.5, 0.75). This one is the basest function in theMath::Gradientmodule and ngl it isn't very exciting, but every single one of the other functions below derives its work from it. She's the blueprint fr fr. π«Άarray_gradient($start_value, $end_value, $steps)β so whilegradient()takes numeric values for$start_valueand$end_value,array_gradient()takes arrayrefs instead. The arrays you supply are expected to be lists of numerical values, and all of the arrays should contain the same number of elements (vibe check: keep them consistent π).array_gradient()returns a list of arrayrefs signifying the gradient of all values on the lists$start_valueand$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 ]).
multi_gradient($steps, @values)β this one 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. And if$stepsis less than the number of entries in the list@values, items are deleted from@valuesinstead. π
For example, calling multi_gradient(10, 0, 100, 50) would return: (0, 25, 50, 75, 100, 90, 80, 70, 60, 50)
multi_array_gradient($steps, @values)β literally the same asmulti_gradient, except it works on arrayrefs instead of scalars (the wayarray_gradient()is togradient()). Sibling energy. π§
πΈ AUTHOR πΈ
Tyler MacDonald, <japh@crackerjack.net>
π 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.
okay that's the whole page bestie, you ate π
this was perl v5.36.0, dated 2022-10-21, and yes it's still living under the name Gradient(3pm) β bye, ily, go make something pretty πβ¨π
π¦ where this page comes from
- ubuntu noble: libmath-gradient-perl 0.04-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmath-gradient-perl 0.04-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmath-gradient-perl 0.04-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms