For details, see How to Use.
Wave Interference Animation (Two Sine Waves on a Line)
This is a simple simulator developed in VCSSL to visualize the interference between sine waves traveling along a one-dimensional line.
In the previous article, we focused on the animation of a single sine wave. This article continues from there. If you're not yet familiar with what a sine wave is, please refer to that article first. Here, we'll superimpose two sine waves and animate how they interfere with each other.
[ Related Article ]
- Previous: Sine Wave Animation
Sponsored Link
How to Use
Download and Extract
At first, click the "Download" button at the above of the title of this page by your PC (not smartphone). A ZIP file will be downloaded.
Then, please extract the ZIP file. On general environment (Windows®, major Linux distributions, etc.), you can extract the ZIP file by selecting "Extract All" and so on from right-clicking menu.
» If the extraction of the downloaded ZIP file is stopped with security warning messages...
Execute this Program
Next, open the extracted folder and execute this VCSSL program.
For Windows
Double-click the following batch file to execute:
For Linux, etc.
Execute "VCSSL.jar" on the command-line terminal as follows:
java -jar VCSSL.jar
» If the error message about non-availability of "java" command is output...
After Launching the Program
When the program starts, you'll be asked whether to input numerical values for the wave parameters. If you don't have a specific need like "setting the wavelength to exactly this value," it's fine to just skip this by choosing "No."
Then, two windows will appear: a graph window and a parameter setting window.

In the graph window, the sine waves are animated.
The red and blue curves represent the two individual waves (Wave A and Wave B) to be superimposed. The green curve represents the resulting composite wave formed by their interference. In the parameter setting window, you can adjust values such as the amplitude, wavelength, and period independently for each wave using sliders.
Closing either window will terminate the program.
If it's hard to tell apart Wave A (red) and the composite wave (green), you can change their colors freely by selecting Edit > Set Color from the menu at the top of the graph window.
In the color settings window, Series No.1 corresponds to Wave A, No.2 to Wave B, and No.3 to the composite wave. For example, if you set No.3 to "BLACK", the composite wave will be drawn in black instead of green.

Concept Overview
When multiple waves are superimposed, the resulting wave often takes on a shape (and motion) that is quite different from the original waves. This phenomenon is called interference.
For example, sine waves follow the shape of the sin function. When two sine waves with slightly different wavelengths are superimposed, a distinctive pattern appears: areas of large amplitude and small amplitude (even close to zero) alternate along the x-axis. The result looks like a distorted sine wave, as shown by the green curve below:

( Wave A: A=1.0, ă=0.35, T=1.0 Wave B: A=1.0, ă=0.4, T=1.0 )
If the periods are different instead, the amplitude changes over time even at the same position along the x-axis. This is known as a beat phenomenon.

( Wave A: A=1.0, ă=0.4, T=2.0 Wave B: A=1.0, ă=0.4, T=1.0 )
When both wavelength and period differ, you can observe the unique pattern along the x-axis shifting over time.

( Wave A: A=1.0, ă=0.35, T=1.0 Wave B: A=1.0, ă=0.4, T=0.5 )
What's especially interesting is that the pattern of amplitude variation (the envelope) and the distorted sine waves within it generally move in different directions and at different speeds. The speed of the envelope is called the group velocity, while the speed of the inner waves is called the phase velocity.
The phase velocity also applies to single sine waves -- it's simply the speed of the wave itself. For composite waves made from two similar sine waves, the phase velocity is almost the same as that of the originals.
In contrast, the group velocity depends on the ratio of the differences in wavelength and period (or, equivalently, the difference in wave number and angular frequency). If you superimpose a continuous spectrum of many waves with varying wavelengths and periods, the ratio becomes a derivative instead of a simple difference.
Sponsored Link
Code
This program is written in VCSSL.
Here, we'll briefly explain the contents of the code. Since VCSSL uses a simple C-like syntax, it should be relatively easy to read for anyone who has experience with C or similar languages.
If you'd like to customize this program -- such as changing the graph range or making other modifications -- you can open the source file SineWave.vcssl in any text editor and edit it directly. Since VCSSL is a scripting language, no compiler or external software is needed: simply modify the code and run it.
Full Code
Let's first take a look at the entire code:
That's it. It's a short program, a bit over 300 lines. Most of the logic is already explained in the inline comments within the code itself, but in this section, we'll walk through the main parts in more detail.
This program is largely based on the code from the previous article, Sine Wave Animation. The main difference is that now we're working with two sine waves instead of one, and the code has been slightly extended to accommodate that.
So if you're new to the basic structure, we recommend reviewing the earlier code first.
Below, we'll focus on the parts that have changed since the previous version.
Variable Declarations
At the beginning of the program, variables are declared-just like in the previous version. The key difference is that now we have two waves, so parameters and slider controls are prepared separately for Wave A and Wave B.
One notable change is the arrays used to store coordinate data for plotting. Previously, we only needed 1D arrays, but now we use 2D arrays:
This is because we now need to pass multiple data series to the graph. The first dimension (the leftmost one) corresponds to the different wave series: Wave A, Wave B, and the composite wave, totaling three.
The second dimension is for the individual data points within each wave, same as before. Each series contains N points, which are connected by lines in the graph.
Assigning Wave Data and Plotting in the main Function
Now let's look at the part inside the animation loop in the main() function where wave data is calculated and passed to the graph:
This block is inside the animation loop, so you can think of it as drawing one frame of the graph at a specific time "t". By incrementally increasing t and repeatedly running this loop -- like a flipbook -- the graph appears animated.
For Wave A and Wave B, the logic is essentially the same as in the previous program: We compute the Y-value of a sine wave at each small step along the X-axis using the formula:
\[ y = A \sin 2 \pi \bigg( \frac{t}{T} - \frac{x}{\lambda} \bigg) \] Then we store those X and Y values into arrays. The graphing software connects the dots automatically to form the wave shapes.The next part is the composite wave, which we calculate by simply adding the Y-values of Wave A and Wave B at each point. It may seem almost too simple, but for typical physical waves, this approach works accurately thanks to the principle of superposition, which holds well in everyday scenarios.
In other words, this program assumes a perfectly ideal case where the principle of superposition holds precisely.
Note: Of course, there are situations where superposition doesn't hold this simply. In such cases, you can't just add the wave values directly. Instead, you'd typically start with a predefined composite wave and use numerical methods to solve the time-evolution differential equations to simulate how it evolves over time.
Other Parts
The rest of the code is a straightforward extension of the previous version. Sliders and controls are added for the two separate waves, but no major structural changes were made.
That's all for the code explanation!
License
The license of this VCSSL / Vnano code (the file with the extension ".vcssl" / ".vnano") is CC0 (Public Domain), so you can customize / divert / redistribute this VCSSL code freely.
Also, if example code written in C/C++/Java are displayed/distributed on Code section of this page, they also are distributed under CC0, unless otherwise noted.
Wave Interference Animation (Two Sine Waves on a Line) |
|
![]() |
Interactive simulation of wave interference between two 1D sine waves. |
Circular Wave Animation |
|
![]() |
Draws the circular wave as 3D animation, under the specified wave parameters. |
Sine Wave Animation |
|
![]() |
Interactive simulator for animating sine waves with adjustable parameters. |
Vnano | Solve The Lorenz Equations Numerically |
|
![]() |
Solve the Lorenz equations, and output data to plot the solution curve (well-known as the "Lorenz Attractor") on a 3D graph. |