Skip to content

Instantly share code, notes, and snippets.

@yi-jiayu
Last active March 20, 2018 04:34
Show Gist options
  • Save yi-jiayu/a55ae6f4b2877e19b0d3bf8e4ca3cd37 to your computer and use it in GitHub Desktop.
Save yi-jiayu/a55ae6f4b2877e19b0d3bf8e4ca3cd37 to your computer and use it in GitHub Desktop.
import string
import random
import time
chars = string.digits + string.ascii_letters + string.punctuation + ' '
iterations_per_character_revealed = 2
update_delay = 0.05
choices = ['Edmond To', 'Tu Yong Tan', 'Clement Chua', 'Wei Quan Ng']
max_length = max(len(c) for c in choices)
choice = random.choice(choices).ljust(max_length)
reveal_order = list(x for x in range(max_length) if choice[x] != ' ')
random.shuffle(reveal_order)
for i in range(iterations_per_character_revealed * len(reveal_order)):
chrs = [' ' if choice[x] == ' ' else random.choice(chars) for x in range(max_length)]
revealed = i // iterations_per_character_revealed
for j in range(revealed):
chrs[reveal_order[j]] = choice[reveal_order[j]]
time.sleep(update_delay)
print('\r' + ''.join(chrs), end='')
print('\r' + choice)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment