Learn to Code via Tutorials on Repl.it!

← Back to all posts
EASY-python animations!
SilvermoonCat

Python Animation Tutorial-EASY!

By SilvermoonCat

Hey! This is SilvermoonCat :D


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:

i is our variable.


To make everything easier, let's define some functions...

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.

I'll explain everything here:
while True:
this is simple, just makes the whole thing go in a loop. Aka makes the animation
infinite/repeating.
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. ;)
read() time.sleep(0.5) 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:

BUT

Everytime you do it, increase i by one.
what I mean is

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

T

h

a

n

k
s
Voters
JWZ6
Th3Coder
fluffykitty421
SilvermoonCat
Comments
hotnewtop
Th3Coder

Awesome!!!

Btw, I usually use

to print multiple lines of code! So for animation we can probably just use:

Anyways, thanks for the tutorial! I didn't know you can access files using Python :D

SilvermoonCat

@Th3Coder np! and yes, that is another way, this way is just slightly more organized :)

fluffykitty421

first to upvote!

nice :O