Tuesday, 30 December 2014

New year countdown with UnicornHat

Now Christmas is over, I'm missing my Unicorn Hat decoration. So how about a New Year countdown?

Using my Scrolling text library, I've knocked up some quick Python to display (in a random colour) the number of seconds remaining until 00:00:00 on Jan 1st 2015. Once that time is upon us it will display a suitable message.

from dateutil.relativedelta import relativedelta
from datetime import *
import calendar
from UHScroll import *
import random
import time

NY= datetime(2015,1,1,0,0)
cols = ['red','white','green','blue','cyan','yellow','orange']
while True:
NOW=datetime.now()
t = relativedelta(NOW,NY)
total = (24 * 60 * 60 * t.days) + (60 * 60 * t.hours) + ( 60 * t.minutes) + t.seconds
countdown = str(total)
if total < 0:
unicorn_scroll(countdown[1:],random.choice(cols),255,0.05)
time.sleep(0.2 * len(countdown[1:]))
else:
unicorn_scroll('happy new year!',random.choice(cols),255,0.1)
time.sleep(0.5)

video


No comments:

Post a Comment