Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
PNG example using Pillow library
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Oct 10, 2014
1 parent f033f42 commit dee8994
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Binary file added python/examples/lofi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions python/examples/show_png.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python

'''
This basic example shows use of the Python Pillow library:
sudo apt-get install pillow
The tiny 8x8 chars in lofi.png are from Oddball:
http://forums.tigsource.com/index.php?topic=8834.0
Licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
'''

import UnicornHat as unicorn
from PIL import Image
import signal, numpy, time

img = Image.open('lofi.png')

for o_x in range(img.size[0]/8):
for o_y in range(img.size[1]/8):

for x in range(8):
for y in range(8):
pixel = img.getpixel(((o_x*8)+y,(o_y*8)+x))
print(pixel)
r, g, b = int(pixel[0]),int(pixel[1]),int(pixel[2])
unicorn.set_pixel(x, y, r, g, b)
unicorn.show()
time.sleep(0.5)
2 changes: 2 additions & 0 deletions python/test/UnicornHat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
connected = True
print('Connected',port)
except:
if port >= 10:
exit("Unable to connect to UnicornHat Emulator")
port += 1

def close():
Expand Down

0 comments on commit dee8994

Please sign in to comment.