def display_image(self, name, centered=True): # cache images to avoid re-reading them for each request # (we use a lazy loading method to avoid too long program # start time if loading all of them on init) try: img = self._images[name] except KeyError: self._images[name] = img = Image.open(os.path.join(os.path.dirname(__file__), 'img', name + '.png')) self._screen.clear() if centered: xy = tuple((d1 - d0) / 2 for d1, d0 in zip(self._screen.shape, img.size)) else: xy = (0, 0) self._screen.img.paste(img, xy) self._screen.update()
""" Draw some stuff on the LCD. """ import time import os from ev3dev.display import Screen, Image screen = Screen() screen.hide_cursor() w, h = screen.shape for image_file in ('tux.png', 'pobot.png', 'smiley.png'): decal = Image.open(os.path.join(os.path.dirname(__file__), 'img', image_file)) iw, ih = decal.size screen.draw.rectangle( ((0, 0), (w-1, h-1)), outline='black' ) for i, dim in enumerate(zip('wh', (w, h))): label, value = dim s = "%s=%d" % (label, value) tw, th = screen.draw.textsize(s) screen.draw.text((w - tw - 1, 2 + i * th), s) screen.draw.arc((5, 5, 25, 25), 0, 360) screen.draw.arc((w - 25, h - 25, w - 5, h - 5), 0, 360)