4.9.3.1 sine - sin( x )

We use the sine function in this example to animate the Y position of the sphere. The sine function in Xpressionist assumes the argument to be in degrees. We use time * 90 as an argument for the sine functions because we want the argument to create angle values between 0 and 360 in four seconds - like one full rotation:

sphere.YPosition = sin( time * 90 );

We preview the result:

Since the sine function is a trigonometric function it returns the sine of an angle of a triangle within a circle. The sine of any angle is a value between 1 and -1. When the angle is 0° the sine is 0. If the angle is 90° the sine is 1. When the angle is 180° the sine returns 0 again, and when the angle is 270° the sine is -1. When the argument of this function is a rotation of 360° the function will return one period of a sinevave with an amplitude of 1. In our example the function returns one period of a sinewave in four seconds.

In the second example we have added a "clock" to show the relationship between the sine function and rotation angles. The pointer shows the angle to the X axis. Note that the tip of the pointer has always the same Y position value as the sphere:

Click on the image to play the movie.

We can control different aspects of the wave form when we modify the sine function with offset values. With this we can shape frequency, amplitude, shift and phase of the sine wave. In our example we used the argument time * 90 to get the desired sine. By multiplying time with 90 we have actually edited the frequency of our wave. The frequency in our example is 0.25 Hz which is one cycle in four seconds. The abstract form can be written like this:

A = frequency modifier value;
B = amplitude modifier value;
C = shift modifier value;
D = phase modifier value;

wave = sin( time * A + D ) * B + C;

We can increase the frequency when we increase the frequency modifier value:

sphere.YPosition = sin( time * 360 );

Now we will get 4 complete periods of sine waves beause it will oscillate with 1Hz - once in a second.

We can edit the amplitude of the wave by multiplying the function with an amplitude modifier value:

sphere.YPosition = sine( time * 360 ) * 0.5;

Since we have multiplied the result of the function with 0.5 the resulting amplitude is only half as high:

We can edit the placement of the wave on the Y axis by adding a shift modifier value:

sphere.YPosition = sine( time * 360 ) * 0.5 + 1;

Since we add 1 to the result of the function the wave shifts one unit in Y:

We can edit the phase of the wave by adding a phase modifier value:

sphere.YPosition = sine( time * 360 + 90 ) * 0.5 + 1;

This shifts the phase 90° to the left:

Every modifier value can also be a custom variable. This means that you can dynamically change every aspect of the sine wave. This can be used in various applications, which range from blinking, bouncing to even organic movement like the swinging of bird wings or even wlak cycles.

Read also the Quickstart section about the sine function.

Xpressionist 3.5