Built-in interpolation functions
djrrb last edited by gferreira
I’m curious if you think there is value in adding interpolation functions to DrawBot, similar to
I understand it’s not good to bloat the initial state, and perhaps this is better handled by an external package. (Or maybe there is already a built-in way to deal with this that I don’t know about?)
Interpolation plays such a big part in so many of my scripts and those I create with my students, and I have cut and pasted the code below into so many of my DrawBot scripts that I felt moved to write this post and ask.
In case you are interested, I am happy to contribute the code I use. It uses the same syntax as Processing, except that
remap()is used to avoid conflict with the Python
Thank you, as always
# Released by DJR under the BSD license def lerp(start, stop, amt): """ Return the interpolation factor (between 0 and 1) of a VALUE between START and STOP. https://processing.org/reference/lerp_.html """ return float(amt-start) / float(stop-start) def norm(value, start, stop): """ Interpolate using a value between 0 and 1 See also: https://processing.org/reference/norm_.html """ return start + (stop-start) * value def remap(value, start1, stop1, start2, stop2, withinBounds=False): """ Re-maps a number from one range to another. """ factor = lerp(start1, stop1, value) if withinBounds: if factor < 0: factor = 0 if factor > 1: factor = 1 return norm(factor, start2, stop2)
could you move this topic to a github issue?
djrrb last edited by