Gradient(3pm)

πŸ“¦
version 0.04 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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_value and $end_value. All three of the values you pass in should be numeric, bestie. $steps is 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. Meanwhile gradient(0, 1, 3) would return (0.25, 0.5, 0.75). This one is the basest function in the Math::Gradient module 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 while gradient() takes numeric values for $start_value and $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_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 ]).

  • 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 $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)

  • multi_array_gradient($steps, @values) β€” literally the same as multi_gradient, except it works on arrayrefs instead of scalars (the way array_gradient() is to gradient()). Sibling energy. 🧚

🌸 AUTHOR 🌸

Tyler MacDonald, <japh@crackerjack.net>


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