Adding an animated text (typewriter effect) to an existing figure

Viewed 30

I wrote a piece of code for writing a message like a typewriter, as follows:


import sys,time,os
message = "hello world! \n\
First Cool message. \n\
And Second. \n"

def typewriter(message):
    for char in message:
        sys.stdout.write(char)
        sys.stdout.flush()
        
        if char !="\n":
            time.sleep(0.1)
        else:
            time.sleep(1)
        
        
#os.system('clear') #clear

typewriter(message)

Now I want to use this typewriter effect and write these characters as an animation on an imported figure. If I want to add the text to a figure and without animation I do is like bellow:

from PIL import Image
from PIL import ImageDraw

message = "hello world! \n\
First Cool message. \n\
And Second. \n"

img = Image.open('a.0000.jpeg') #Open Image

I1 = ImageDraw.Draw(img)  # Add Text to Image

I1.text((28, 36), message, fill=(255, 0, 0)) # call text


img.save("a.00001.jpeg") #Save Image

Now how can I combine this typewriter and figure and create an animated text on the figure?

0 Answers
Related