🐍🎞️🎬 Python Animation! 🐍🎞️🎬
HAHAHAAH, the emoji md works! >:)
Make your own animation - Tutorial!
🐍 A step by step tutorial on making a python animation 🐍
- About the tutorial
- The basics
- The easy way or the hard way
- Filing OR
- ASCII ART
- ASCII ART
- Filing OR
- Starting the animation
- Small details
- Clearing the console
- Small details
- Middle of animation
- File opening
- End animation
- A small note
This tutorial is all about making your first or your non-first animation. Basically, this tutorial is about animating in python. [pogchamp] This was a sudden idea, so some details might be left out. [thonk]
2) The Basics:
The basics of an animation that you should remember are the following:
- Remember to add
time.sleep()'s every so often.
- Clear the console everytime the file/print goes on.
- If you make the animation using
\'s to allow it to actually show (This will be talked about later on into the tutorial)
Remember the following, and you'll be just fine
(or will you...)
2.1) The Basics/imports
The only modules you need for animation making are the following:
So far, you will have the following code:
import os import time
TIP: If you press the button on the top right corner, it will automatically copy it for you!
import os, time
Both code has correct syntax. However, the thing with python (and many other langs) is that you can import certain librarys from a module. Like this:
from time import sleep import os
In this case, it would import the library sleep, from the module time. So any three of those would work. Let's move on now!
2.2) The Basics/The Easy way or the Hard way
There are multiple ways to actually code animations. But in this tutorial, we'll talk about 2 ways:
- File animations
- Print animations
So let me start with the file animation.
2.21) The Basics/The Easy way or the Hard way/Filing
So the way filing animation works is that it uses files. Say you wanted to name a file
poggers. Then just click the file button:
However, to store it evenly and organized, click the folder button:
So far, you should have a folder and a file (which it is in the folder) The folder and file should also be named; I would suggest:
- frames (for the folder)
- frame1 (file)
NOTE: You'll always have one folder, unless your animation has a series of animations looped together(we're not talking about that this tutorial)
Decide on what kind of animation you're going to make. I suggest making something easy, as it takes pretty long to code the ASCII ART. (This animation you're making in the file is ASCII ART. Click here) Some common examples you might want to try are:
- Snow (using
- Rain (using
- Bullets (Using
I'll choose an example from there and lets say I choose 'Snow'. So then, I would make a test file.
NOTE: So far you should have 2 files and one folder
So there are 2 ways you can make the file, since you made the folder.
- Click the file button and then name it
Testor anything. Then drag the file onto the folder.
- Click the folder button and then click the file button. Name it
Either way works!
So far, we've kinda done the basics, making the file and folder. Now, we do the ASCII code. I can't really explain much about it because this is about your creativity. However, I'll try to explain my best.
2.211) The Basics/The Easy way or the Hard way/Filing/ASCII ART
I can't explain much about this part of the tutorial. This is really up to your thinking and creativity. I did say I would try my best though, so lets get right into it. [poggers]
So think about your animation plan for a sec. What kind of ASCII character are you going to use?* What will be the scene? Will there be characters? ...
Think about those questions and answer them (in your mind, not to me ;)). If you can, your animation is probably possible! If not, try again to think a new idea. This was, however not really talking about ASCII art. So I'll show you a few examples and go on ot the next subject.
NOTE: Remember, these were made in a regular file, not a .py file.
* * * * * * * * * * * * * * * * * * * *
NOTE: I have not included ALL the files, only some of them. You will have to create the other files.
| | | | | | | | | | | | | | | | | | | |
Note: Some of these animations you can also do in python. However, I will talk about this in the next subject.
And that's it! (kinda) Let's move on to the next one!
2.22) The Basics/The Easy way or the Hard way/
So. That is a lot. lol. Anyway, if any of you guys are stuck, please notify me in the comments!
This time, we're gonna focus on making an animation in
main.py (in python). Like in the header above, the whole animation is gonna be printing ON AND ON. Which will be annoying. But who cares?!? [haha.]
Let me talk about the basics of
printing animations. You know every one of those files that you usually make in the files? Everytime you print something, it's one file. It sounds ok
, and you're laying back relaxing in the sun, drinking beer, right? Well, its not. It's literally torture Ok, sry for the strike-through's, but I had to add some humor. I think. [thonk]
I'll talk about the torture for a sec. Do you remember when I said that when you dont do 2
\'s, it creates some kind of blob? Yeah, that's the torture. If you don't do it, the indentation becomes a mess and becomes hard to deal with. Really.
I know i'm blabing on and on, but I have a point (kinda). I'm telling you guys to use the Filing animation. The indentation, symbols, everything is easier to deal with. However, as I made this tutorial, I'll tell you guys how to do it.
2.221) The Basics/The Easy way or the Hard way/
NOTE: If you haven't already looked at the header '2.211) The Basics/The Easy way or the Hard way/Filing/ASCII ART', you might as well do so.
The ASCII art for the
print will be relatively similar to the Filing ASCII art. The only
big difference is that in
print*'s, there are some indentation rules to follow.
*I know i'm saying this over and over, but what else can I say?
- When you put
\, put 2 of them. Like this for ex.
This is the problem. If you don't add the extra
\'s, you'll end up with a problem. I'm just reminding you to add the double
Just follow that rule and you'll be ok!
^Yep, I said rules before, but its rule now. [yep]
3) Starting the Animation
To start the animation, first create your files/print's and finish the animation. By means, create all your files/print's in order to make the animation. When you're done with that, you'll be up to here. If not, keep working until you're done. Just remember, practice makes perfect!
Once you finished the part above, go to the
main.py (otherwise another python file). If you look at the code, it will have this so far:
import os, time
You might have something similar to this, that's ok. As long as it's following these guidelines, you'll be fine.
Now we need to make the real part, the animating. As I said before though, we need screen clearing and time sleeping. To do that, we need small details and functions... [wha?]
3.1) Starting the Animation/Small Details
What are these small details? Well, this could mean;
This pretty much covers all what we need. As we've listed it, lets get coding!
3.11) Starting the Animation/Small Details/Clearing the Console
NOTE:We use the
osmodule to cover this section.
So one of the most common things I do and most other python coders do is import the
os module. We(py coders) usually use it for clearing the console. The syntax is:
os.system('clear'). However, because writing it may be painful [lazy], we make it a function! We do this:
import os ... def clear():#call this whatever os.system('clear')
NOTE: Just to make sure, you can call the function whatever you want. ;)
Because that this is a function, it can be called any amount of times. Now that we're done with that, lets move on!
3.12) Starting the Animation/Small Details/Colors
There isn't much to include in this section, I will just attach a copy and paste of the colors. You can either paste this into the
main.py or a different .py file. Here it is:
Red = "\033[0;31m" Green = "\033[0;32m" Orange = "\033[0;33m" Blue = "\033[0;34m" Purple = "\033[0;35m" Cyan = "\033[0;36m" White = "\033[0;37m" black = "\033[0;30m" red = "\033[0;91m" green = "\033[0;92m" yellow = "\033[0;93m" blue = "\033[0;94m" magenta = "\033[0;95m" cyan = "\033[0;96m" bright_black = "\033[0;90m" bright_red = "\033[0;91m" bright_green = "\033[0;92m" bright_yellow = "\033[0;93m" bright_blue = "\033[0;94m" bright_magenta = "\033[0;95m" bright_cyan = "\033[0;96m" bright_white = "\033[0;97m" cyan_back = "\033[0;46m" purple_back = "\033[0;45m" white_back = "\033[0;47m" blue_back = "\033[0;44m" orange_back = "\033[0;43m" green_back = "\033[0;42m" pink_back = "\033[0;41m" grey_back = "\033[0;40m" grey = '\033[38;4;236m' bold = "\033[1m" underline = "\033[4m" italic = "\033[3m" darken = "\033[2m" invisible='\033[08m' reverse='\033[07m' reset='\033[0m' grey = "\x1b[90m"
The capatilzed colors are darker, while the lowercase are a bit lighter. The back is a thing that will be behind the text. The bright is as it is said, bright colors. Also, the rest that I haven't mentioned are other editing things. For example, underline underlines and reset resets everything. And we're done with this section!
3.13) Starting the Animation/Small Details/
NOTE: In this topic I will be talking about how to use this function.
time.sleep() is very important in animations. It makes the animation actually rest, instead of going at the speed of light and you not being able to see. You have to put it in between file openings and before printing another 'file'. I will talk more about this in later sections.
4) Middle of animation
The middle of the animation is the main code. This is where we will talk about opening up the files and printing your 'files'. So lets go to opening up files!
4.1) Middle of animation/File opening
Opening up your file is how the animation 'animates'. It is the following syntax:
for i in range(0):#any int clear()#or your function for line in range(len(open("Folder/frame"+ str(i + 1)).readlines())): print(open("Folder/frame"+ str(i + 1)).readlines()[line],end="") time.sleep(0)#any int
Do that, replace Folder with the folder name, and you'll be done! Actually, add more of those on different lines, and you'll be done! ;)
forloops could be nested, it could be
for x in rangeor
for i in rangeor whatever. ;)
So you've got the basics for file opening! Nice job! To continue on to more to the animation, keep adding
for loops. I will be putting an example in this repl. Let's continue on to the
4.2) Middle of animation/Printing
So printing animations are actually simple (without the animation). The following syntax is correct (and an example):
import os, time print(""" .__________________________. | .___________________. |==| | | Apple | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ] | | ,| | !___________________! |(c| !_______________________!__! | ___ -= ___ -= | ,| | ---[_]--- ---[_]--- |(c| !_______________________!__! / \\ /  \\ /  \\ ( [____________] ) \ ------------------------------ / \______________________________/ """) time.sleep(2) os.system('clear')
The output would be:
.__________________________. | .___________________. |==| | | Apple | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ] | | ,| | !___________________! |(c| !_______________________!__! | ___ -= ___ -= | ,| | ---[_]--- ---[_]--- |(c| !_______________________!__! / \ /  \ /  \ ( [____________] ) \ ------------------------------ / \______________________________/
NOTE: The Reason why I added two backslashes was because regularly it is an escape slash in python. Also, the reason why the second backslash disappears in the output is that it now knows that we're trying to make it a symbol, so it switches it to a regular backslash.
So say you making someone go on the internet typing something in. You could add seperate print statements printing each and every other one.
hmmrmm, that would be a good idea So there you have it! Let's move on! [pogchamp]
5) End animation
If you've read through the whole thing (hopefully you have without sleeping), you'll have reached here! [pog] If not, try your best and keep trying! There isn't much to do left... However, I give congrats to you! [yayay!] 🎉🥳 Just read through the whole code, just in case for typos!
NOTE: Remember that my code WILL be different than yours, mine will just reference yours
ANOTHER NOTE: My code will only show the
main.py, so look through my files for those.
import time, os, random #colors - i only used some red = "\033[0;31m" green = "\033[0;32m" yellow = "\033[0;33m" blue = "\033[0;34m" magenta = "\033[0;35m" cyan = "\033[0;36m" white = "\033[0;37m" bright_black = "\033[0;90m" bright_red = "\033[0;91m" bright_green = "\033[0;92m" bright_yellow = "\033[0;93m" bright_blue = "\033[0;94m" bright_magenta = "\033[0;95m" bright_cyan = "\033[0;96m" def clear(): os.system('clear') color_list=[red,green,yellow,magenta,cyan,bright_blue,bright_cyan,bright_green,bright_magenta,bright_red,bright_yellow] clear() for x in range(5): for i in range(9): f_color = random.choice(color_list) clear() for line in range(len(open("fireworks/frame" + str(i + 1) ).readlines())): print(f_color+open("fireworks/frame" + str(i + 1) ).readlines()[line],end="") time.sleep(0.1) time.sleep(0.5) clear()
Again, if you followed correctly, you have done it! YAY! Congrats! Wait a sec though...
Hey guys, thanks for viewing this tutorial so much! I hope you guys like it, give suggestions, feedback!
This is my longest tutorial! 400 lines - 2449 Words - 16049 chars
6.1) Closing/Last Note
LAST NOTE OF TUTORIAL: Please don't ask for editing access, it annoys me, and you can just fork the repl. That would help both me and you, because you wouldn't have to wait so long for my permission. Thanks a lot again! ✌☮ @JBYT27