# How can I animate a vertex translation of a triangular mesh?

I have a triangular mesh in my viewport and I used this Python script to move a single vertex of the mesh (Do You know better methods? I am new to Blender and Python).

``````import bpy

obj = bpy.context.object

edge = obj.data.edges[0] #An edge, the first one

vIndex1 = edge.vertices[0] #Get the indices of the vertices of this edge
vIndex2 = edge.vertices[1]

v1 = obj.data.vertices[vIndex1] #Get the corresponding vertices
v2 = obj.data.vertices[vIndex2]

vCoord1 = v1.co #Get their coordinates
vCoord2 = v2.co

edgeVector = vCoord2 - vCoord1 #The vector formed by these two vertices

edgeVector.normalize() #So that it has 1 unit length

distance = 0.5 #Say we want to move v2 of this distance of 0.5 units

v2.co += edgeVector * distance #Translate the vertex
``````

My doubt is: how can I create the animation of this translation using scripts? This is the code to create a triangular mesh:

``````# Create a triangle mesh
import bpy

# Initialize our vertices
vert=[(0,0,0),(10,0,0),(5,10,0)]

face=[(0,1,2)]

# Create mesh and related object
my_mesh=bpy.data.meshes.new("Triangle")
my_obj=bpy.data.objects.new("Triangle",my_mesh)

# Set object location in 3D space
my_obj.location = bpy.context.scene.cursor.location

# make collection
new_collection = bpy.data.collections.new('new_collection')

# Link object to the scene collection

# Create object using blender function
my_mesh.from_pydata(vert,[],face)
my_mesh.update(calc_edges=True)
``````