# Python Turtle – Morphing Algorithm

Tweening/Morphing effects are often used in Computer Animations to change the shape of an object by morphing an object from one shape into another.

In tweening, key frames are provided and “in-between” frames are calculated to make a smooth looking animation.

In this blog post we will implement a tweening algorithm to morph a letter of the alphabet (e.g. “A” into another letter “Z”) using a linear interpolation.

We will consider a letter as being a list of connected nodes (dots) where each dot has its own set of (x,y) coordinates. #### Linear Interpolation Formulas: Using the following linear interpolation formulas we can calculate the (x,y) coordinates of each dot for any “in-between” frame.

x(t) = xA + (xZ – xA) * t / 10
y(t) = yA + (yZ – yA) * t / 10
• “t” represents the time: in other words the frame number (e.g. between 0 and 10)
• (xA,yA) the coordinates of a node/dot from the starting letter (e.g. A)
• (xZ,yZ) the coordinates of a node/dot from the ending letter (e.g. Z)

Using these formulas we can see that:

x(0) = xA
y(0) = yA
x(10) = xZ
y(10) = yZ

Our tweening algorithm will need to apply these formulas to each node of the letter.