Anim8or Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

Ian Ross has just released a book on Anim8or. It's perect for a beginner and a good reference for experienced users. It contains detailed chapters on every aspect, with many examples. Get your own copy here: "Anim8or Tutorial Book"

Author Topic: I have written a script to simulate waves.  (Read 14925 times)

2020 Hindsight

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
I have written a script to simulate waves.
« on: November 13, 2020, 03:56:50 pm »

Description of the script:

To understand what the script is doing, imagine it is firing a shotgun into the water to generate waves. To get a pleasing scene you can play around with the parameters (draw a "Waves" object on the screen, then double click on it to bring up the "Parametric Plug-in Editor").

Parameters:
 
The larger the area the better the waves look, but the slower the software will run. I recommend setting the X Tiles and Y Tiles parameters to about 100.

"Scale" (I removed the Y-Scale and Z-scale parameter so that I could add "wave direction" and "Time". The X,Y, and Z Scale are now all set to "Scale".) If you want bigger/smaller waves you can change "Max wave height").

The "Seed" parameter is the random number generator seed value. If you don't like what you see, plug in a different random number into this field. Some numbers seem to be quite good seeds. I keep returning to 25637.

"Wave origin count": You can think of this parameter as how many pellets there are in the shotgun cartridge.

Expanding on the shotgun analogy, each pellet produces waves of different height, and frequency.  These are assigned randomly, guided by the following parameters:

"Max wave height": This is used to control the height of waves. This is usually best set to a value close to 1.

(Note: the unit of distance used by "Mean wavelength", and "Min wave distance" are in terms of the length of a tile side.)

"Mean wavelength": Waves are set to a random wavelength around this value.

The "Min wave distance" is basically where you target the shotgun. So some "pellets" land closer than the "min" distance - perhaps that should be renamed. The distance is measured from the center of the mesh. If you set this to 0 you can see what the "shotgun blast" looks like.

"Wave direction"  This sets where to aim the "shotgun" around the mesh in degrees (0 = 12 O'clock). Think of this in conjunction with "minimum wave distance".

"Time" This field allows animation of the water. Increasing this by 1 moves the waves by one tile length. (You can get a feel of it by advancing the time by 10, and shift-Tab, Tab, to modify the field again.)


There are a few tweaks that can be made to the script:
Originally "Wave direction" was assigned at random. This functionality can be restored by changing line 93 to: $dominantAngle = PI * frand();

With the script as it stands waves never get weaker no matter how far they are from their source. This can be changed by commenting out line 133, and uncommenting line 134. You can then get drip effects. Note that you will need to set  "Max wave height" to much bigger values than with the unmodified script, otherwise you may think the script isn't working.

In the real world long waves move faster than short waves, but I'm not sure by what ratio. In this script I have all waves advancing at the same speed. The code for this is on line 128, if you comment that line out, and un-comment line 129, the waves move according to their wavelengths.

P.S. This is my first post on this forum, it is Friday the 13th, and it's 2020 - what can go wrong?
Logged

2020 Hindsight

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: I have written a script to simulate waves.
« Reply #1 on: November 13, 2020, 03:58:57 pm »

An example image
Logged

2020 Hindsight

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: I have written a script to simulate waves.
« Reply #2 on: November 13, 2020, 04:05:44 pm »

"Flat Shaded" version of the same image + an image with different wave parameters.
Logged

2020 Hindsight

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: I have written a script to simulate waves.
« Reply #3 on: November 13, 2020, 04:10:06 pm »

The script's icon:
Logged

2020 Hindsight

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: I have written a script to simulate waves.
« Reply #4 on: November 14, 2020, 06:04:13 am »

This is an example of what the decay modification looks like (by commenting out line 133, and uncommenting line 134).

Note: Is there a bug in how Anim8or scans script files? Does it truncate file names? To create this image, I saved the modified version as "animated_waves_V1-01.a8s", and modified the icon so I didn't confuse it with the original "animated_waves.a8s". When I launched Anim8or both icons were there, but both icons ran the "animated_waves.a8s" script, I only got the decay effect when I changed the original to a .txt file! I have used the multiple file approach while debugging the code, and it has always worked but I was using shorter file names.
Logged

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 2125
    • View Profile
Re: I have written a script to simulate waves.
« Reply #5 on: November 14, 2020, 06:27:29 am »

I'll look into this, Hindsight. Nice script!
Logged

2020 Hindsight

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: I have written a script to simulate waves.
« Reply #6 on: November 14, 2020, 07:45:06 am »

Thanks!
I'm running version 1.00 of Anim8or. "29-May-17"
Logged

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 2125
    • View Profile
Re: I have written a script to simulate waves.
« Reply #7 on: November 14, 2020, 10:50:17 am »

2020 Hindsight What's happeneing is that Anim8or uses the plug-in script defined name, not the file name, to connect the objects in a project to a script file. This is the third argment in the #plugin psudo command in the script:

#plugin("object", "mesh", "Waves");

If two or more scripts use the same name Anim8or can't tell which one to use so it uses the first one in found.
Logged

2020 Hindsight

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: I have written a script to simulate waves.
« Reply #8 on: November 14, 2020, 11:28:10 am »

Useful to know!

Thinking about it, when I was debugging I did change the name given to #plugin() to avoid confusing myself.

Thanks!
Logged

ianross

  • Sr. Member
  • ****
  • Posts: 251
  • Imagination is the elixir of life.
    • View Profile
    • https://www.tradebit.com/filedetail.php/164976574-part-1-anim8or-tutor-course
Re: I have written a script to simulate waves.
« Reply #9 on: November 16, 2020, 09:13:28 am »

Thank you Hindsight this is a good script. Great!!! now we can create water with a script.






Logged

ianross

  • Sr. Member
  • ****
  • Posts: 251
  • Imagination is the elixir of life.
    • View Profile
    • https://www.tradebit.com/filedetail.php/164976574-part-1-anim8or-tutor-course
Re: I have written a script to simulate waves.
« Reply #10 on: November 16, 2020, 09:22:28 am »

Also I created this.I really like this script. Thank you again.



« Last Edit: July 18, 2022, 05:41:08 am by ianross »
Logged

2020 Hindsight

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: I have written a script to simulate waves.
« Reply #11 on: November 16, 2020, 11:47:45 am »

Those reflections look great Ian!

It is tempting to hard code some extra wave origins in the script, to correspond with the boat's hull. It wouldn't be hard to have a mix of decaying waves and the standard immortal waves.
Logged

2020 Hindsight

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: I have written a script to simulate waves.
« Reply #12 on: November 17, 2020, 03:09:32 pm »

So tempting that I have posted a new script to do that!

Get it here: https://www.anim8or.com/smf/index.php/topic,6029.0.html
Logged