Mathematical equation for calculating various speeds for an animation of attenuation

I am trying to add a fade effect to my form by manually changing the opacity of the form, but I am having trouble calculating the correct value to increase the opacity of the form.

I know that I could use the AnimateWindow API, but it showed some unexpected behavior, and I would prefer to do it manually anyway, to avoid any p / invoke, so I can use it in Mono later.

My application supports speeds from 1 to 10. And I manually calculated that for speed 1 (the slowest) I should increase the opacity by 0.005 and for speed 10 (faster) I should increase by 0.1. As for speeds from 1 to 10, I used the following expression to calculate the correct value:

double opSpeed = (((0.1 - 0.005) * (10 - X)) / (1 - 10)) + 0.1; // X = [1, 10] 

Although it can give me a linear meaning and that everything will be alright. However, for X equal to 4 and above, this is already too fast. More than it should be. I mean, the speed is from 7 to 10, I can hardly see the difference, and the speed of the animation with these values ​​should be a little more spaced.

Please note that I still want the fastest growth of 0.1 and the slowest 0.005. But I need everyone else to be linear between them.

What am I doing wrong?

EDIT: It actually makes sense why this works, for example, for a fixed interval between increments, say, a few milliseconds and with the above equation, if X = 10, then opSpeed ​​= 0.1, and if X = 5, then opSpeed = 0.47. If we think about it, the value 0.1 will depend 10 times, and the value 0.47 will loop on the double. For such a small interval of just a few milliseconds, the difference between these values ​​is not so much that they differentiate speeds from 5 to 10.

+4
source share
5 answers

I think what you want is:

 0.005 + ((0.1-0.005)/9)*(X-1) 

for X from 1 to 10

This gives a linear scale corresponding to 0.005 at X = 1 and 0.1 at X = 10

After the comments below, I also included my answer, suitable for a geometric series instead of linear scale.

 0.005 * (20^((X-1)/9))) 

The result is a geometric deviation corresponding to 0.005 for X = 1 and 0.1 for X = 10

After much more discussion, as can be seen from the comments below, the updates are as follows.

@Nazgulled found the following relationship between my geometric series and the manual values ​​that he really needed to provide a smooth fading animation.

The relationship was as follows: I β™₯ Graphs! :)

This means that the geometric / exponential series is the way to go.

After hours of trying to find the right curve that fits the right graph and get the right equation, @Nazgulled informed me that Wolfram | Alpha does it. Seriously amazing. :)

Wolfram alpha link

He should have what he wants now, eliminating a very high error from the equation above.

+6
source

Your problem is that the human eye is not linear in its answer; to be precise, the eye does not register a difference between brightness from 0.05 to 0.10 to be the same as a brightness difference between 0.80 and 0.85. The whole topic is complicated; you can find the phrase "gamma correction" for more information. In general, you probably want to find an equation that is effectively gamma corrected for the human eye response and use it as a function of fading.

+4
source

This is not quite the answer, but I will simply point out that everyone who has written so far, including the original question, is publishing the same equation. Thus, with four independent conclusions, perhaps we should assume that the equation was probably correct.

I made algebra, but here is the code to check (in Python, by the way, with offsets added to separate the curves:

 from pylab import * X = arange(1, 10, .1) opSpeed0 = (((0.1 - 0.005) * (10 - X)) / (1 - 10)) + 0.1 # original opSpeed1 = 0.005 + ((0.1-0.005)/9)*(X-1) # Suvesh opSpeed2 = 0.005*((10-X)/9.) + 0.1*(X-1)/9. # duffymo a = (0.1 - 0.005) / 9 #= 0.010555555555... # Roger b = 0.005 - a #= -0.00555555555... opSpeed3 = a*X+b nonlinear01 = 0.005*2**((2*(-1 + X))/9.)*5**((-1 + X)/9.) plot(X, opSpeed0) plot(X, opSpeed1+.001) plot(X, opSpeed2+.002) plot(X, opSpeed3+.003) plot(X, nonlinear01) show() 

In addition, at the request of Nazgulled, I included a non-linear curve proposed by Suves (which, incidentally, is also very similar to the gamma correction curve, as suggested by McWafflestix). Suvesh non-linear equation is in code as nonlinear01 .

alt text

+2
source

This is how I will program this linear relationship. But first, I would like to clarify what I think you are doing.

You want the rate of change in opacity to be a linear function of speed:

o (v) = o1 * N1 (v) + o2 * N2 (v), so 0 <= v <= 1 and o (v1) = o1 and o (v2) = o2.

If we choose N1 (v) equal to 1-v and N2 (v) = v, we get what you want:

o (v) = o1 * (1-v) + o2 * v

So, include your values:

v = (u-1) / (10-1) = (u-1) / 9

o1 = 0.005 and o2 = 0.1

So the function should look like this:

  • o (u) = 0.005 * {1- (u-1) / 9} + 0.1 * (u-1) / 9
  • o (u) = 0.005 * {(9-u + 1) / 9} + 0.1 * (u-1) / 9
  • o (u) = 0.005 * {(10-u) / 9} + 0.1 (u-1) / 9

You can simplify this until you get a simple formula for o (u), where 1 <= u <= 10. This should work fine.

+1
source

If I understand what you need, you need a line equation that goes through these two points in the plane: (1, 0.005) and (10, 0.1). The general equation for such a line (as long as it is not vertical) is y = ax + b. Connect two points to this equation and resolve the resulting set of two linear equations to get

  a = (0.1 - 0.005) / 9 = 0.010555555555... b = 0.005 - a = -0.00555555555... 

Then for each integer x = 1, 2, 3, ..., 10, connect x to y = ax + b to calculate y, the value you want.

+1
source

Source: https://habr.com/ru/post/1286038/


All Articles