General Category > ASL Scripts
A new version of my water simulator script with more features!
2020 Hindsight:
OK, I didn't anticipate a new update this quick, but looking at Ian Ross's yacht image made me think that it would look better if objects in the water looked like they were interacting with the water. So here is a new script to do that, called "Combo waves". It has a new icon to avoid confusion with the "waves" script.
I considered tagging this onto the end of the "waves" topic. But I think the script is different enough to warrant starting fresh. The interface for generating random waves is identical, and you should follow the instructions posted on the "waves" post https://www.anim8or.com/smf/index.php/topic,6025.0.html.
If you don't edit the script itself then this script is indistinguishable from my "waves" script. However I have modified the code to allow wave sources to be easily added.
There are two types of wave that can be added:
1) Decaying waves: These are best for boat hulls, drips, etc.
2) Immortal waves: These never reduce in size, and are good for wind produced waves - best if they are placed outside the visible area of the mesh.
As with the original "waves" script the user can play with the run time parameters to create random weather. The values plugged into the "Parametric Plug-in Editor" only act on the randomly generated waves, not the hard coded waves (actually you can write code to read $XTiles, $YTiles, and potentially other passed variables, if you want to do clever things with your hard coded waves).
To add hard coded waves look for the following comment block in the script:
"
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Start of additional hard coded waves block
///////////////////////////////////////////////////////////////////////////////
"
Under this there are two sub sections:
"
///////////////////////////////////////////////////////////////////////////////
// Add additional hard coded non-decaying "immortal" wave origins here if required:
"
You can add as many additional wave origins as you want.
Each "immortal" wave origin is added with a line like:
$WaveOrigins.push( (0,0, 0.25, 5) );
In this example push() takes the parameter (0, 0, 0.25, 5). Which means the origin is at x=0,y=0, the wave height = 0.25, and the wave length = 5.
The second sub section is where decaying waves origins are added with a line like:
$DecayingWaveOrigins.push( (10, 20, 40, 7) );
In this example push takes the parameter (10, 20, 40, 7). Which means the origin is at X=10, and Y=20, with a height of 40, and a wavelength of 7. (Decaying waves need larger height values than immortal waves do.)
You could place it at the center of the grid with:
$DecayingWaveOrigins.push( ($XTiles/2, $YTiles/2, 40, 7) );
In this example the width and height the user sets in the "Parametric Plug-in Editor" are read from $XTiles, and $YTiles, and used to find the centre.
Another variable that may be useful is "Max wave height" stored in $MaxWaveHeight
I mark the end of the area where hard coded waves should be added with the comment block:
"
///////////////////////////////////////////////////////////////////////////////
// End of additional hard coded waves block
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
"
Have fun!
John
2020 Hindsight:
As an example of creating waves around a boat I came up with this rough and ready demonstration of a boat hull at 45 degrees. (note +0.5 on x,y to avoid big splashes):
$DecayingWaveOrigins.push( ($XTiles/2 -10.5, $YTiles/2 +10.5, 3, 3) );
$DecayingWaveOrigins.push( ($XTiles/2 -8.5, $YTiles/2 +8.5, 4, 4) );
$DecayingWaveOrigins.push( ($XTiles/2 -6.5, $YTiles/2 +6.5, 5, 5) );
$DecayingWaveOrigins.push( ($XTiles/2 -4.5, $YTiles/2 +4.5, 6, 6) );
$DecayingWaveOrigins.push( ($XTiles/2 -2.5, $YTiles/2 +2.5, 7, 7) );
$DecayingWaveOrigins.push( ($XTiles/2 -0.5, $YTiles/2 +0.5, 8, 8) );
$DecayingWaveOrigins.push( ($XTiles/2 +2.5, $YTiles/2 -2.5, 7, 7) );
$DecayingWaveOrigins.push( ($XTiles/2 +4.5, $YTiles/2 -4.5, 6, 6) );
$DecayingWaveOrigins.push( ($XTiles/2 +6.5, $YTiles/2 -6.5, 5, 5) );
$DecayingWaveOrigins.push( ($XTiles/2 +8.5, $YTiles/2 -8.5, 4, 4) );
$DecayingWaveOrigins.push( ($XTiles/2 +10.5, $YTiles/2 -10.5, 3, 3) );
2020 Hindsight:
In the code there are a couple of commented out example wave origins:
$WaveOrigins.push( (0,0, 0.25, 5) ); // Example of how to add a hard coded immortal wave, should you have a reason to do so.
This is an immortal wave starting at the bottom left with a wavelength of 5.
and
$DecayingWaveOrigins.push( ($XTiles/2, $YTiles/2, 40, 7) ); // x, y = horizontal offset, z = amplitude, w = wavelength;
This is a decaying wave starting in the centre, with a wavelength of 7.
I captured some images:
First one with the randomly generated waves + immortal waves + Decaying waves. I selected a Time to demonstrate what I mean by a "spiky spikes" in the code comments.
The second image is the same setup, but with the "Max wave height" turned down to 0, so only the hard coded waves are visible.
2020 Hindsight:
If you are having problems with decaying waves creating spikes that are too big (maybe poking through another object). You can change the script to reduce the spike size. (Originally this code was just to protect against dividing by zero.)
Lines 206,207 are an if statement:
if( $distance <= 0.1 ) // If you want big spikes change this to: if( $distance == 0 )
$distance = 0.1; // Avoid division by zero for points exactly on tile boundary
If you want smaller spikes you could modify these lines to:
if( $distance <= 0.5 )
$distance = 0.5;
If on the other hand you want to make a feature of the spikes you can increase them with:
if( $distance <= 0.001 )
$distance = 0.001;
Remember each tile is 1.0 long. The maximum spike is achieved when the wave origin is positioned on the corner of a tile (i.e. X and Y are both whole numbers). The "if" statement above bluntens spikes.
bayinghound:
Maybe a stupid question. Does this animate the waves as well?
Navigation
[0] Message Index
[#] Next page
Go to full version