Ejemplo n.º 1
0
def move_bird(event):
    if not active_tag:
        print('no tag selected')
        return
    
    width = utilities.get_width(canvas, active_tag)
    height = utilities.get_height(canvas, active_tag)
    left = utilities.get_left(canvas, active_tag) 
    top = utilities.get_top(canvas, active_tag) 
    current_x = left + (width / 2)
    current_y = top + (height / 2)

    delta_x = -1 * (current_x - event.x)
    delta_y = -1 * (current_y - event.y)

    utilities.update_position(canvas, active_tag, x=delta_x, y=delta_y)
Ejemplo n.º 2
0
def move_circle(event):
    if not active_tag:
        print('no tag selected')
        return
    
    # calculate the current position of the current shape:
    width = utilities.get_width(canvas, active_tag)
    height = utilities.get_height(canvas, active_tag)
    left = utilities.get_left(canvas, active_tag) 
    top = utilities.get_top(canvas, active_tag) 
    current_x = left + (width / 2)
    current_y = top + (height / 2)

    # calculate the delta of the current shape:
    delta_x = -1 * (current_x - event.x)
    delta_y = -1 * (current_y - event.y)

    # move the shape:
    utilities.update_position_by_tag(canvas, active_tag, x=delta_x, y=delta_y)
Ejemplo n.º 3
0
##################################################################################
point_list = []
f = open(utilities.get_file_path('florida.csv'))
for line in f.readlines():
    line = line.replace('\n', '')
    items = line.split(',')
    x = float(items[0])
    y = float(items[1])
    point_list.append((x, y))

canvas.create_polygon(point_list, fill='white', outline='black', tag='florida')
gui.update()

while True:
    center = utilities.get_center(canvas, 'florida')
    width = utilities.get_width(canvas, 'florida')
    print(center, width)
    shape_ids = canvas.find_withtag('florida')
    for shape_id in shape_ids:
        flipped_coordinates = []
        shape_coords = canvas.coords(shape_id)
        counter = 0
        for num in shape_coords:
            if counter % 2 == 0:
                shape_coords[counter] = -num + center[0] + width / 2
            counter += 1
            canvas.coords(shape_id, shape_coords)
            gui.update()
            time.sleep(0.01)
    time.sleep(2)
Ejemplo n.º 4
0
canvas.create_text((window_width / 2, window_height / 2),
                   text='Click or drag to create circles',
                   font=("Purisa", 32))


def make_circle(event):
    tag = 'circle_' + str(len(data))
    utilities.make_circle(canvas, (event.x, event.y),
                          random.uniform(10, 50),
                          color=None,
                          tag=tag)
    data.append({'tag': tag, 'speed': random.uniform(1, 5)})


canvas.bind(MOUSE_DRAG, make_circle)
canvas.bind(MOUSE_CLICK, make_circle)

# animation loop should come after everything else
# (because while loop never terminates, and therefore nothing
# below the while loop will ever run):
while True:
    # print(data)
    for item in data:
        tag = item['tag']
        speed = -1 * item['speed']
        if utilities.get_bottom(canvas, tag) < 0:
            reset_position = window_height + utilities.get_width(canvas, tag)
            utilities.update_position(canvas, tag=tag, y=reset_position)
        utilities.update_position(canvas, tag=tag, x=0, y=speed)
    gui.update()
    time.sleep(0.002)