Trying ASCII Animations
Looking into doing some animating.
"""
* Creator: Nighthawk Coding Society
Sailing Ship Animation (programatic method)
"""
import time # used for delay
from IPython.display import clear_output # jupyter specific clear
# ANSI Color Codes
OCEAN_COLOR = u"\u001B[34m\u001B[2D"
SHIP_COLOR = u"\u001B[32m\u001B[2D"
RESET_COLOR = u"\u001B[0m\u001B[2D"
def ship_print(position): # print ship with colors and leading spaces according to position
clear_output(wait=True)
print(RESET_COLOR)
sp = " " * position
print(sp + " |\ ")
print(sp + " |/ ")
print(SHIP_COLOR, end="")
print(sp + "\__ |__/ ")
print(sp + " \____/ ")
print(OCEAN_COLOR + "--"*35 + RESET_COLOR)
def ship(): # ship function, loop/controller for animation speed and times
# loop control variables
start = 0 # start at zero
distance = 60 # how many times to repeat
step = 2 # count by 2
# loop purpose is to animate ship sailing
for position in range(start, distance, step):
ship_print(position) # call to function with parameter
time.sleep(.2)
ship() # activate/call ship function
print(" O ")
print(" /|\ ")
print(" | | ")
print("-----")
print(" O ")
print("\/|\ ")
print(" / | ")
print("-----")
def startpos():
print(" O ")
print(" /|\ ")
print(" | | ")
print("-----")
startpos()
def waveup():
print(" O /")
print(" /| ")
print(" | | ")
print("-----")
waveup()
def wavemid():
print(" O| ")
print(" /| ")
print(" | | ")
print("-----")
wavemid()
And here it is iterated.
import time # used for delay
from IPython.display import clear_output # jupyter specific clear
def startpos():
print(" O ")
print(" /|\ ")
print(" | | ")
print("-----")
def waveup():
print(" O /")
print(" /| ")
print(" | | ")
print("-----")
def wavemid():
print(" O| ")
print(" /| ")
print(" | | ")
print("-----")
i = 0
while i < 30:
clear_output(wait=True)
if i == 0:
startpos()
else:
if i % 2 == 0:
wavemid()
else:
waveup()
i += 1
time.sleep(.2)