Friday, 18 August 2017
Sense Hat pixel art V1
Two weeks today is the first Nuneaton Raspberry Jam in the local library. Get your tickets here (
https://www.eventbrite.co.uk/e/nuneaton-raspberry-jam-tickets-36625343388
) We will be using the sense hat emulator on the pi to create sense hat sparkles and the some pi pixel art based on the demo code from trink.io (the link to their site is listed below) I have cut down and adapted their demo to simplify and inject a bit of disco :).
Here is the code for the sense hat / online emulator:
"""
to run on the pi based emulator change the 1st import statement to
from sense_emu import SenseHat
"""
from sense_hat import SenseHat
import time
import random
s = SenseHat()
s.low_light = False
green = (0, 255, 0)
yellow = (255, 255, 0)
blue = (0, 0, 255)
red = (255, 0, 0)
white = (255,255,255)
nothing = (0,0,0)
pink = (255,105, 180)
ColourList = [green,yellow,blue,red,white,pink]
def raspi_logo():
G = green
R = red
O = nothing
logo = [
O, G, G, O, O, G, G, O,
O, O, G, G, G, G, O, O,
O, O, R, R, R, R, O, O,
O, R, R, R, R, R, R, O,
R, R, R, R, R, R, R, R,
R, R, R, R, R, R, R, R,
O, R, R, R, R, R, R, O,
O, O, R, R, R, R, O, O,
]
return logo
def raspi_logo_random():
G = random.choice(ColourList)
R = random.choice(ColourList)
O = random.choice(ColourList)
logo = [
O, G, G, O, O, G, G, O,
O, O, G, G, G, G, O, O,
O, O, R, R, R, R, O, O,
O, R, R, R, R, R, R, O,
R, R, R, R, R, R, R, R,
R, R, R, R, R, R, R, R,
O, R, R, R, R, R, R, O,
O, O, R, R, R, R, O, O,
]
return logo
def heart():
P = pink
O = nothing
logo = [
O, O, O, O, O, O, O, O,
O, P, P, O, P, P, O, O,
P, P, P, P, P, P, P, O,
P, P, P, P, P, P, P, O,
O, P, P, P, P, P, O, O,
O, O, P, P, P, O, O, O,
O, O, O, P, O, O, O, O,
O, O, O, O, O, O, O, O,
]
return logo
while True:
s.set_pixels(raspi_logo())#images[count % len(images)]())
time.sleep(0.75)
s.set_pixels(raspi_logo_random())
time.sleep(0.75)
#count += 1
Here is a link to show you how the pixel Pi logo works:
https://twitter.com/Warksraspijam/status/898468180477214722
Here is the emulator that I used :
https://trinket.io/sense-hat
Here is the code in action:
Enjoy :)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment