Exemplo n.º 1
0
def plot(grid: np.ndarray):
    if not u:
        return
    u.clear()
    for x, y in zip(*np.where(grid[:, :, 2] > 0.)):
        u.set_pixel_hsv(x, y, *grid[x, y])
    u.show()
Exemplo n.º 2
0
 def draw_level(self, level, x, y):
     nb_p = int(level/20)        #nb de palliers de 20% atteints: 0 à 5
     h = self.hue_level(level)   #HUE en fonction du level (0:vert à 100 rouge)
     for i in range(5):
         unicornhathd.set_pixel(x,y+i,self.c_gris_fonce[0],self.c_gris_fonce[1],self.c_gris_fonce[2])    # fond gris
         if (level/20>i):
             unicornhathd.set_pixel_hsv(x,y+i, self.hue_level(level), 1.0, (i+1)/(1+nb_p)) #dégradé bas(-) vers haut(+)
Exemplo n.º 3
0
    def display_percent(self, bar_percent):

        # Calculate number of pixels to illuminate.  If asked to display something more than the number of pixels, set
        # to the max available todo Make this a parameter rather than hard coding it to 16 pixels
        if bar_percent > 100:
            bar_percent = 100

        bar_pixels = bar_percent / 100 * (self.y_size - 1)

        #print("@@ {}".format(bar_pixels))

        # Figure out the colour to display based on the percentage
        state_colour = self.colour_list[int(
            bar_percent / 100 *
            15)]  # 15 is the maximum colours in the colour list

        # Set the pixels as required, using the colour for the state. Pixels not actively lit use the background
        # colour (could be black).
        for i in range(self.x_size):
            for j in range(self.y_size, ):
                if j >= 15 - int(bar_pixels):
                    unicornhathd.set_pixel_hsv(self.x_loc + i, j, state_colour)
                else:
                    unicornhathd.set_pixel(self.x_loc + i, j,
                                           self.back_colour[0],
                                           self.back_colour[1],
                                           self.back_colour[2])
Exemplo n.º 4
0
 def draw_horiz_3b(self, n3b, x, y, h):
     xb=0b100
     for c in range(3):
         if (xb & n3b) == xb :
             unicornhathd.set_pixel_hsv(x+c,y,h, 1.0, 0.7)
         else:
             unicornhathd.set_pixel(x+c,y,0,0,0) #led noire éteinte
         xb>>=1  #décalage 1b vers la droite
Exemplo n.º 5
0
 def draw_T(self, t, h):
     matrix_bin = self.msg.create_msg(str(t)) #conversion du message en codes binaires
     for i in range(13): #T° exprimées sous forme de 13 codes binaires
         xb=0b10000
         n5b=matrix_bin[i] #1 code binaire sur 5b rerpésente une barre verticale de 5 pixels
         for l in range(5):
             if (xb & n5b) == xb :
                 unicornhathd.set_pixel_hsv(3+i,4-l, h, 1.0, 1.0)
             else:
                 unicornhathd.set_pixel(3+i,4-l,0,0,0) #led noire éteinte
             xb>>=1 #décalage 1b vers la droite
Exemplo n.º 6
0
 def draw_square_level(self, level, x,y):
     nb_c = int(level/20)        #nb de tranches de 20% atteintes, varie de 0 à 5
     nb_l = int((level%20)/4)    #reste représantant 4% chacun: varie de 0 à 5
     self.draw_fullbox(10, 6, 14, 10 ,self.c_gris_fonce) #fond niveau DISK
     h = self.hue_level(level)
     #tranches pleines de 20%
     for c in range(nb_c):
         for l in range(5):
             unicornhathd.set_pixel_hsv(c+x,l+y, h, 1.0, (c+1)/nb_c) #dégradé gauche(-) vers droite (+)
             #unicornhathd.set_pixel_hsv(c+x,l+y, h, 1.0, 1-c/(nb_c+1))    #dégradé gauche(+) vers droite (-)
             
     #tranches de 4% supplémentaires
     for l in range(nb_l):
         unicornhathd.set_pixel_hsv(nb_c+x,l+y,h)  #dégradé gauche(-) vers droite (+)
Exemplo n.º 7
0
def display(sound, lastcry):
    levels = np.abs((sound['data'] * calib))  #sound['data']
    rgb = []
    if np.mean(levels) > 0.07:
        cry = True
        # cry_alert(lastcry)
        gid = randint(0, len(CRY_GHOST_PIXELS) - 1)
        show_pixel_image(CRY_GHOST_PIXELS[gid], GHOST_COLOUR['cry'])
    else:
        cry = False
        for i in range(1, 256):
            val = levels[i]
            colour = val_to_hsv(10 * val, cry)
            x, y = divmod(i, 16)
            unicornhathd.set_pixel_hsv(x, y, colour[0], colour[1], colour[2])
    return rgb
Exemplo n.º 8
0
def Color(h, s, v, run, running):
    running(True)
    h = float(h) / 360.0
    s = float(s)
    v = float(v)
    # x0, y0 current center
    x0 = uniform(0, 15)
    y0 = uniform(0, 15)

    # y_goal, x_goal -> goal
    y_goal = uniform(0, 15)
    x_goal = uniform(0, 15)
    while run() and v != 0:
        if x0 == x_goal and y0 == y_goal:
            print("color - arrived", end="\tx:\t")
            print(x_goal, end="\ty:\t")
            print(y_goal)

            # goal reached, create new goal
            y_goal = uniform(0, 15)
            x_goal = uniform(0, 15)

        direction = [x_goal - x0, y_goal - y0]
        distance = np.linalg.norm(direction)

        # 0.05 is max velocity of movement
        if distance > 0.05:
            rescale = 0.05 / distance
            direction[0] *= rescale
            direction[1] *= rescale

        # move towards goal
        x0 += direction[0]
        y0 += direction[1]

        #create dists and v_map
        make_mapping(v, x0, y0)

        for x in range(u_width):
            for y, v_from_v_map in zip(range(u_height), v_map[x]):
                unicorn.set_pixel_hsv(x, y, h, s, v_from_v_map)
        unicorn.show()

    unicorn.off()
    running(False)
Exemplo n.º 9
0
def unicorn_display(sound, lastcry):
    if DISP == 'eq':
        y_len = calculate_levels(sound)
        unicornhathd.clear()

        for x in range(0, 4):
            y_val = y_len[x]
            for y in range(0, 16):
                if y < int(y_val):
                    amp = y_val / 16
                    unicornhathd.set_pixel_hsv(x, y, amp, 0.7, 0.5)
                else:
                    unicornhathd.set_pixel_hsv(x, y, 0, 0, 0)
    else:
        colours = display(sound, lastcry)
    try:
        unicornhathd.rotation(ROT)
        unicornhathd.show()
    except Exception as e:
        # print(msg.data)
        pass
    return
Exemplo n.º 10
0
    def __circle(self, r, center_x, center_y, b, hue):
        sat = 0.7

        led_x = center_x + r
        led_y = center_y
        if 0 < led_x < 16 and 0 < led_y < 16:
            unicornhathd.set_pixel_hsv(led_x, led_y + .5, hue, sat, b)

        for theta in range(0, 314):
            logic_x = center_x + (r * math.cos(theta / 50))
            logic_y = center_y + (r * math.sin(theta / 50))

            if abs(logic_x - led_x) > 1:
                print(str(led_x) + ", " + str(led_y))
                if 0 < led_x < 16 and 0 < led_y < 16:
                    unicornhathd.set_pixel_hsv(led_x, led_y, hue, sat, b)
                led_x = int(round(logic_x))

            elif abs(logic_y - led_y) > 1:
                print(str(led_x) + ", " + str(led_y))
                if 0 < led_x < 16 and 0 < led_y < 16:
                    unicornhathd.set_pixel_hsv(led_x, led_y, hue, sat, b)
                led_y = int(round(logic_y))
Exemplo n.º 11
0
async def set_pixel_hsv(x, y, h, s=1.0, v=1.0):
    return unicornhathd.set_pixel_hsv(x, y, h, s, v)
Exemplo n.º 12
0
def set_pixel_hsv(x, y, h, s=1.0, v=1.0) -> None:
    uni.set_pixel_hsv(x, y, h, s, v)
Exemplo n.º 13
0
def hsv_wave(run, running, flavor):
    global dists
    running(True)

    v = 1

    # x0, y0 current center
    x0 = uniform(0, 15)
    y0 = uniform(0, 15)

    # y_goal, x_goal -> goal
    y_goal = uniform(0, 15)
    x_goal = uniform(0, 15)
    step1 = uniform(0, math.pi * 2)
    step2 = uniform(0, math.pi * 2)
    x_func_mapping_class = flavor_funcs(flavor[1])
    y_func_mapping_class = flavor_funcs(flavor[2])
    x_func = x_func_mapping_class.flavor_function_map()
    y_func = y_func_mapping_class.flavor_function_map()
    #x_func = _flavor_function_map(flavor[1])
    #y_func = _flavor_function_map(flavor[2])
    while run() and v != 0:
        if x0 == x_goal and y0 == y_goal:
            print("hsv_wave - arrived", end="\tx:\t")
            print(x_goal, end="\ty:\t")
            print(y_goal)

            # goal reached, create new goal
            y_goal = uniform(0, 15)
            x_goal = uniform(0, 15)

        direction = [x_goal - x0, y_goal - y0]
        distance = np.linalg.norm(direction)

        # 0.05 is max velocity of movement
        if distance > 0.05:
            rescale = 0.05 / distance
            direction[0] *= rescale
            direction[1] *= rescale

        # move towards goal
        x0 += direction[0]
        y0 += direction[1]

        # create dists and v_map
        make_mapping(v, x0, y0, flavor=flavor[0])
        maximum = np.amax(dists)
        dists *= math.pi / maximum

        # set colors

        for x in range(u_width):
            for y, v_from_v_map, mapped_distance in zip(
                    range(u_height), v_map[x], dists[x]):
                h = x_func(step1 + mapped_distance)
                #h = _triangle(step1 + mapped_distance)
                s = y_func(step2 + mapped_distance)
                #s = math.sqrt((math.sin(step2 + mapped_distance) + 1) * 0.5)
                unicorn.set_pixel_hsv(x, y, h, s, v_from_v_map)

        step1 += math.pi * 0.001 * flavor[3]
        step2 += math.e * 0.001 * flavor[3]
        unicorn.show()

    unicorn.off()
    running(False)
Exemplo n.º 14
0
OMG MY EYES.

Press Ctrl+C to exit!

""")

unicornhathd.rotation(0)

step = 0
try:
    while True:
      step += 1
      for x in range(0, 16):
        for y in range(0, 16):
          dx = 7
          dy = 7

          dx = (math.sin(step / 20.0) * 15.0) + 7.0
          dy = (math.cos(step / 15.0) * 15.0) + 7.0
          sc = (math.cos(step / 10.0) * 10.0) + 16.0

          h = math.sqrt(math.pow(x - dx, 2) + math.pow(y - dy, 2)) / sc

          unicornhathd.set_pixel_hsv(x, y, h, 1, 1)

      unicornhathd.show()

except KeyboardInterrupt:
    unicornhathd.off()
Exemplo n.º 15
0
    def workout_attack(self, attack_type, delay=0.2, colour=-1):

        # x and y lengths of the pixels to display
        x_len = 2
        y_len = 5

        #print(attack_type)

        # Translate the quadrant to pixel start locations and
        # colours.  Use Red for Right (Hue =1), Green (Hue =0.33) for Left.
        if attack_type == 'KickLeft':
            x_start = 0
            y_start = 0

            if colour == -1:
                attack_colour = 0.33
            else:
                attack_colour = colour

        elif attack_type == 'PunchLeft':
            x_start = 0
            y_start = 11
            if colour == -1:
                attack_colour = 0.33
            else:
                attack_colour = colour

        elif attack_type == 'PunchRight':
            x_start = 14
            y_start = 11
            if colour == -1:
                attack_colour = 1
            else:
                attack_colour = 1
        elif attack_type == 'KickRight':
            x_start = 14
            y_start = 0

            if colour == -1:
                attack_colour = 1
            else:
                attack_colour = 1

        # Don't do anything special for Wait - it is just a pause.
        elif attack_type == 'Wait':
            x_start = 0
            y_start = 0
            attack_colour = 0

        # Raise exception of quadrant doesn't make sense.
        else:
            print("attack {} not handled ".format(attack_type))
            x_start = 7
            y_start = 0
            attack_colour = 0.78

        # Set the pixels and then display.
        for i in range(x_len):
            for j in range(y_len):
                unicornhathd.set_pixel_hsv(x_start + i, y_start + j,
                                           attack_colour)

        unicornhathd.show()

        time.sleep(delay)
        for i in range(x_len):
            for j in range(y_len):
                unicornhathd.set_pixel_hsv(x_start + i, y_start + j, 0, v=0)

        unicornhathd.show()