Twaining a value in Lua

How can I do it? I want to change the time from one to the other at a time. Bearing in mind also that it would be nice to have "lightness" at the beginning and at the end.

I know I shouldn't really be asking, but I tried myself and I got stuck. Suppose that in order to trigger the delay, you need to call the wait (time) function.

+1


a source to share


2 answers


One simple approach that might work for you is unit circle interpolation: Unit circle

To do this, you simply evaluate the points along the circle, which provides a fairly smooth movement as well as lightness and lightness. You can control the speed of the interpolation by changing how quickly you change the angle.

Assuming you are doing one-dimensional interpolation (i.e. simple scalar interpolation like 3.5 to 6.9 or whatever), it would be convenient to use the Y values ​​from -spi; / 2 to π / 2. They are given by the sine function, all you have to do is apply the appropriate scaling:



angle = -math.pi / 2
start = 3.5
end = 6.9
radius = (end - start) / 2
value = start + radius + radius * math.sin(angle)

      

I'm not 100% sure if it's legal Lua, haven't tested it. If not, it is probably trivial to convert.

+4


a source


You can have a look at the Tweener ActionScript library for inspiration.

For example, you can take the required equations here .



If you need more help, please ask.

0


a source







All Articles