We are about to switch to a new forum software. Until then we have removed the registration on this forum.
My math skills have faded with my hair color, I'm afraid. I need a function that produces a downward curve. For example, I will send it integers from 255-0. This is for a fading effect, the numbers are transparency values. I want it to fade quickly at first then to fade more slowly as it gets closer to zero. Ideally I'd like some control over the steepness (or "curviness") of the curve.
Suggestions? :)
--Darin
Answers
An alternative approach using a class to generate next opacity value: $-)
Online version: https://OpenProcessing.org/sketch/450448
@darinb --
Non-linear curve-based interpolation along a single dimension based on control values is already built-in to Processing in curvePoint() and bezierPoint().
You can use it like this:
So, if I want values 0-255 and I'm exerting 300 worth of control to the 'out' end of the curve (making it more shallow), then:
...where
t
is a time-based value 0-1.0 and the return is 0-255 along that time curve.I find curve-based interpolation easier to use if I wrap it in a helper function that makes the arguments easier to understand:
So:
To see it in action, check out this demo sketch:
If you are interested in understanding how the
bezierPoint()
1D process relates to 2D Bezier curves, watch this sketch, then try pressing 'i' / 'o' to turn on and off the in and out control steppers:Wow--what a great forum. Not only is my question answered but I've learned about the map function, an object version (still trying to get a handle on object code), and a mini-course on bezier curves in Processing and how to use them. Really outstanding. You should add this to the documentation.....
Really, thanks to everyone. I'm so glad I found Processing (after a bit of a struggle with pyGame) and so glad this forum is here.
--Darin
I also had some fun trying to understand bezier creation...
try running this
That's a very cool Bezier demo, @_vk !
One thing to keep in mind about the original question about time interpolation is that it is 1D, not 2D -- you put the time and some parameters into a single
bezierPoint()
call, not two calls, and the value you get back could be considered the x component only of a complex curve -- it is a non-linear value distribution that uses the x components of the control "points", here just control values.Thanks @jeremydouglass. Good point.
O.K., I'm still trying to understand this--thought I did but I'm getting unexpected results. I put together a slightly modified version of jeremydouglass' code (his first example)--but I'm getting negative numbers initially coming out of the cerp function--which doesn't make sense to me.
The results of the cerp function start out slightly negative then turn around an go in the correct (positive) direction.
Here is what I have to test--the first line of the output in the raw result of the cerp function.
My guess here is that the third parameter in the cerp function might be not what I want? As I understand it (perhaps dimly), the third and fourth parameter are specifying a point, forcing the curve to go through that point on its way from the begin point and end point (thus the Bezier curve). So is having that point at zero on the x-axis forcing the beginning of the curve into negative territory?
Or....? :)
--Darin
Your max value is 255. Your out control is 300. That's probably not what you want -- if you don't want your values to go negative, the max out control you want is 255.
See this illustration from the demo sketch I shared above. Out (the orange line, 350) is greater than the range of min-max values (0-255), which causes the curve to become concave like a C.
Compare out control set = 255.
And of course, this is with a small out control value, = 128.
Got it working and I understand it now. Thanks!
--Darin