Ejemplo n.º 1
0
def updatedisplay(displaymap):
    x = 0
    y = 0
    for row in displaymap:
        for line in row:
            for char in line:
                if x < w and y < h:
                    if char == "X":
                        r, g, b = 255, 255, 255
                    elif char == "R":
                        r, g, b = [
                            int(c * 255)
                            for c in hsv_to_rgb(x / w, y / h, 1.0)
                        ]
                    elif char == "D":
                        r, g, b = 200, 200, 40
                    elif char == "A":
                        r, g, b = playerABcolours
                    elif char == "Y":
                        r, g, b = playerXYcolours
                    else:
                        r, g, b = 0, 0, 0
                    picounicorn.set_pixel(x, y, r, g, b)
                x += 1
            x = 0
        y += 1
    return displaymap
Ejemplo n.º 2
0
def lightcontrolXY(onlistXY):
    for x in range(15, 16):
        for y in listH:
            if y in onlistXY:
                r, g, b = playerXYcolours
            else:
                r, g, b = 0, 0, 0
            picounicorn.set_pixel(x, y, r, g, b)
Ejemplo n.º 3
0
def lightcontrolAB(onlistAB):
    for x in range(1):
        for y in listH:
            if y in onlistAB:
                r, g, b = playerABcolours
            else:
                r, g, b = 0, 0, 0
            picounicorn.set_pixel(x, y, r, g, b)
def draw_image(x, y, image_data, w=5, h=5):
    dw = picounicorn.get_width()
    dh = picounicorn.get_height()
    for xi in range(5):
        if xi + x >= dw:
            return
        if xi + x < 0:
            continue
        for yi in range(5):
            if yi + y >= dh:
                break
            print(xi + x, yi + y)
            pixel = image_data[yi * h + xi]
            # We've inverted X Y here.
            picounicorn.set_pixel(x + xi, y + yi, pixel[0], pixel[1], pixel[2])
Ejemplo n.º 5
0
def draw(w, h, t, sr=0, sc=0, clear=False):
    for row_w in range(sr, w):
        for col_h in range(sc, h):
            if clear:
                x, y, z = 0, 0, 0
            else:
                x, y, z = _rgb_randomiser()
            picounicorn.set_pixel(row_w, col_h, x, y, z)
            sleep(t)

            if picounicorn.is_pressed(picounicorn.BUTTON_B) and not clear:
                sleep(0.5)
                return row_w, col_h

        if sc != 0:  # to make sure all subsequent rows get randomised
            sc = 0

    return 0, 0
Ejemplo n.º 6
0
def ball(currentballx, currentbally, prevballx, prevbally, prevball2x,
         prevball2y, ballcolours):
    for x in listWball:
        for y in listHball:
            if x == currentballx:
                if y == currentbally:
                    r, g, b = ballcolours
                    picounicorn.set_pixel(x, y, r, g, b)
            elif x == prevballx:
                if y == prevbally:
                    r, g, b = [round(element * 0.3) for element in ballcolours]
                    picounicorn.set_pixel(x, y, r, g, b)
            elif x == prevball2x:
                if y == prevball2y:
                    r, g, b = [round(element * 0.2) for element in ballcolours]
                    picounicorn.set_pixel(x, y, r, g, b)
            else:
                r, g, b = 0, 0, 0
                picounicorn.set_pixel(x, y, r, g, b)
    return currentballx, currentbally, prevballx, prevbally, prevball2x, prevball2y
Ejemplo n.º 7
0
def pomocycle():

    # Set up our variables
    r = 255
    g = 0
    column = 15
    row = 6
    phase = "work"
    multiplier = 134

    # Start counting down
    while not (picounicorn.is_pressed(picounicorn.BUTTON_Y)):

        # Illuminate every LED on the board
        for x in range(16):
            for y in range(7):
                picounicorn.set_pixel(x, y, r, g, 0)

        # Extinguish LEDs one by one
        while row > -1:
            while column > -1:
                for x in range(multiplier):
                    if not (picounicorn.is_pressed(picounicorn.BUTTON_Y)):
                        utime.sleep(0.1)
                    else:
                        break
                picounicorn.set_pixel(column, row, 0, 0, 0)
                column -= 1
            column = 15
            row -= 1
        row = 6

        # No more LEDs? Switch from work to rest and vice versa
        if phase == "work":
            phase = "rest"
            multiplier = 27
            r = 0
            g = 255
        elif phase == "rest":
            phase = "work"
            multiplier = 134
            r = 255
            g = 0
        pass

    # Clear the display
    for x in range(16):
        for y in range(7):
            picounicorn.set_pixel(x, y, 0, 0, 0)
Ejemplo n.º 8
0
    if i == 4:
        return t, p, v
    if i == 5:
        return v, p, q


width = picounicorn.get_width()
height = picounicorn.get_height()

print("Running!")

while not picounicorn.is_pressed(
        picounicorn.BUTTON_A):  # Wait for Button A to be pressed
    # Scroll red across
    for x in range(width):
        for y in range(height):
            r, g, b = [int(c * 255) for c in hsv_to_rgb(x / width, 1.0, 1.0)]
            picounicorn.set_pixel(x, y, r, g, b)
        time.sleep_ms(50)

    # Clear the display
    for x in range(width):
        for y in range(height):
            picounicorn.set_pixel(x, y, 0, 0, 0)
        time.sleep_ms(50)

for x in range(width):
    for y in range(height):
        picounicorn.set_pixel(x, y, 0, 0, 0)

print("Ended!")
Ejemplo n.º 9
0
def cleardisplay():
    for x in range(w):
        for y in range(h):
            picounicorn.set_pixel(x, y, 0, 0, 0)
Ejemplo n.º 10
0
    # creates a good timing. But the plasma-effect needs some time-related variable. That is t. It grows by ti (0.15 at the beginning)
    # and ti is therefore responsible for the tempo of the plasma-effect. But the sine-function-pattern starts to repeat itselt at 12 + pi.
    # Thats why t is resetted there. It would be not necessary. But if you think about letting this run for days t could be a really
    # great number that the processor would sooner or later start to struggle with in all the sine-functions.
    t += ti
    if t >= 12 * math.pi: t = 0

    # This loop iterates through all pixels of the unicorn-display and initiates the plasma-effect-calculation. If the text-masking of
    # the plasma-effect is active (which is the case inititally: tm == 1) the returned rgb-values are multiplied with the value
    # found in the framebuffer at this moment in scrolling. If it is 1 the color appears, if 0 the led is off (black). This is the reason
    # why the framebuffer was created with inverted text.
    for x in range(w):
        for y in range(h):
            r, g, b = pix_color(x, y, cm)
            if tm == 0:
                picounicorn.set_pixel(x, y, r, g, b)
            else:
                s = fb.pixel(x, y)
                picounicorn.set_pixel(x, y, r * s, g * s, b * s)

    # The scrolling starts at fc == 0. Two empty letter-spaces of 8 pixels each where inserted when the framebuffer was created.
    # For the unicorn-display has exactly 16 columns there is no letter visible and therefore no masking takes place.
    # After fc reaches fbw (the width of the framebuffer) the text is scrolled entirely through the screen and scrolling stops.
    # fc is then resetted to -30 and at -10 the same framebuffer will be created unless the user did not change the text.
    if fc >= 1 and fc <= fbw:
        fb.scroll(-1, 0)
    elif fc > fbw:
        fc = -30

    # All buttons have a simple but effective debouncing. Once they are pressed the ap (or bp, xp, yp) variable is set to True
    # and the function can not be fired again. Not before the button is released the variable is set to False again.
def set_all(r, g, b):
    w = picounicorn.get_width()
    h = picounicorn.get_height()
    for x in range(w):
        for y in range(h):
            picounicorn.set_pixel(x, y, r, g, b)