The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1

172 THE OFFICIAL RASPBERRY PI BEGINNER'S GUIDE


5 Figure 7-16: Displaying an image on the matrix

You can also rotate and flip images, either as a way to show images the right way up when
your Sense HAT is turned around or as a way of creating simple animations from a single
asymmetrical image.
Start by editing your creeper_pixels variable to close his left eye, by replacing the four
‘b’ pixels, starting with the first two on the third line and then the first two on the fourth line,
with ‘g’:

creeper_pixels = [
g, g, g, g, g, g, g, g,
g, g, g, g, g, g, g, g,
g, g, g, g, g, b, b, g,
g, g, g, g, g, b, b, g,
g, g, g, b, b, g, g, g,
g, g, b, b, b, b, g, g,
g, g, b, b, b, b, g, g,
g, g, b, g, g, b, g, g
]

Click Run, and you’ll see the creeper’s left eye close (Figure 7-17). To make an animation, go
to the top of your program and add the line:

from time import sleep
Free download pdf