The Simple Console Rocket Animation in Python


I have implemented a C/C++ Rocket that launches a rocket in the console in this post: Simple C/C++ Rocket Animation. My sons recently start learning Python programming and I think it would be cool to make a Python rocket version:

Here we go:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# save this as rocket.py
from time import sleep
 
def printRocket():
    print(
"""
           _
          /^\\
          |-|
          | |
          |N|
          |A|
          |S|
          |A|
         /| |\\
        / | | \\
       |  | |  |
       `-\\"\\"\\"-`
""")
    
printRocket()
 
delay = 300
for i in range(60):
    print()
    sleep(delay/1000)
    delay = delay * 0.9
# save this as rocket.py
from time import sleep

def printRocket():
    print(
"""
           _
          /^\\
          |-|
          | |
          |N|
          |A|
          |S|
          |A|
         /| |\\
        / | | \\
       |  | |  |
       `-\\"\\"\\"-`
""")
    
printRocket()

delay = 300
for i in range(60):
    print()
    sleep(delay/1000)
    delay = delay * 0.9

And here is how it looks like when you launch the rocket simulation by python3 rocket.py

It is a very simple rocket launching code ever. We just wait and print empty lines (that pushes the rocket upward). The time interval between two blank line printing is shorter and shorter (multiplier by 0.9 because the rocket is accelerating faster and faster until it is fully into the sky then we can’t see it anymore after 60 empty lines)

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
249 words
Last Post: Counting the Big Numbers (Largests in Its Row and Column) in a Matrix
Next Post: The Simple Implementation of Binary Index Tree (BIT or Fenwick Tree)

The Permanent URL is: The Simple Console Rocket Animation in Python

Leave a Reply