Skip to content

Instantly share code, notes, and snippets.

@pendingchaos
Last active October 13, 2015 20:05
Show Gist options
  • Save pendingchaos/ce5441916db0d209329d to your computer and use it in GitHub Desktop.
Save pendingchaos/ce5441916db0d209329d to your computer and use it in GitHub Desktop.
The most awesome arm printer.

Awesome Arms v1.0.0

Animation

Usage:

awesomearms <the number of lines of awesome arms>

Or:

awesomearms -v

Or:

awesomearms --version

Or:

awesomearms --help

If your want an animation:

awesomearms animate

Example:

awesomearms 5

...will output:

\           /
 \         /
  \       /
   \     /
    \   /
     \o/
#!/usr/bin/env python
"""Awesome Arms v1.0.0
Usage: awesomearms <the number of lines of awesome arms>
Or: awesomearms -v
Or: awesomearms --version
Or: awesomearms --help
If your want an animation: awesomearms animate
Example:
awesomearms 5
\ /
\ /
\ /
\ /
\ /
\o/
"""
import sys
import os
import time
def get_console_size():
rows, columns = os.popen('stty size', 'r').read().split()
rows = int(rows)
columns = int(columns)
return rows, columns
def print_arms(lines_, centered=False):
columns = get_console_size()[1]
offset = (columns - ((lines_) * 2)) / 2
for i in xrange(lines_):
print " " * (i + offset) + "\\" + " " * ((lines_ - i) * 2) + " /"
print " " * (lines_ + offset) + "\o/"
def exit(code=1):
print """Usage: awesomearms <the number of lines of awesome arms>
Or: awesomearms -v
Or: awesomearms --version
If your want an animation: awesomearms animate"""
sys.exit(code)
if len(sys.argv) != 2:
print "Awesome Arms takes 1 arguments, not %d." % (len(sys.argv) - 1)
print
exit()
if sys.argv[1] in ["-v", "--version"]:
print "You are speaking to Awesome Arms v1.0.0!"
sys.exit()
if sys.argv[1] == "--help":
exit(0)
if sys.argv[1] == "animate":
lines = 0
dir = 1
while True:
max_lines = get_console_size()[0]
max_lines -= 2
os.system("tput reset")
if lines >= max_lines:
dir = -1
lines = max_lines
if lines == 0:
dir = 1
lines = 0
for i in xrange(max_lines - lines):
print
print_arms(lines, True)
lines += dir
time.sleep(0.1)
else:
try:
lines = int(sys.argv[1])
except:
print "Sorry, I do not understand \"%s\"." % sys.argv[1]
print
exit()
print_arms(lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment