Last active
December 26, 2015 00:29
-
-
Save erikrose/7065098 to your computer and use it in GitHub Desktop.
Open-source Halloween! Here's a spooky light show. Just `pip install blessings` and then run the script in any terminal. At the moment, it rotates between lightning-like flashes in various colors and gentle gradient pulsing. Put it in a window with the blinds down, and it diffuses nicely. Laptops are bright! Contribute your own effects in the co…
This file contains 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 python | |
from itertools import chain | |
import random | |
from random import randint | |
from time import sleep, time | |
from blessings import Terminal | |
t = Terminal() | |
# Gradients of various hues, in darkest-to-brightest order: | |
gradients = [[t.on_color(x) for x in 16, 22, 28, 34, 40, 46], | |
[t.on_color(x) for x in 0, 19, 20, 21, 27, 33, 39, 45, 51], | |
[t.on_color(x) for x in 52, 53, 54, 55, 56, 57, 63, 69, 75, 81]] | |
def paint_screen(color): | |
with t.location(0, 0): | |
print color('\n'.join((' ' * t.width) for h in xrange(t.height + 1))), | |
def fade_effect(): | |
colors = random.choice(gradients) | |
delay = random.choice([.04, .06]) | |
while True: | |
for color in chain(colors, reversed(colors)): | |
paint_screen(color) | |
sleep(delay) | |
yield | |
def flash_effect(): | |
color = random.choice([t.on_color(c) for c in 46, 27] + [t.on_bright_red]) | |
while True: | |
sleep(randint(3, 5)) | |
for _ in xrange(randint(2, 5)): | |
paint_screen(color) | |
sleep(0.1) | |
paint_screen(t.on_black) | |
sleep(randint(1, 5) / 10.0) | |
yield | |
def make_timer(duration): | |
start = time() | |
def time_is_up(): | |
return time() - start >= duration | |
return time_is_up | |
def main(): | |
effects = [v for k, v in globals().iteritems() if k.endswith('_effect')] | |
while True: | |
paint_screen(t.on_black) | |
effect = random.choice(effects)() | |
time_is_up = make_timer(randint(8, 8)) | |
while not time_is_up(): | |
next(effect) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment