Last active
August 29, 2015 14:21
-
-
Save thorsummoner/aecc75cd746ff7f9e205 to your computer and use it in GitHub Desktop.
Double helix ascii printer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
""" | |
Double Helix Text | |
""" | |
import argparse | |
import math | |
import sys | |
import time | |
from itertools import cycle | |
from pprint import pprint | |
DEFAULT = "(='.'=)" | |
ARGP = argparse.ArgumentParser( | |
description=__doc__, | |
formatter_class=argparse.RawTextHelpFormatter, | |
) | |
ARGP.add_argument('text', nargs='?', help='Input String', default=DEFAULT) | |
def strput(ob, offset, text): | |
for i, v in enumerate(text): | |
ob[offset+i] = v | |
def main(argp=None): | |
if argp is None: | |
argp = ARGP.parse_args() | |
width = len(argp.text) + 2 | |
step = math.pi * 2 / width | |
steps = [] | |
for x in xrange(1, width + 1): | |
steps.append(int(round(math.sin(step * x) * width/2) + width)) | |
pos = cycle(steps) | |
delta = None | |
while True: | |
offset = pos.next() | |
ob = [' '] * (width*3); | |
if delta is None: | |
delta = offset | |
else: | |
delta = offset - last | |
if delta >= 0: | |
strput(ob, offset, argp.text) | |
strput(ob, (width*2)-offset, argp.text) | |
if delta < 0: | |
strput(ob, offset, argp.text) | |
sys.stdout.write(''.join(ob) + '\n') | |
sys.stdout.flush() | |
last = offset | |
time.sleep(0.1) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment