# create function to calculate values

I'm writing a program that needs to determine a variable (opacity) based on a linear function of time (milliseconds elapsed during the program).

Basically, over a period of 1000 milliseconds (end_time - start_time), I need to linearly calculate an integer (opacity) that goes from 255 to 0 (start_opacity to end_opacity).

What is this type of function called? Is it "linear regression?" "linear programming?" Can Wolfram Alpha create the function? I tried this (making my imaginary milliseconds being from 951 to 1951), but it's not quite what I want.

I want a function F to calculate the opacity based on these parameters:

opacity = F (start_opacity, end_opacity start_time, current_time, end_time)

What search terms will help me figure out how to do this?

(winning answer may also explain how to do it)

-
Then your function would look like ((end_opacity-start_opacity)/(end_time-start_time))(current_time-start_time)+st‌​art_opacity... –  Ｊ. Ｍ. Aug 31 '11 at 6:21
J.M. is correct. This is called linear interpolation. –  Rahul Aug 31 '11 at 7:10
Thank you both! First one to phrase their comment in the form of an answer can get a green check. :-) –  Thunder Rabbit Aug 31 '11 at 7:28

$$\frac{y_2-y_1}{x_2-x_1}=\frac{y-y_1}{x-x_1}$$
In your case, since you wanted the line joining two points in the (time,opacity) plane, you then obtain the expression ((end_opacity-start_opacity)/(end_time-start_time))(current_time-start_time)+start_opacity. As Rahul mentions, this is sometimes termed as linear interpolation.