Ejemplo n.º 1
0
def UnicornImage():
    print("Showing image " + conf.IMAGE_NAME)

    unicorn.rotation(0)

    lenght = conf.IMAGE_LENGHT
    current_pos = 1

    width, height = unicorn.get_shape()

    img = Image.open(conf.IMAGE_NAME)

    while current_pos <= lenght:
        for o_x in range(int(img.size[0] / width)):
            for o_y in range(int(img.size[1] / height)):

                valid = False
                for x in range(width):
                    for y in range(height):
                        pixel = img.getpixel(
                            ((o_x * width) + y, (o_y * height) + x))
                        r, g, b = int(pixel[0]), int(pixel[1]), int(pixel[2])
                        if r or g or b:
                            valid = True
                        unicorn.set_pixel(x, y, r, g, b)

                if valid:
                    unicorn.show()
                    time.sleep(0.5)
        current_pos = current_pos + 1

    unicorn.off()

    return 0
Ejemplo n.º 2
0
    def __init__(self):
        '''
        @see ByComponentNotifier.__init__()
        '''
        super(UnicornHatNotifier, self).__init__()

        # Unicorn settings
        unicornhathd.rotation(0)
        (w, h) = unicornhathd.get_shape()
        self._width = w
        self._height = h

        # The time, since epoch, when each component type stopped being active
        self._input_time = 0
        self._service_time = 0
        self._output_time = 0

        # The direction of the swirl
        self._input_dir = 0
        self._service_dir = 0
        self._output_dir = 0

        # The currently non-idle components
        self._inputs = set()
        self._services = set()
        self._outputs = set()
Ejemplo n.º 3
0
def display_remote_image(url: str, brightness: float = 0.3) -> None:
    import unicornhathd

    response = requests.get(url)
    source = Image.open(BytesIO(response.content))

    unicornhathd.rotation(0)
    unicornhathd.brightness(brightness)

    width, height = unicornhathd.get_shape()

    sat_booster = ImageEnhance.Color(source)
    img = sat_booster.enhance(1.25)

    # increase contrast of image
    contr_booster = ImageEnhance.Contrast(img)
    img = contr_booster.enhance(1.2)

    # reduce the number of colors used in picture
    img = img.convert("P", palette=Image.ADAPTIVE, colors=10)

    img = source.resize((width, height), resample=Image.BICUBIC)

    img = ImageOps.mirror(img)

    for x in range(width):
        for y in range(height):
            pixel = img.getpixel((x, y))
            r, g, b = int(pixel[0]), int(pixel[1]), int(pixel[2])

            unicornhathd.set_pixel(x, y, r, g, b)

    unicornhathd.show()
Ejemplo n.º 4
0
def show():
    text = open('./isaax-project.env', 'r').readlines()[0]
    matchObj = re.match(r'.*?="(.*)"$', text)
    lines = matchObj.group(1).split(',')

    colours = [
        tuple([
            int(n * 255)
            for n in colorsys.hsv_to_rgb(x / float(len(lines)), 1.0, 1.0)
        ]) for x in range(len(lines))
    ]

    FONT = ("/usr/share/fonts/truetype/roboto/Roboto-Bold.ttf", 10)

    unicornhathd.rotation(0)
    unicornhathd.brightness(1.0)

    width, height = unicornhathd.get_shape()

    text_x = width
    text_y = 2

    font_file, font_size = FONT

    font = ImageFont.truetype(font_file, font_size)

    text_width, text_height = width, 0

    for line in lines:
        w, h = font.getsize(line)
        text_width += w + width
        text_height = max(text_height, h)

    text_width += width + text_x + 1

    image = Image.new("RGB", (text_width, max(16, text_height)), (0, 0, 0))
    draw = ImageDraw.Draw(image)

    offset_left = 0

    for index, line in enumerate(lines):
        draw.text((text_x + offset_left, text_y),
                  line,
                  colours[index],
                  font=font)

        offset_left += font.getsize(line)[0] + width

    for scroll in range(text_width - width):
        for x in range(width):
            for y in range(height):
                pixel = image.getpixel((x + scroll, y))
                r, g, b = [int(n) for n in pixel]
                unicornhathd.set_pixel(width - 1 - x, y, r, g, b)

        unicornhathd.show()
        time.sleep(0.01)

    unicornhathd.off()
    return True
Ejemplo n.º 5
0
def display_animation(image, brightness):  #displays a animation as multi png
    unicornhathd.rotation(90)
    unicornhathd.brightness(brightness)

    width, height = unicornhathd.get_shape()
    img = Image.open(image)

    try:
        while True:
            for o_x in range(int(img.size[0] / width)):
                for o_y in range(int(img.size[1] / height)):

                    valid = False
                    for x in range(width):
                        for y in range(height):
                            pixel = img.getpixel(
                                ((o_x * width) + y, (o_y * height) + x))
                            r, g, b = int(pixel[0]), int(pixel[1]), int(
                                pixel[2])
                            if r or g or b:
                                valid = True
                            unicornhathd.set_pixel(x, y, r, g, b)
                    if valid:
                        unicornhathd.show()
                        time.sleep(1)

    except KeyboardInterrupt:
        unicornhathd.off()
    return
Ejemplo n.º 6
0
def OutputText(energy, power, r, g, b):
    today = "Energy: " + str(energy) + energy_units
    current = "Power: " + str(power) + power_units
    lines = [current, today]
    colours = (r, g, b)
    FONT = ('/usr/share/fonts/truetype/freefont/FreeSansBold.ttf', 10)
    width, height = unicornhathd.get_shape()
    text_x = width
    text_y = 2
    font_file, font_size = FONT
    font = ImageFont.truetype(font_file, font_size)
    text_width, text_height = width, 0

    for line in lines:
        w, h = font.getsize(line)
        text_width += w + width
        text_height = max(text_height, h)

    image = Image.new('RGB', (text_width, max(16, text_height)), (0, 0, 0))
    draw = ImageDraw.Draw(image)

    offset_left = 0
    for index, line in enumerate(lines):
        draw.text((text_x + offset_left, text_y), line, colours, font=font)
        offset_left += font.getsize(line)[0] + width

    for scroll in range(text_width - width):
        for x in range(width):
            for y in range(height):
                pixel = image.getpixel((x + scroll, y))
                red, green, blue = [int(n) for n in pixel]
                unicornhathd.set_pixel(width - 1 - x, y, red, green, blue)

        unicornhathd.show()
        time.sleep(0.05)
Ejemplo n.º 7
0
def run_ticker(bg_color, text):
    FONT = ("DejaVuSans-Bold.ttf", 10)
    unicornhathd.rotation(90)
    unicornhathd.brightness(0.6)
    width, height = unicornhathd.get_shape()
    text_x = width
    text_y = 2
    font_file, font_size = FONT
    font = ImageFont.truetype(font_file, font_size)
    text_width, text_height = width, 0
    w, h = font.getsize(text)
    text_width += w + width
    text_height = max(text_height, h)
    text_width += width + text_x + 1

    image = Image.new('RGB', (text_width, max(16, text_height)), color)
    draw = ImageDraw.Draw(image)
    offset_left = 0
    draw.text((text_x + offset_left, text_y), text, fill="white", font=font)
    offset_left += font.getsize(text)[0] + width
    while True:
        for scroll in range(text_width - width):
            for x in range(width):
                for y in range(height):
                    pixel = image.getpixel((x + scroll, y))
                    r, g, b = [int(n) for n in pixel]
                    unicornhathd.set_pixel(width - 1 - x, y, r, g, b)

            unicornhathd.show()
            time.sleep(0.01)
Ejemplo n.º 8
0
def blank():
    """
    A blank image of the right size for the display.
    """
    w, h = uh.get_shape()
    image = Image.new("RGB", (w, h), color=0)
    return image
Ejemplo n.º 9
0
def run(imgFile='lofi.png'):

    unicornhathd.rotation(0)
    unicornhathd.brightness(0.6)

    width, height = unicornhathd.get_shape()

    img = Image.open(imgFile)

    a_list = []
    threading.Thread(target=input_thread, args=(a_list, )).start()

    while not a_list:
        for o_x in range(int(img.size[0] / width)):
            for o_y in range(int(img.size[1] / height)):

                valid = False
                for x in range(width):
                    for y in range(height):
                        pixel = img.getpixel(
                            ((o_x * width) + y, (o_y * height) + x))
                        r, g, b = int(pixel[0]), int(pixel[1]), int(pixel[2])
                        if r or g or b:
                            valid = True
                        unicornhathd.set_pixel(x, y, r, g, b)

                if valid:
                    unicornhathd.show()
                    time.sleep(0.5)

    unicornhathd.off()
Ejemplo n.º 10
0
 def __init__(self, oversample):
     self.oversample = oversample
     self.size = 16 * self.oversample
     self.initGrid()
     # fire up the unicorn hat
     unicorn.rotation(90)
     unicorn.brightness(1)
     self.width, self.height = unicorn.get_shape()
Ejemplo n.º 11
0
def display_text(lines, colors):

    # Use `fc-list` to show a list of installed fonts on your system,
    # or `ls /usr/share/fonts/` and explore.

    FONT = ("/usr/share/fonts/truetype/freefont/FreeSansBold.ttf", 12)

    # sudo apt install fonts-droid
    #FONT = ("/usr/share/fonts/truetype/droid/DroidSans.ttf", 12)

    # sudo apt install fonts-roboto
    #FONT = ("/usr/share/fonts/truetype/roboto/Roboto-Bold.ttf", 10)

    unicornhathd.rotation(90)
    unicornhathd.brightness(1.0)

    width, height = unicornhathd.get_shape()

    text_x = width
    text_y = 2

    font_file, font_size = FONT

    font = ImageFont.truetype(font_file, font_size)

    text_width, text_height = width, 0

    for line in lines:
        w, h = font.getsize(line)
        text_width += w + width
        text_height = max(text_height, h)

    text_width += width + text_x + 1

    image = Image.new("RGB", (text_width, max(16, text_height)), (0, 0, 0))
    draw = ImageDraw.Draw(image)

    offset_left = 0

    for index, line in enumerate(lines):
        draw.text((text_x + offset_left, text_y),
                  line,
                  colors[index],
                  font=font)

        offset_left += font.getsize(line)[0] + width

    for scroll in range(text_width - width):
        for x in range(width):
            for y in range(height):
                pixel = image.getpixel((x + scroll, y))
                r, g, b = [int(n) for n in pixel]
                unicornhathd.set_pixel(width - 1 - x, y, r, g, b)

        unicornhathd.show()
        time.sleep(0.02)

    unicornhathd.off()
Ejemplo n.º 12
0
def draw_image(image):
    width, height = unicornhathd.get_shape()
    for x in range(width):
        for y in range(height):
            pixel = image.getpixel((x, y))
            r, g, b = int(pixel[0]), int(pixel[1]), int(pixel[2])
            unicornhathd.set_pixel(x, y, r, g, b)

    unicornhathd.show()
Ejemplo n.º 13
0
    def __init__(self):
        self._lock_ui = _thread.allocate_lock()

        unicorn.rotation(270)
        unicorn.brightness(0.5)
        self._unicorn_width, self._unicorn_height = unicorn.get_shape()

        self._default_font_file = 'fonts/Hack-Regular.ttf'
        self._default_font_size = 12
        self._default_font = ImageFont.truetype(self._default_font_file, self._default_font_size)
Ejemplo n.º 14
0
def render(image):
    """
    Update the display with a new image.
    The buffer is a 16x16x3 numpy array, uh._buf.
    """
    xm, ym = uh.get_shape()
    for xy, pixel in zip(range(xm * ym), image.getdata()):
        x = xy // xm
        y = xy % xm
        uh.set_pixel(x, y, pixel[0], pixel[1], pixel[2])
    uh.show()
Ejemplo n.º 15
0
    def pixel_radius():
        """
        Find and return the radius in pixels for the LED Matrix.

        This function will return a minimum of half the length or half the height of the screen in pixels.
        :return: a length of radius in pixels
        :rtype: int
        """

        shape = uh.get_shape()
        radius = math.floor(max(shape[0] / 2, shape[1] / 2))
        return radius
Ejemplo n.º 16
0
def render_changes(image, old_image):
    """
    Update the display only where it has changed.
    """
    xm, ym = uh.get_shape()
    for xy, pixel, old_pixel in zip(range(xm * ym), image.getdata(),
                                    old_image.getdata()):
        x = xy // xm
        y = xy % xm
        if pixel != old_pixel:
            uh.set_pixel(x, y, pixel[0], pixel[1], pixel[2])
    uh.show()
Ejemplo n.º 17
0
def UnicornTextScroll():

    TEXT_FULL = conf.SCROLL_TEXT_RND
    TEXT_LEN = RandomNum(len(TEXT_FULL))
    TEXT = TEXT_FULL[TEXT_LEN]
    print("Scrolling text: " + TEXT)

    #TEXT = conf.SCROLL_TEXT
    FONT = ('/usr/share/fonts/truetype/freefont/FreeSansBold.ttf', 12)

    width, height = unicorn.get_shape()

    unicorn.rotation(270)

    text_x = 1
    text_y = 2

    font_file, font_size = FONT
    font = ImageFont.truetype(font_file, font_size)
    text_width, text_height = font.getsize(TEXT)
    text_width += width + text_x
    image = Image.new('RGB', (text_width, max(height, text_height)), (0, 0, 0))
    draw = ImageDraw.Draw(image)
    draw.text((text_x, text_y), TEXT, fill=(255, 255, 255), font=font)

    for scroll in range(text_width - width):
        for x in range(width):
            hue = (x + scroll) / float(text_width)

            br, bg, bb = [
                int(n * 255) for n in colorsys.hsv_to_rgb(hue, 1.0, 1.0)
            ]

            for y in range(height):

                pixel = image.getpixel((x + scroll, y))

                r, g, b = [float(n / 255.0) for n in pixel]

                r = int(br * r)
                g = int(bg * g)
                b = int(bb * b)
                unicorn.set_pixel(width - 1 - x, y, r, g, b)

        unicorn.show()

        # And sleep for a little bit, so it doesn't scroll too quickly!
        time.sleep(0.02)

    unicorn.off()

    return 0
Ejemplo n.º 18
0
    def pixel_origin():
        """
        Get the pixel coordinates of the ADSB receiver on the UnicornHat HD

        This should always be the centre of the LED matrix.
        :return: pixel coordinates of the ADSB receiver
        :rtype: (int, int)
        """

        shape = uh.get_shape()
        x = math.floor(shape[0] / 2)
        y = math.floor(shape[1] / 2)
        return int(x), int(y)
Ejemplo n.º 19
0
    def pixel_pos(self, radius, origin, position):
        """
        Calculate the pixel coordinates for a GPS position given the GPS coordinates of the origin and a radius in
        Nautical Miles.

        :param int radius: radius in Nautical Miles
        :param (float, float) origin: GPS coordinates of the centre point (origin)
        :param (float, float) position: GPS coordinates to plot (i.e. of the aircraft)
        :return: a tuple of pixel coordinates (x, y)
        :rtype: (int, int)
        """

        span = self.coord_span(radius, origin)
        shape = uh.get_shape()

        deg_per_px_lat = span["lat"]["delta"] / self.pixel_radius()
        deg_per_px_lon = span["lon"]["delta"] / self.pixel_radius()

        delta_lat = position[0] - origin[0]
        delta_lon = position[1] - origin[1]

        delta_x = delta_lon / deg_per_px_lon
        delta_y = delta_lat / deg_per_px_lat

        x_sign = 1
        y_sign = 1

        if origin[1] < 0:
            x_sign = -1
        if origin[0] < 0:
            y_sign = -1

        x = self.pixel_origin()[1] + (delta_x * x_sign)
        y = self.pixel_origin()[0] + (delta_y * y_sign)

        if origin[1] < 0:
            x = shape[0] - x
        if origin[0] < 0:
            y = shape[1] - y

        if x < 0:
            x = 0
        if x > shape[0] - 1:
            x = shape[0] - 1

        if y < 0:
            y = 0
        if y > shape[1] - 1:
            y = shape[1] - 1

        return int(x), int(y)
Ejemplo n.º 20
0
def display_text(data):
    text = "{} from {} backers = {}%!".format(data['pledged'], data['backers'],
                                              data['percent'])

    colours = [
        tuple([int(n * 255) for n in colorsys.hsv_to_rgb(x / 1.0, 1.0, 1.0)])
        for x in range(1)
    ]

    FONT = ("/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", 12)

    unicornhathd.rotation(0)
    unicornhathd.brightness(1.0)

    width, height = unicornhathd.get_shape()

    text_x = width
    text_y = 2

    font_file, font_size = FONT

    font = ImageFont.truetype(font_file, font_size)

    text_width, text_height = width, 0

    w, h = font.getsize(text)
    text_width += w + width
    text_height = max(text_height, h)

    text_width += width + text_x + 1

    image = Image.new("RGB", (text_width, max(16, text_height)), (0, 0, 0))
    draw = ImageDraw.Draw(image)

    offset_left = 0

    draw.text((text_x, text_y), text, colours[index], font=font)

    for scroll in range(text_width - width):
        for x in range(width):
            for y in range(height):
                pixel = image.getpixel((x + scroll, y))
                r, g, b = [int(n) for n in pixel]
                unicornhathd.set_pixel(width - 1 - x, y, r, g, b)

        unicornhathd.show()
        time.sleep(0.01)

    unicornhathd.off()
    return
Ejemplo n.º 21
0
def display_clock(
    hours, minutes, brightness, cycle, color_width
):  #temperature has tobe  string with at least two chars (add whitspace before)| add color coutner which is counted in main

    FONT = ("/home/pi/.fonts/fixed.ttf", 10)  #also time font in file

    unicornhathd.rotation(0)
    unicornhathd.brightness(brightness)

    width, height = unicornhathd.get_shape()
    text_x = width
    text_y = 0
    font_file, font_size = FONT

    font = ImageFont.truetype(font_file, font_size)

    w, text_height = font.getsize(hours)

    image = Image.new("RGB", (16, max(16, text_height)), (0, 0, 0))
    draw = ImageDraw.Draw(image)
    draw.fontmode = "1"  #turn antialiasing off for pixel fonts

    #draw.line(((11,0),(11,15)),(0,0,255),1)

    #draw.text((-1, 1), hours, (255,255,0), font=font)
    #todo change rand int colours
    draw.text((-1, 0), hours, (0, 255, 0), font=font)
    draw.text((-1, 9), minutes, (0, 255, 0), font=font)

    for x in range(12):
        for y in range(16):
            pixel = image.getpixel((x, y))

            r, g, b = [int(n) for n in pixel]

            if r > 0 or g > 0 or b > 0:

                r, g, b = [
                    int(n * 255)
                    for n in colorsys.hsv_to_rgb((y + cycle) /
                                                 float(color_width), 1.0, 1.0)
                ]

            unicornhathd.set_pixel(-x - 1, y, r, g, b)

    #unicornhathd.show()

    return
Ejemplo n.º 22
0
def display(filename):
    img = Image.open(filename)
    width, height = unicornhathd.get_shape()

    for o_x in range(int(img.size[0] / width)):
        for o_y in range(int(img.size[1] / height)):
            valid = False
            for x in range(width):
                for y in range(height):
                    pixel = img.getpixel(((o_x) + y, (o_y * height) + x))
                    r, g, b = int(pixel[0]), int(pixel[1]), int(pixel[2])
                    if r or g or b:
                        valid = True
                    unicornhathd.set_pixel(x, y, r, g, b)
            if valid:
                unicornhathd.show()
Ejemplo n.º 23
0
def display_data(data):
    width, height = unicornhathd.get_shape()
    num_pix = width * height

    unicornhathd.rotation(90)
    unicornhathd.brightness(0.5)

    percent = floor(float(data['percent']) * float(num_pix))
    for x in range(width):
        for y in range(height):
            pix = x * width + y
            if pix < percent:
                unicornhathd.set_pixel(x, y, 255, 255, 255)
            else:
                unicornhathd.set_pixel(x, y, 0, 0, 0)
    unicornhathd.show()
    return
Ejemplo n.º 24
0
 def prepareImage(self):
     self.width, self.height = unicornhathd.get_shape()
     unicornhathd.brightness(0.5)
     text_x = 1
     text_y = 2
     # Load the font using PIL's ImageFont
     font = ImageFont.truetype(self.font, self.font_size)
     # Ask the loaded font how big our text will be
     self.text_width, self.text_height = font.getsize(self.text)
     # Make sure we accommodate enough width to account for our text_x left offset
     self.text_width += self.width + text_x
     # Now let's create a blank canvas wide enough to accomodate our text
     self.image = Image.new('RGB', (self.text_width, max(self.height, self.text_height)), (0, 0, 0))
     # To draw on our image, we must use PIL's ImageDraw
     draw = ImageDraw.Draw(self.image)
     # And now we can draw text at our desited (text_x, text_y) offset, using our loaded font
     draw.text((text_x, text_y), self.text, fill=(255, 255, 255), font=font)
Ejemplo n.º 25
0
def start():
    threading.Timer(3.0, start).start()
    FONT = ('/usr/share/fonts/truetype/freefont/FreeSansBold.ttf', 12)
    width, height = unicornhathd.get_shape()
    text_x = width
    text_y = 2
    font_file, font_size = FONT

    font = ImageFont.truetype(font_file, font_size)

    text_width, text_height = width, 0

    lines = str(datetime.datetime.now())[10:-10]
    colours = [tuple([int(n * 255) for n in colorsys.hsv_to_rgb(x / float(len(lines)), 1.0, 1.0)]) for x in range(len(lines))]
    
    unicornhathd.rotation(90)
    if (int(lines[:3])>=21 or int(lines[:3])<9):
        unicornhathd.brightness(0.01)
    else:
        unicornhathd.brightness(1)

    for line in lines:
        w, h = font.getsize(line)
        text_width += w + width
        text_height = max(text_height, h)

    text_width += width + text_x + 1

    image = Image.new('RGB', (text_width, max(16, text_height)), (0, 0, 0))
    draw = ImageDraw.Draw(image)

    offset_left = 0

    for index, line in enumerate(lines):
        draw.text((text_x + offset_left, text_y), line, colours[index], font=font)

        offset_left += font.getsize(line)[0] + 1

    for scroll in range(text_width - width):
        for x in range(width):
            for y in range(height):
                pixel = image.getpixel((x + scroll, y))
                r, g, b = [int(n) for n in pixel]
                unicornhathd.set_pixel(width - 1 - x, y, r, g, b)

        unicornhathd.show()
Ejemplo n.º 26
0
def do_light_thing(context):
    unicorn.set_layout(unicorn.AUTO)
    unicorn.rotation(0)
    unicorn.brightness(.40)
    width, height = unicorn.get_shape()

    while True:
        if context.current_color == "green":
            set_color(0, 255, 0)
        elif context.current_color == "red":
            set_color(255, 0, 0)
        elif context.current_color == "blue":
            set_color(0, 0, 255)
        elif context.current_color == "yellow":
            set_color(255, 255, 0)
        else:
            unicorn.clear()
            unicorn.show()
        time.sleep(0.05)
Ejemplo n.º 27
0
def display_image(image, brightness):
    unicornhathd.rotation(0)
    unicornhathd.brightness(brightness)

    width, height = unicornhathd.get_shape()
    img = Image.open(image)

    for x in range(width):
        for y in range(height):

            pixel = img.getpixel((x, y))
            r, g, b = int(pixel[0]), int(pixel[1]), int(pixel[2])

            unicornhathd.set_pixel(x, y, r, g, b)

    unicornhathd.show()
    #time.sleep(1) #for debug

    return
def scroll_text(text):
    print(text)

    width, height = unicornhathd.get_shape()
    text_x = width
    text_y = 2

    font = ImageFont.truetype(*FONT)
    text_width, text_height = width, 0

    for line in text.splitlines():
        w, h = font.getsize(line)
        text_width += w + width
        text_height = max(text_height, h)

    text_width += width + text_x + 1

    image = Image.new("RGB", (text_width, max(16, text_height)), (0, 0, 0))
    draw = ImageDraw.Draw(image)

    offset_left = 0

    global col_index

    for index, line in enumerate(text.splitlines()):
        draw.text((text_x + offset_left, text_y),
                  line,
                  colours[col_index],
                  font=font)
        offset_left += font.getsize(line)[0] + width
        col_index += 1
        if col_index >= col_max:
            col_index = 0

    for scroll in range(text_width - width):
        for x in range(width):
            for y in range(height):
                pixel = image.getpixel((x + scroll, y))
                r, g, b = [int(n) for n in pixel]
                unicornhathd.set_pixel(width - 1 - x, y, r, g, b)

        unicornhathd.show()
        time.sleep(0.01)
def display_sprite(source, sprite, frame):
    image_width, image_height = source.size

    num_sprites = image_width / SPRITE_W
    num_frames = image_height / SPRITE_H

    offset_x = (sprite % num_sprites) * SPRITE_W
    offset_y = (frame % num_frames) * SPRITE_H

    width, height = unicornhathd.get_shape()

    for x in range(width):
        for y in range(height):
            pixel = source.getpixel((offset_x + x, offset_y + y))
            r, g, b, alpha = [int(p) for p in pixel]
            if alpha > 0:
                unicornhathd.set_pixel(x, y, r, g, b)
            else:
                unicornhathd.set_pixel(x, y, 0, 0, 0)

    unicornhathd.show()
Ejemplo n.º 30
0
def init():
    global current_activity_light, indicator_row, u_height, u_width

    # Clear the display (just in case)
    unicornhathd.clear()
    # Initialize  all LEDs to black
    unicornhathd.set_all(0, 0, 0)
    # set the display orientation to zero degrees
    unicornhathd.rotation(90)
    # set u_width and u_height with the appropriate parameters for the HAT
    u_width, u_height = unicornhathd.get_shape()
    # calculate where we want to put the indicator light
    indicator_row = u_height - 1

    # The app flashes a GREEN light in the first row every time it connects to Google to check the calendar.
    # The LED increments every time until it gets to the other side then starts over at the beginning again.
    # The current_activity_light variable keeps track of which light lit last. At start it's at -1 and goes from there.
    current_activity_light = u_width

    # Set a specific brightness level for the Pimoroni Unicorn HAT, otherwise it's pretty bright.
    # Comment out the line below to see what the default looks like.
    unicornhathd.brightness(0.5)
Ejemplo n.º 31
0
import digits

try:
  import unicornhathd as unicorn
  print("unicorn hat hd detected")
except ImportError:
  from unicorn_hat_sim import unicornhathd as unicorn

try:
    from PIL import Image
except ImportError:
    exit("This script requires the pillow module\nInstall with: sudo pip install pillow")

unicorn.rotation(0)
width, height = unicorn.get_shape()

def setPixel(x, y, r, g, b):
  unicorn.set_pixel((width-1)-x, y, r, g, b)

def loadImage(imageFile):
  return loadImages([imageFile])

def applyFade(pixels, mult):
  newpixels = copy.deepcopy(pixels)
  for x in range(width):
    for y in range(height):
      pixel = newpixels[x][y]
      newpixel = (pixel[0] * mult, pixel[1] * mult, pixel[2] * mult)
      newpixels[x][y] = newpixel
  return newpixels