 ##      ##  #######   ########
  ##    ##   ##    ##     ##
   ##  ##    #######      ##
    ####     ##    ##     ##
     ##      ##    ##     ##
#############################################
###..THIS SCRIPT IS BY VRT:MWANDA VICENT..###
###...............2015 TUTORIALS..........###
#############################################
from mathutils import Vector as vec
from math import*
#global variables for wave system
global center,amp,length,ang,dt,f
#center of wave as 3d vector
center=vec((0,0,0))
#amplitude
amp=0.2
#wavelength
length=0.1
#angular velocity
ang=5
#small change in time
dt=0
#wave strength that determines amplitude at different points
f=20
#function to set vertex position
def posVertex(mesh,index):
   #necessary global variables
   global center,amp,length,ang,dt,f
   #wavelength
   l=length
   #vertex at the given index of mesh polygon
   vert=mesh.getVertex(0,index)
   #position of vertex in terms of 3d vector
   pos=vec((vert.XYZ[0],vert.XYZ[1],vert.XYZ[2]))
   #displacement of vertex from center as vector
   vec1=pos-center
   #distance of vertex from center as magnitude of the displacement
   d=vec1.magnitude
   #offset z-value for the vertex position
   z0=center.z
   #amplitude of point/vertex calculated basing on wave strength at
   #that point
   a=(-0.1*d+amp)/(f*d*d*d+1)
   #displacement caused wave at that point/vertex as the z-cordinate
   z=0.5*a*sin(ang*dt-2*d/l)+z0
   #update position of vertex in vector form
   pos.z=z
   #update position of vertex in list form
   vert.XYZ=[pos.x,pos.y,pos.z]
   

def main(cont):
   #necessary global variables
   global center,dt
   #object/plane object used to create the waves
   owner=cont.owner
   #obtain first mesh on the object
   mesh=owner.meshes[0]
   #center of wave obtained as position of object
   center=owner.position
   #number of vertices on object mesh
   num=mesh.getVertexArrayLength(0);
   #index of vertex
   index=0
   while(index<num):
         #now positioning vertex basing on wave properties
         posVertex(mesh,index)
         index+=1
   #update  time
   dt+=0.1
   
   
   
   