Unicorn HAT HD - set_pixels() not found


#1

I just installed my new Unicorn HAT HD (thank you Pimoroni!) and I am puzzled why I am getting and error:

unicornhathd.set_pixels(Buffer)
AttributeError: ‘module’ object has no attribute ‘set_pixels’

I am attempting to port my clock program to the HD format but it seems that set_pixels is not a recognized function. I use this on the regular Unicorn HAT without any problems.

Is this function deprecated?


#2

It appears to have gone the way of the dinosaur, although not intentionally since the shade_pixels method still exists:

def shade_pixels(shader):
    for x in range(WIDTH):
        for y in range(HEIGHT):
            r, g, b = shader(x, y)
            set_pixel(x, y, r, g, b)

This method accepts a “shader” function, which you can use to imitate the functionality of set_pixels for now:

unicornhathd.shade_pixels(lamdba x, y: (255, 0, 0))

Would be the same as:

unicornhathd.set_pixels(255, 0, 0)

shade_pixels accepts a function that takes an X and Y position, and returns a colour tuple: (r, g, b)

I’ll get set_pixels added ASAP.


#3

Wow! Thank you for the fast response. I got one of my games working last night (3 worms crawling around, growing bigger as they eat dots). It was so cool! I’ll be working on this all weekend, and I’ll send you a copy so you can see for yourself. :)