Ejemplo n.º 1
0
def interaction(cards):
    '''
    Interactive interaction(cards)
    '''
    width = 90
    height = 117
    is_break = False
    field_state = {'slots': {}, 'selected': []}
    chosen_set = None
    pygame.event.set_blocked(None)
    pygame.event.set_allowed([pygame.MOUSEBUTTONDOWN, pygame.QUIT])
    slots = draw.visualize(cards, field_state)
    while not is_break:
        event = pygame.event.wait()
        if event.type == pygame.QUIT:
            exit()
        elif event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:
                (x_pos, y_pos) = pygame.mouse.get_pos()
                slots = field_state['slots']
                for key in slots:
                    slot = slots[key]
                    (v, h) = slot['position']
                    if v <= x_pos < v + width and h <= y_pos < h + height:
                        if key in field_state['selected']:
                            field_state['selected'].remove(key)
                            draw.visualize(cards, field_state)
                        else:
                            if len(field_state['selected']) < SET_NUMBER:
                                field_state['selected'].append(key)
                                draw.visualize(cards, field_state)
                            if len(field_state['selected']) == SET_NUMBER:
                                selected_cards = []
                                for number in field_state['selected']:
                                    selected_cards.append(slots[number]['card'])
                                if set.is_set(selected_cards):
                                    chosen_set = selected_cards
                                    is_break = True
                                    break
            if event.button == 2:
                exit()
            if event.button == 3:
                is_break = True
                break
    return chosen_set
Ejemplo n.º 2
0
def run() -> None:
    b = Builder()

    b.add_node("Config", depends=[primitive("filename")])
    b.add_node("X", depends=["Config"])
    b.add_node("Y", depends=["Config"])
    b.add_node("Z", depends=["X", "Y"])

    g = b.build()
    print(visualize(g))
Ejemplo n.º 3
0
def pair_visualization(pairs, img, img_shape, show_method='line'):
    board = img.copy()
    if show_method == 'line':
        for id in pairs:
            pair = pairs[id]
            for p in pair:
                board = draw.visualize(board, p.compos_dataframe, img_shape, attr='pair', show=False)
    elif show_method == 'block':
        for id in pairs:
            pair = pairs[id]
            for p in pair:
                board = draw.visualize_block(board, p.compos_dataframe, img_shape, attr='pair', show=False)
    cv2.imshow('pairs', board)
    cv2.waitKey()
    cv2.destroyAllWindows()
Ejemplo n.º 4
0
 def visualize(self, img, img_shape, attr='class', name='board'):
     draw.visualize(img, self.compos, img_shape, attr, name)
Ejemplo n.º 5
0
 def visualize(self, gather_attr='class', name='board'):
     draw.visualize(self.img, self.compos_dataframe, self.img_shape,
                    gather_attr, name)