Created
April 16, 2013 15:40
-
-
Save beauzeaux/5396992 to your computer and use it in GitHub Desktop.
A more showy version of bwk's random program for 333. Builds up some more suspense at the expense of time / student sanity.
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 | |
from random import randint | |
import sys | |
from time import sleep | |
MAX_TIME = 3 + randint(0,3) | |
SHOWMAN_RUNS = 40 | |
SHOWMAN_SLEEP = .05 | |
f = open(sys.argv[1]) | |
lines = f.readlines() | |
slp = .0001 | |
lastline = "" | |
# showmanship loop for some time | |
for i in range(SHOWMAN_RUNS): | |
# get a random line | |
line = lines[randint(0,len(lines)-1)] | |
# clear the line | |
sys.stdout.write('\r' + (' ' * len(lastline))) | |
# print the line | |
sys.stdout.write('\r' + line.strip('\n')) | |
sys.stdout.flush() | |
# sleep | |
sleep(SHOWMAN_SLEEP) | |
lastline = line | |
while slp < MAX_TIME: | |
# get a random line | |
line = lines[randint(0,len(lines)-1)] | |
# clear the line | |
sys.stdout.write('\r' + (' ' * len(lastline))) | |
# print the line | |
sys.stdout.write('\r' + line.strip('\n')) | |
sys.stdout.flush() | |
# sleep | |
sleep(slp) | |
slp = slp * 1.5 | |
lastline = line | |
sys.stdout.write('\n') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment