Python Animation Tutorial-EASY!
Hey! This is SilvermoonCat :D
print("Python Animation Tutorial")
Let's learn how to make python animations today-- it's pretty easy, so anyone will understand!
First, get a blank repl in python set up.
IN there, add a folder and name it
frame (can be modified later). In the folder, you will
later have files named "frame1" "frame2" etc for the art. Let's move on for now--
Now go to the file main.py and import time and os:
import time import os i = 0
i is our variable.
To make everything easier, let's define some functions...
def clear(): # For clearing the board! os.system("clear") def read(): # This is reading files--needed later global i with open("frame/frame" + str(i + 1)) as f: content = f.read() print(content)
Great! Now go make your art :> In the folder "frame",
add a file named
frame1. Make your first picture/frame there, then create
a file named
frame2, and so on.
If you don't get animations, they're basically pictures connected together
to make a moving picture (aka an animation).
You can scroll ↓ for the example :P
Ok so we have to connect the pictures.
while True: i = 0 read() time.sleep(0.5) clear()
I'll explain everything here:
this is simple, just makes the whole thing go in a loop. Aka makes the animation
i = 0
I know we already asssigned this variable, just add it here in case. Basically,
the read() function reads files called
frame i+1, so if we put i as 0 here,
it will read the file frame1 (continue reading and this will become clear. ;)
Here, the read function makes the computer print out frame1, your first picture.
time.sleep(0.5) will pause everything briefly, for half a second here, before
clear() clears the board.
but that is only 1 frame...
Now, just keep copy and pasting this:
i = 0 read() time.sleep(0.5) clear()
Everytime you do it, increase
i by one.
what I mean is
frame 1: i = 0, blah blah blah frame 2: i = 1
and so on, so that all your files get printed.
You're probably still confused, since I'm not very good at explaining :'(
☆ Scroll down for the example I made ☆
Link to post is here
Btw, I usually use
print(""" ________ | | | | |______|""")
to print multiple lines of code! So for animation we can probably just use:
from time import sleep as sl from os import system as sys print(""" /\ / \ /____\""" sl(5) sys("clear") print(""" ________ | | | | |______|""") #I can't draw a pentagon lol
Anyways, thanks for the tutorial! I didn't know you can access files using Python :D