Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- from time import sleep
- from random import randint
- import string
- class Bouncer (threading.Thread):
- def __init__ (self):
- threading.Thread.__init__ (self)
- self.max = 59 #Max width of the screen
- self.sleeptime = 50 #MS delay. Sets wave speed
- self.sleeplock = threading.Lock ()
- self.chars = string.ascii_letters + string.digits + string.punctuation
- def rand_char (self):
- return self.chars [randint (0, len (self.chars) - 1)]
- def set_rate (self, nvalue):
- try:
- nvalue = int (nvalue)
- except ValueError as e:
- nvalue = 2000
- print ("Incorrect input type:", e)
- with self.sleeplock:
- self.sleeptime = nvalue
- def wave (self):
- pad = 0
- dir = 'r'
- padchar = ' '
- while True:
- if dir == 'l':
- pad += -1
- elif dir =='r':
- pad += 1
- if randint (0, 1000) == 0:
- padchar = '!'
- yield (padchar * pad)
- if pad > self.max:
- dir = 'l'
- elif pad < 0:
- dir = 'r'
- padchar = ' '
- def run (self):
- for p in self.wave ():
- print (p + self.rand_char ())
- with self.sleeplock:
- sleeptime = self.sleeptime
- sleep (sleeptime / 1000)
- wave = Bouncer ()
- wave.start ()
- while True:
- wave.set_rate (input (""))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement