import random, time # The pause between rows in seconds; smaller values scroll faster. DELAY = 0.1 # The number of character columns in every printed row. WIDTH = 80 # The chance from 0 to 1 that a moving bolt creates a branch. FORK_CHANCE = 0.03 # The chance from 0 to 1 that an existing bolt disappears each row. DELETE_CHANCE = 0.10 # The chance from 0 to 1 that a new bolt appears each row. NEW_BOLT_CHANCE = 0.40 bolts = [] try: while True: row = [' '] * WIDTH # Add new bolts. if random.random() < NEW_BOLT_CHANCE: bolts.append(random.randint(1, WIDTH - 2)) # Move and occasionally fork the bolts. for i, bolt in enumerate(bolts): if bolt != 0 and random.random() < 0.5: bolts[i] -= 1 row[bolts[i]] = '/' elif bolt != WIDTH - 1: bolts[i] += 1 row[bolts[i]] = '\\' if bolt != 0 and random.random() < FORK_CHANCE: bolts.append(bolt) # Delete bolts at an edge or when they pass the deletion chance. for i in range(len(bolts) - 1, -1, -1): if bolts[i] == 0 or bolts[i] == WIDTH - 1 or random.random() < DELETE_CHANCE: del bolts[i] print(''.join(row)) time.sleep(DELAY) except KeyboardInterrupt: print('Scroll Lightning, by Al Sweigart al@inventwithpython.com')