A simple interference effect with Java
For me this effect is a kind of a "hello world" program. Whenever i learned a new language i implemented it. Starting with Pascal, moving to C and inevitably ending as an applet once i gave Java a try.
Physically there is no meaning behind it. It's nonsense (apart from the interference), but it's nice to watch anyway. The setup is simple: Take a bunch of sources that have a "static" wave field attached to them. Move them randomly across a 2D field and sum up the values of all wave fields for each pixel. Let the sources bounce back from walls and you are done.
I took a few measures in order to speed the animation up:
- The 2d-sinus waves are pre-calculated reducing the number of mathematical operations to width*height additions per frame.
- For each frame the color of every pixel is compared to the corresponding color of this pixel in the previous frame. If they are equal no new pixel will be drawn.
- Single frames consist only of even or odd colums of pixels, swapping with each frame. (This was done in order to reduce the amount of pixels to be drawn for each single frame without reducing the resolution further)
- Note: The code is old! Especially the drawing code is terribly uneffective due to drawing each pixel seperately you shouldn't take it as a reference.
Download and Useage
Download jar file
Download source code
(requires Netbeans)
In order to use the applet add the following lines to your html code:
<object classid="java:intring/intring.class" type="application/x-java-applet" width="300" height="300">
<param name="archive" value="JIntring.jar"/>
<param name="code" value="intring/intring.class"/>
<param name="pixsize" value="1"/>
<param name="sleep" value="15"/>
<param name="damping" value="0.01"/>
<param name="src_num" value="4"/>
</object>
The following table lists the applet parameters and their meaning.
| Parameter | Meaning |
|---|---|
| pixsize | The size of a pixel |
| sleep | time to wait after each frame (in milli seconds) |
| damping | The damping factor for the sine waves |
| src_num | The number of sources |
| preview | If this value is true the applet looks like an image only moving when the mouse is over the applet. |